Sign in to follow this  
vNistelrooy

Quaternion multiplication

Recommended Posts

I have decided that it is finally time to use quaternions for the camera, however I seem to be unable to multiply quaternions or D3DX's quaternion multiplication does something more than just multiplying. Here is the *= operator, q is the const reference to the right operand. vx,vy,vz are the imaginary vector parts and w is the real part.
	float d=vx*q.vx + vy*q.vy + vz*q.vz;

	float nvx=vy*q.vz - q.vy*vz + vx*q.w + q.vx*w;
	float nvy=vz*q.vx - q.vz*vx + vy*q.w + q.vy*w;
	float nvz=vx*q.vy - q.vx*vy + vz*q.w + q.vz*w;
	w=w*q.w - d;

	vx=nvx;
	vy=nvy;
	vz=nvz;


?

Share this post


Link to post
Share on other sites
Here's my guess: DirectX uses 'reversed' quaternion multiplication to be consistent with the use of row vectors, and you're using the standard form. I would try changing these lines:

float nvx = vy * q.vz - q.vy * vz + vx * q.w + q.vx * w;
float nvy = vz * q.vx - q.vz * vx + vy * q.w + q.vy * w;
float nvz = vx * q.vy - q.vx * vy + vz * q.w + q.vz * w;

To this:

float nvx = q.vy * vz - vy * q.vz + vx * q.w + q.vx * w;
float nvy = q.vz * vx - vz * q.vx + vy * q.w + q.vy * w;
float nvz = q.vx * vy - vx * q.vy + vz * q.w + q.vz * w;

And see if that fixes the problem.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this