GetRotation() help

Started by qcrist, September 08, 2011, 02:13:17 AM

Previous topic - Next topic

qcrist

I'm using this code:
public SimpleVector deriveAngles(Matrix mat) {
    SimpleVector s=new SimpleVector();
    float[] m=mat.getDump();
    s.x=(float) Math.atan(m[9]/m[10]);
    s.y=(float) Math.asin(-m[2]);
    s.z=(float) Math.atan(m[4]/m[0]);
    return s;
}


Which is supposed to change rotation matrices to angles. (I think?)

But the following code does not work :o

Both objects should be rotated the same amount, but they arnt :?


Object3d obj1,obj2;
[make objects bla bla bla]
SimpleVector rot = deriveAngles(obj1.getRotationMatrix());
obj2.rotateY(rot.y);
obj2.rotateX(rot.x);
obj.rotateZ(rot.z);


EgonOlsen

Try to avoid working with angles instead of rotation matrices. You might want to check out the align()-method in Object3D instead.

qcrist

How does one rotate with rotation matricies?

EgonOlsen

What i meant was, don't try to get angles from a matrix and use them if you can use the matrix itself. There are cases, where you need the actual angle but these are rare. Your code snippet doesn't look like one to me. As mentioned, align should do the trick here.


Familyfriend

#5
ok, i'm tring to implement a die with physic. I have from the physic framework a Matrix4, how should i use the aling()  method?
I expeted to find a align( Matrix m ) method but there isn't one so how can i apply a Matrix to an object3D by align()?

this i probably a dumb question, but you know, i'm new to 3D graphic and physics as well ^^.


EDIT:
i've been tring with setRotation() method but then it shows only part of the texture.
To show the die i'v implemented  a cube extending Object 3D, any face of the cube is made of 2 tringles defined by clock wise verticies and has a different  texture.
Do i need to do something in the object3D initialization or you think it's just a rotation mistake?
i have to add that when i rotate with the camera around the object i can see all the faces without any texture problem, the problem seems to be when i try to rotate the object3D itself.


Thx in advance for the response