Author Topic: GetRotationX  (Read 800 times)

Offline mkranga

  • byte
  • *
  • Posts: 5
    • View Profile
GetRotationX
« on: June 29, 2013, 03:36:37 pm »
Hi,

im rotation object(3d) using
Code: [Select]
rotateX(n)
how do i get current rotation?(specific axis)

if jpct can have function like below would be grate
Code: [Select]
float  obj3d.GetRotationX()
thanks

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: GetRotationX
« Reply #1 on: June 29, 2013, 03:57:40 pm »
You should try to avoid working with angles in that way if possible. You can derive angles from a matrix, but because each matrix can be created from an unlimited number of rotations, the angles don't reflect the actual angles that where used to create it but only one possible solution. If you need the angles, try to keep track of them yourself. You might as well use something like  this: http://www.jpct.net/forum2/index.php/topic,576.0.html

Offline mkranga

  • byte
  • *
  • Posts: 5
    • View Profile
Re: GetRotationX
« Reply #2 on: June 30, 2013, 10:40:27 am »
My object interact with mouse. so its little  difficult to track rotation by my self.

This works.  Thank you .
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;
}