it's been a while since I wrote that, so bear with me...
Quote:
1) how did u calculate theta by using sqrt(iDx*iDx + iDy*iDy)? what is this procedure of finding the angle called?
I don't think this has a name, you see there are many ways to solve this problem here is what I'm trying to accomplish here. basically our mouse funciton gets called and we calculate the deltaX, and deltaY. we want to rotate the object around the global X axis in proportion to deltaY, and we want to rotate the object about the Y axis in proportion to deltaX. now one way to do this, is to build 2 seperate rotations rotY, rotX. each of them with there rotation angles proportional to delta's given by the mouse. then multiply them together to obtain the final rotation, for example.
Quaternion qY, qX, qRot;(initialized to identity quaternion or somthing)
angleX = ((float)iDy)*DELTA; //you need to multiply by a small constant to scal the rotation, it's just to large otherwise.
angleY = ((float)iDx)*DELTA;
qX.set(1*sin(angleX), 0*sin(angleX), 0*sin(angleX), cos(angleX));
qY.set(0*sin(angleY), 1*sin(angleY), 0*sin(angleY), cos(angleY));
//set the final rotation
qRot = qX*qY;
ok, now the way I do it is slightly more efficent. instead of building two seperate rotations with angles proportional to iDx, and iDy I build a single rotation. the axis I rotate around is the axis (iDy, iDx, 0). this vector is closely related to the hat function, the hat vector is the 2d vector orthognal to the vector being hatted. another way to put it, is I rotate the object around the vector that is perpendicular to the line formued by the start and end points of the mouse's displacement.
...
HAT((x,y)) = (-y,x) because (x,y) DOT HAT((x,y)) = 0, thus the vector orthogonal.
...
the reason I didn't use a negative component in my fromulation. is strictly because of signess, my angles are strictly positive because of my use of the sqrt() otherwise I'd need to take sign in account, for example my angle is positive if the mouse goes right to left OR left to right, obviously those rotate the object in oposite directions, instead of using the angle to take care of this fact, I just use dx, which is positive left to right and negative right to left(hope that makes sense).
anyway, to calculate the angle(the magnitude of the rotation) I simply rotate the object in proportion to the distance travled by the mouse, that is to say
sqrt(dx^2 + dy^2) it's probably more efficent to use the distance squared, but that will give you uneaven rotations, on second thought, don't use the distance squared lol.
Quote:
2) what is iDy*fSin/fNorm for? is it the fields conversion needed when convrting a quaternion to matrix? and if so, why do u need to devide by fNorm?
no, this has nothing to do with a matrix, in my program, everything is kept as a quaternion, until the final rendering stage.
recal the definiton of a quaternion:
q = (a*sin(T), b*sin(T), c*sin(T), cos(T))
where (a,b,c) is the vector to rotate around and is NORMALIZED.
IFF the vector a,b,c is normalized, then the resulting quaternion x,y,z,w is normalized as well.
my division by the norm of of the direction vector (dy, dx, 0) is used to normalize it.
recal that
fNorm = fTheta = sqrt(iDx*iDx + iDy*iDy);
(although, strictly speaking, it is not necessary that a quaternion be normalized, the magnitude of quaternion DOESNT effect it's rotation, however it does matter for the matrix conversion, which relies on the fact that the quaternion is normalized, but you could formulate it differently if you wanted, it also matters that all your quaternions have the same magnitude when you're applying spherical linear interpolation, for simplicity sake we make the magnitude 1, this is the standard way of doing it)
Quote:
3) what is fNorm? is it a normal? what normal? how did u find it using the length calculation in the sqrt? i know that u have to use cros prod to find norms.
you've probably figured this one out by now, lol.
fNorm is the norm(ie magnitude) of the rotation vector (dy, dx, 0) and is used to normalize the rotation vector.
Tim