Author Topic: GetRotation() help  (Read 3377 times)

Offline qcrist

  • byte
  • *
  • Posts: 29
    • View Profile
GetRotation() help
« on: September 08, 2011, 02:13:17 am »
I'm using this code:
Code: [Select]
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 :?

Code: [Select]
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);
« Last Edit: September 08, 2011, 02:46:06 am by qcrist »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: GetRotation() help
« Reply #1 on: September 08, 2011, 07:57:17 am »
Try to avoid working with angles instead of rotation matrices. You might want to check out the align()-method in Object3D instead.

Offline qcrist

  • byte
  • *
  • Posts: 29
    • View Profile
Re: GetRotation() help
« Reply #2 on: September 08, 2011, 06:16:01 pm »
How does one rotate with rotation matricies?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: GetRotation() help
« Reply #3 on: September 08, 2011, 08:03:57 pm »
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.

Offline qcrist

  • byte
  • *
  • Posts: 29
    • View Profile
Re: GetRotation() help
« Reply #4 on: September 08, 2011, 08:08:59 pm »
k

Offline Familyfriend

  • byte
  • *
  • Posts: 7
    • View Profile
Re: GetRotation() help
« Reply #5 on: September 26, 2011, 12:47:16 pm »
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
« Last Edit: September 26, 2011, 03:00:41 pm by Familyfriend »