4

Greetings all,

As seen in the image,

alt text

I have an object named O (set of linestripes).Its object-coordinate system is (x',y',z'). I translate,rotate this object in my OpenGL scene using following code snippet:

glPushMatrix();
 glTranslatef(Oz, Oy,Oz);
 glRotatef(rotationX , 1.0, 0.0, 0.0);  
 glRotatef(rotationY, 0.0, 1.0, 0.0);
 glRotatef(rotationZ, 0.0, 0.0, 1.0); 
contour->render();
glPopMatrix()

;

I have a point called H ,which is translated to (hx,hy,hz) world coordinates using

glPushMatrix();
 glTranslatef(hx,hy,hz);
glPopMatrix();

If I am correct, (Oz,Oy,Oz) and (hx,hy,hz) are world coordinates.

Now,what I want todo is calculate the position of H (hx,hy,hz) relative to O's object-coordinate system.(x',y',z'); As I understood,I can do this by calculating inverse transformations of object O and apply them to point H.

Any tips on this? Does OpenGL gives any functions for inverse-matrix calculation ? If I somehow found inverse-matrices what the order of multiplying them ?

Note : I want to implement "hammer" like tool where at point H ,I draw a sphere with radius R.User can use this sphere to chop the object O like a hammer.I have implemented this in 2D ,so I can use the same algorithm if I can calculate the hammer position relative to (x',y',z')

Thanks in advance.

3
  • 1
    If I understand your question, wouldn't it just be {Ox - hx, Oy - hy, Oz - hz} (ie, glTranslatef(Ox - hx, Oy - hy, Oz - hz);)? If you already have your global vectors O and h, it's a simple matter of vector subtraction, leaving matrix manipulation completely out of the equation. Your original solution sounds correct, by the way.
    – MrGomez
    Dec 7, 2010 at 4:28
  • hi,I have to change the original object-coordinates of the object O.That means,I have to compare object-coordinates, not world-coordinates. Dec 7, 2010 at 4:32
  • 1
    No worries. A quick refresher reminded me that OpenGL doesn't provide a general purpose matrix library. You'll need to use a separate library for that, or perform the calculation (mathworld.wolfram.com/MatrixInverse.html) yourself.
    – MrGomez
    Dec 7, 2010 at 5:17

2 Answers 2

2

Inverting the matrix would be the general solution, but as far as I can see this isn't actually a "general" problem. Rather than undoing an arbitrary transformation, you are trying to do the reverse of a known sequence of transformations, each of which can be inverted very simply. If your object-to-world transformation is:

glTranslatef(Ox, Oy, Oz);
glRotatef(rotationX , 1.0, 0.0, 0.0);
glRotatef(rotationY, 0.0, 1.0, 0.0);
glRotatef(rotationZ, 0.0, 0.0, 1.0);

Then the world-to-object inverse is just:

glRotatef(-rotationZ, 0.0, 0.0, 1.0);
glRotatef(-rotationY, 0.0, 1.0, 0.0);
glRotatef(-rotationX , 1.0, 0.0, 0.0);
glTranslatef(-Ox, -Oy, -Oz);

Basically, just back out each applied transformation in the opposite order originally applied.

2

Yes, basically you're right that you can perform this operation by the translation matrix

M = O^-1 * H

any like you already guessed you need the inverse of O for this. OpenGL is not a math library though, it only deals with rendering stuff. So you'll have to implement the inversion yourself. Google for "Gauss Jordan" to find one possible algorithm. If you can be absolutely sure, that O consists only of rotation and translation, i.e. no shearing or scaling, then you can shortcut by transposing the upper left 3x3 submatrix and negating the uppermost 3 elements of the rightmost column (this exploits the nature of orthogonal matrices, like rotation matrices, that the transpose is also the inverse, the upper left 3x3 is the rotational part, the inverse of a translation is negating the elements of it's vector which is the rightmost upper 3 elements).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.