How to change Coordinate system, like glMatrixMode

Started by gman, October 22, 2010, 09:14:28 AM

Previous topic - Next topic

gman

Dear Sir,


I would like to change the coordinate system of the jPCT so that I can place the 3D model on specific position/orientation. In OpenGL, I can change the coordinate system by

gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadMatrixf( glCameraMatrixBuffer );

I got the glCameraMatrixBuffer declared with
protected static FloatBuffer glCameraMatrixBuffer;

On jPCT, how to change coordinate system that is working like

gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadMatrixf( glCameraMatrixBuffer );

Thank you very much for your kindly help.

EgonOlsen

You can get the camera's matrix from Camera.getBack() and set it via Camera.setBack(). However, i don't recommend to do this and i don't get that "so that I can place the 3D model on specific position/orientation"-part. You can already do this with the methods that Object3D offers!? There's no need to fiddle around with the camera's matrix (apart from that, it's not the correct place to do it, because it's actually the camera, not the model view matrix).

gman

Thank you very much EgonOlsen for your quickly replied

My app is Augmented Reality, therefore, I would like to place the 3D animation on the center of the Marker.
I got the position and orientation of the marker. Then I would like to setup the coordinate system so that the position and orientation of the coordinate system is placed and rotated on the 'AR Marker'. After that I can place the 3D animation at the position 0,0,0 which is the center of the marker.

Could you help me please.

EgonOlsen

Your thinking seems to be a bit twisted to me (no offense... ;D) or i just don't get it. So you have some location in space, where this AR-marker is? And you want to place a model at that location with a given orientation? Well, then just translate the model. Object3D has a translate()-method and lets you specify rotations either by using some rotate-methods, by setting a rotation matrix directly or by using the align-method.
There are basically three spaces that are important in this case: Object space, world space and camera space.
Object space is the space, in which the model itself is defined, i.e. the coordinate system used in the modeller. An objects position in object space never changes unless you manipulate an object's vertices directly.
World space represents the world, i.e. the locations of those objects (and camera and lights and...) in a world.
Finally, camera space is the space which is used to render the scene. In camera space, the camera is always located at the origin and the rest of the world gets tranformed accordingly.
An example: An object might have it's center around the origin in object space. For example a simple cube reaching from -10 to 10 on all three axes. It's position in world space might be 100,0,0, i.e. it sits 100 units away from the origin on positive x axis. That's what you do by calling translate(100,0,0) on it. The camera might be located at 50,0,0 (in world space!), so the final position of the cube's center in camera space is 50,0,0.

gman

I unstand your explanation.

However, I think there are two ways to do this.

1. Transform the coordinate system so that the position 0,0,0 of the coordinate is on the marker's center.

2. Transform the Object so that it stand on the marker.

If we can transform the coordinate system, we do not need to transform the 3d object. Just place it on the position 0,0,0. It would be much more easier to maintain the animation.

I'm not sure that is it correct?

Should you advise me please.

EgonOlsen

In which aspect should it be easier to do the animation when changing the coordinate system? It's just twisted IMHO. I've never seen any 3D application that works this way. What if you have more than one object? You can't apply this logic to that case.
Your logic says that, instead of moving a chair from the living room to the kitchen, you define the living room as kitchen (and vice versa). As that's perfectly fine as long as both rooms are empty except for the chair. But that's usually not the case.

gman

Thank you very much for your suggestion  :)
I'll try your ideas.

Regards