Trackball view controll

Hello,

This is perhaps not strictly JoGL, but I thought I’d try here anyway.

I want to rotate the objects in JOGL with a trackball type of interface, using the mouse.
This means of rotation is common in most 3D CAD software and means rotation around a fixed coordinate system.

Is there a good example of this or even some reuseable code around? I’d hate to reinvent the wheel.

Thanks
/Jonas

Hi Jonas,

I have arcball control implemented in my app which I think is what your talking about. It’s a cad like app where you can rotate the model around by clicking on it w/ the mouse. I think pepijnv also posted some code or a link somewheres on his version.

I can post when I get a chance later today if you like.

Nehe lesson 48 includes that bit of code.

This was exactly what I was hoping for.

Many thanks gentlemen,

/Jonas

but what about moving objects in 3d space? how to calculate vector i should move my object in 3d from two points betwean i drag a mouse pointer? is there any tut how to do that ???

First you have to now which object was “selected”… than you should transform the mouse-position on the projection plane to the worldcoordinates of the mouse on the projection plane via gluUnproject. Than you can cast a ray from the camery-eye through this point and see at which point it intersects with your draggable geometry.

So you have the initial position of the mouse on your geometry. Than you can calc the above mentioned ray on every mouse-dragged call.

Than there is a problem: You don’t know where to place the object on the new caled ray. you could for example calc the distance fomr eye to the intersecting point and apply this length to your new ray. (you would move your object on a big virtual sphere in this case). you could also just use the same z coordinate (if it fits for your setup.

Finally you have 2 points one on your “before”-ray one on your “actual”-ray. Your translation vector would be p2.sub(p1). Of course you could do some rotaing and stuff to ensure you see the geometry from the same perspective.

I hope this helps…

saxer thank you very much , i also found some little tutorial about those gl functions here:
http://students.iiit.net/~vkrishna/data/unproj.html

and jogl example:
http://www.java-tips.org/other-api-tips/jogl/how-to-use-gluunproject-in-jogl.html

thanks again :smiley: