www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: mkranga on June 29, 2013, 03:36:37 pm

Title: GetRotationX
Post by: mkranga 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
Title: Re: GetRotationX
Post by: EgonOlsen 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 (http://www.jpct.net/forum2/index.php/topic,576.0.html)
Title: Re: GetRotationX
Post by: mkranga 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;
}