Main Menu

ArcBall

Started by wmjoers, July 11, 2005, 06:38:21

Previous topic - Next topic

wmjoers

Has anyone implemented the ArcBall class using the Quaternion and Vector classes in  LWJGL???

wmjoers

Another question....

The Quaternion class has a method called .setFromAxisAngle(Vector4f a1)
...shouldn't there be a .toAxisAngle(...) as well?

...or can you obtain that vector in some other way?

DeX

I agree, there should be a toAxisAngle function. Instead I am doing this process manually:

float ax, ay, az;
float quatScale = (float)Math.sqrt(quat.getX()*quat.getX() + quat.getY()*quat.getY() + quat.getZ()*quat.getZ());
float quatAngle;
if (quatScale == 0) { //no rotation
	ax = 1; ay = 0; az = 0;
	quatAngle = 0;
}else{
	ax = quat.getX() / quatScale;
	ay = quat.getY() / quatScale;
	az = quat.getZ() / quatScale;
	quatAngle = 2 * (float)Math.acos(quat.getW());
}


The axis is stored in ax, ay and az and the angle in quatAngle.

It would be really nice if someone could optimise this code and put it into a function for the Quaternion class. Anyone?