I had implemented arcball rotation after the NEHE #48 tutorial which seems to be working normally, except that everytime I click on my model to rotate it, it resets (snaps back) as if it were in the original position before it starts to rotate.
Below is pretty much how I have the arcball implemented in my class that implements GLEventListener.
private ArcBall arcBall = null;
private Point2f mousePoint = new Point2f();
public void init(GLDrawable drawable) {
// ...
arcBall = new ArcBall(0, 0);
}
public void reshape(GLDrawable drawable, int x, int y, int width, int height) {
// ...
arcBall.setBounds(width, height);
}
public void display(GLDrawable drawable) {
float[] transf = new float[16];
// ...
arcBall.transform.get(transf);
gl.glMultMatrixf(transf);
drawModel(drawable, gl);
}
public void mousePressed(MouseEvent me) {
mousePoint.set((float) me.getX(), (float) me.getY());
if (SwingUtilities.isLeftMouseButton(me)) {
arcBall.lastRot = arcBall.thisRot;
arcBall.click(mousePoint);
}
}
public void mouseDragged(MouseEvent me) {
mousePoint.set((float) me.getX(), (float) me.getY());
if (SwingUtilities.isLeftMouseButton(me)) {
// Update end vector and get rotation as a quaternion.
arcBall.drag(mousePoint, arcBall.quat);
// Convert quaternion into matrix3f.
arcBall.matrix3fSetRotationFromQuat4f(arcBall.thisRot, arcBall.quat);
// Accumulate last rotation into this one.
arcBall.matrix3fMulMatrix3f(arcBall.thisRot, arcBall.lastRot);
// Set our final transform's rotation from this one.
arcBall.matrix4fSetRotationFromMatrix3f(arcBall.transform, arcBall.thisRot);
}
this.gldrawable.display();
return;
}
If anyone has any ideas, any help much appreciated.