Author Topic: How to change Coordinate system, like glMatrixMode  (Read 4715 times)

Offline gman

  • byte
  • *
  • Posts: 5
    • View Profile
How to change Coordinate system, like glMatrixMode
« on: October 22, 2010, 09:14:28 am »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to change Coordinate system, like glMatrixMode
« Reply #1 on: October 22, 2010, 09:20:07 am »
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).

Offline gman

  • byte
  • *
  • Posts: 5
    • View Profile
Re: How to change Coordinate system, like glMatrixMode
« Reply #2 on: October 22, 2010, 09:38:59 am »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to change Coordinate system, like glMatrixMode
« Reply #3 on: October 22, 2010, 10:17:49 am »
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.

Offline gman

  • byte
  • *
  • Posts: 5
    • View Profile
Re: How to change Coordinate system, like glMatrixMode
« Reply #4 on: October 22, 2010, 11:01:38 am »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to change Coordinate system, like glMatrixMode
« Reply #5 on: October 22, 2010, 11:06:57 am »
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.

Offline gman

  • byte
  • *
  • Posts: 5
    • View Profile
Re: How to change Coordinate system, like glMatrixMode
« Reply #6 on: October 22, 2010, 04:29:20 pm »
Thank you very much for your suggestion  :)
I'll try your ideas.

Regards