Quarternion rotation problems
First of all, my apologies for posting this in two forums.I put it in the graphics first. Anyway, I''m rotating a 3D object currently with a single unit rotation quarternion. i.e.
w1 = Math.cos(t/2);
x1 = 0 * Math.sin(t/2);
y1 = 100 * Math.sin(t/2);
z1 = 0 * Math.sin(t/2);
q1 = new Quarternion(w1, new Vector(x1,y1,z1));
unit = Math.root(v.x*v.x + v.y*v.y + v.z*v.z + w*w);
v.x /= unit;
v.y /= unit;
v.z /= unit;
w /= unit;
...then converting to a matrix,
x = q.v.x; y = q.v.y; z = q.v.z; w = q.n;
x2 = x*x; y2 = y*y; z2 = z*z;
r[0][0] = 1 - 2*y2 - 2*z2;
r[0][1] = 2*x*y - 2*w*z;
r[0][2] = 2*x*z + 2*w*y;
r[1][0] = 2*x*y + 2*w*z;
r[1][1] = 1 - 2*x2 - 2*z2;
r[1][2] = 2*y*z - 2*w*x;
r[2][0] = 2*x*z - 2*w*y;
r[2][1] = 2*y*z + 2*w*x;
r[2][2] = 1 - 2*x2 - 2*y2;
And multiplying all object vectors by the matrix. The x,y,z rotation seems to work fine, but the w rotation keeps fluctuates wildly in speed, am I not specifying the angle correctly or is there a problem with my code? I suspect the problem is the first one.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement