Trackball - OpenGL
Trackball - OpenGL
Trackball - OpenGL
org
http://www.opengl.org/wiki/Trackball
Trackball
From OpenGL.org
Contents
1 Introduction 2 Having a ball 3 Of mice and manipulation 4 Sit and spin 5 Numeric drift and a snapper 6 Conclusion 7 References
Introduction
The motivation behind the trackball (aka arcball) is to provide an intuitive user interface for complex 3D object rotation via a simple, virtual sphere - the screen space analogy to the familiar input device bearing the same name. The sphere is a good choice for a virtual trackball because it makes a good enclosure for most any object; and its surface is smooth and continuous, which is important in the generation of smooth rotations in response to smooth mouse movements. Any smooth, continuous shape, however, could be used, so long as points on its surface can be generated in a consistent way.
Having a ball
The first step in generating a trackball is defining the ball itself, which is simply a sphere at the origin, , where r is the radius of the sphere. Next we would like to center our sphere on the object we would like to rotate. To do this, we can project the object's center into screen space. Let be the projected object center. The equation for our sphere then becomes . This will place our sphere at the screen space origin, which, in OpenGL, is the lower left corner of the screen by default. We can put the origin amid screen with an additional translation of half the screen dimensions in either direction, , giving the final form of our sphere as . Objects outside the view frustum could be culled via a sphere-frustum collision test, for example.
. 1 4
11.05.2013 21:44
Trackball - OpenGL.org
http://www.opengl.org/wiki/Trackball
View of sphere and hyperbolic sheet in the plane of intersection. The profile curve is C1 continuous at the crossover.
. 2 4
11.05.2013 21:44
Trackball - OpenGL.org
http://www.opengl.org/wiki/Trackball
, for a given mouse x and y. But what of points outside the sphere? Frustum culling restricts us to spheres at least partially visible, but we can still generate points outside of the sphere but within the screen's extent, which would generate complex results (square roots of negative numbers). This can be seen in the explicit form of the sphere, , where and in trouble. are the centered mouse and shorthands from above. Wherever , we're
One nice way to get around this unpleasantness is to use a piecewise combination of surfaces in place of a single sphere. In this way we can switch to one surface in a region where things are awkward in another. One surface that works well in this case is the hyperbolic sheet given by . This surface has the shape of an inverted trumpet, with the mouth piece at infinity along the z axis and the horn opening flaring out to cover the xy-plane. With the sphere nestled snugly at its opening, we can transition very smoothly from a ball to a flaring horn defined everywhere except the origin. The crossover from sphere to sheet occurs at their intersection, which is defined by the circle . One might be tempted to simply ignore points outside the sphere altogether; but as the mouse approaches the perimeter of the sphere response can quickly become clumsy and unintuitive due to z/x and z/y approaching infinity near the silhouette edge. So in addition to avoiding negative numbers in our radical, the primary motivation for the transition is to make rotational falloff as graceful as possible: the farther the mouse ventures from the center of the sphere the less angular displacement is generated between any two mouse positions, which tapers off completely as the sheet flattens off to zero at infinity.
. 3 4
11.05.2013 21:44
Trackball - OpenGL.org
http://www.opengl.org/wiki/Trackball
With each incremental mouse movement from to and then unitize the result to ensure we retain a rotation.
Conclusion
The virtual trackball can provide an intuitive user interface for the interactive rotation of models in 3D.
References
Graphics Gems (http://tog.acm.org/GraphicsGems/) IV (http://tog.acm.org/GraphicsGems/gems.html#gemsiv) Arcball (http://tog.acm.org/GraphicsGems/gemsiv/arcball/) Retrieved from "http://www.opengl.org/wiki_132/index.php?title=Trackball&oldid=3785" Category: Tutorials This page was last modified on 25 July 2011, at 05:08. This page has been accessed 30,663 times.
. 4 4
11.05.2013 21:44