Hello Guest

ArcBall

  • 2 Replies
  • 7213 Views
ArcBall
« on: July 11, 2005, 06:38:21 »
Has anyone implemented the ArcBall class using the Quaternion and Vector classes in  LWJGL???

ArcBall
« Reply #1 on: July 11, 2005, 14:28:42 »
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?

*

Offline DeX

  • *
  • 15
ArcBall
« Reply #2 on: September 14, 2005, 09:29:47 »
I agree, there should be a toAxisAngle function. Instead I am doing this process manually:

Code: [Select]

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?