How to change the center of the trackball in its regular implementation?

297 views Asked by At

I have successfully implemented a trackball in java using the below two tutorials:

  1. http://nehe.gamedev.net/tutorial/arcball_rotation/19003
  2. http://www.java-tips.org/other-api-tips/jogl/arcball-rotation-nehe-tutorial-jogl-port.html

This trackball is centered at the screen center. Now, I wish to center it at any point on the screen. How can I incorporate the center logic in the existing code? How the normalization of mouse coordinates change due to introduction of center?

1

There are 1 answers

0
DJClayworth On BEST ANSWER

This can be easily achieved by transforming the mouse coordinates. When you transform the mouse coordinates as you do at the start of the first tutorial, instead of just transforming them as specified to the range -1..1, first subtract the offset from the centre of the screen where you want to make your trackball centre. So to make the trackball centre 50 pixels to the right and 20 pixels above the centre, use

MousePt.X  =  ((MousePt.X-50) /Width)*2)-1;
MousePt.Y  =  ((MousePt.X-20) /Height)*2)-1;