• Create Account

## Matrix operation order causing positioning problems!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1PixelPrime11  Members

108
Like
0Likes
Like

Posted 09 November 2012 - 11:07 AM

Hi All,

I'm currently having some positioning problems using OpenGL and LWJGL, but figured this would be generic enough for the OGL forum!

I wanted to know whether my method for positioning objects in the world is correct, as I'm not sure my matrix operations are in the right order.

For every object that's placed in the world, I'm doing the following:
• Load the Identity Matrix (reset everything)
• Translate to the camera's X, Y, Z position
• Rotate the camera around the X and Y axes (I'm not doing Z rolling)
• Translate to the object's X, Y, Z position
• Rotate the object around the X, Y, Z axes.

I keep tweaking things and somehow getting it to work, but I'd like to know the de-facto method for accomplishing this. I'm aware that you're normally supposed to rotate before a translation, but I think it works different in LWJGL? I might be wrong on this, though.

Every object has its own X, Y, Z position in the world, as has the camera. But the whole interation between them has confused me to no end now!

Thanks for any assistance anyone can offer : )

Edited by PixelPrime11, 09 November 2012 - 11:12 AM.

### #2mhagain  Members

12436
Like
0Likes
Like

Posted 09 November 2012 - 11:25 AM

Matrix multiplication is not commutative, so m1 * m2 != m2 * m1. The correct order to use will depend on the matrix library you're using.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.

### #3PixelPrime11  Members

108
Like
0Likes
Like

Posted 09 November 2012 - 01:45 PM

I'm not sure what you mean by which Matrix Library, unless you mean LWJGL's implementation of this?

The methods I use to accomplish the transformations are as follows:

[source lang="java"]glLoadIdentity();glTransform3f(camera.x, camera.y, camera.z);glRotate3f(camera.yaw, 0.0f, 1.0f, 0.0f);glRotate3f(camera.pitch, 1.0f, 0.0f, 0.0f);[/source]

So, if I were trying to draw an object in the world, I'd call the above code first, then this:

[source lang="java"]// move to the object's coordinatesglTranslate3f(position.x, position.y, position.z);// rotate the object (Y axis only)glRotate3f(rotation.y, 0.0f, 1.0f, 0.0f);// draw the objectglBegin(GL_QUADS); // vertex draw operationsglEnd();[/source]

Edited by PixelPrime11, 09 November 2012 - 01:46 PM.

### #4Trienco  Members

2555
Like
0Likes
Like

Posted 11 November 2012 - 10:22 AM

That doesn't seem to make sense. You want to apply the inverse of your camera transformation. There is no actual camera and the point is to move the world in the opposite way, which means reverse direction and reverse order for your camera transformations. You might also want to reconsider your approach using Euler angles sooner rather than later (and no, that doesn't mean using quaternions, it means not using Euler angles).

Unless you're going for a straight forward ground based first person view you will eventually run into a wall when you come to the point where the order in which rotations where applied is actually important.
f@dzhttp://festini.device-zero.de

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.