We noticed that some popular 3D app can smoothly rotate the model even with the mouse out of the virtual trackball sphere (instead of spinning the model around the Z axis coming out of the screen as we all do)
What is the trick behind this?
As you know when the mouse pointer is out of the sphere one of the vector components is zero and the cross product always gives a rotation axis perpendicular to the screen surface.
I wanted also to add - for a better understanding - that the product I used to make movies, calls
Turntable: rotate around world axes
Trackball: rotate relative to view
In effect we managed to mimic the “Smart trackball” using the turtable approach on camera up and right axis, but unfortunately the model is not stick at the mouse cursor as in the movie provided.
Think about it, scaling the trackball would simply keep the mouse position on the sphere edge (circle) always producing a rotation axis perpendicular to the screen.
We also tried to:
switch to turntable when outside of the spere but it doesn’t look fine
use a trackball diameter equal to the viewport diagonal, again with no luck
Sure, here’s a random idea. The idea with trackball rotation is you project the sphere to a plane, and then the mouse selects a point on the plane (which corresponds to a point on the sphere), moves it to another point on the plane, and computes the corresponding rotation that maps the first point to the second.
To be able to rotate more than just a hemisphere (all that’s visible in the projection from sphere to plane), try a different projection. E.g. Paul Debevec has a full sphere mapping onto a plane for his lightprobe images - he details the math of the projection on http://www.debevec.org/probes/ . If you take your two points on the plane to be points according to this mapping, then you could rotate past the normal hemisphere of trackball rotation.
It was just a random idea. There’s plenty of research on this topic in the 3D UI literature. Check out the paper “Virtual Trackballs Revisited”. The authors have code up here: http://image.diku.dk/research/trackballs/index.html As described in that paper, you probably want a Bell trackball.
It looks like the virtual trackball you want is Andy Hanson’s rolling ball" technique. He calls it context free, since you get the same rotation regardless of whether you’re in the sphere or not. It does rotation in the x-y plane, but not around z except via a weird side effect that you can read about – see below).
The technique is described in Graphics Gems III, though the code given is pretty much just an outline. A more thorough explanation can be found in Gems V and in his new book “Visualizing Quaternions”.
I’m currently studying the differences between the most popular virtual trackball algorithms (Chen, Hanson, Shoemake and Bell). So I am very interested in this topic. The only difference I see between your smart trackball movie and Hanson’s rolling ball is that the movie doesn’t show the precession in Hanson’s algorithm (where small rotations cause the entire ball to rotate around the z-axis in the opposite direction).
Could you tell me what other difference(s) you see?
In my opinion the difference is that when the mouse is over the sphere (diameter of the smallest viewport dim) it works like the Shoemake one while out side it work like a rolling ball.