A TrackBall object translates widget events from a draw widget (created with the WIDGET_DRAW function) into transformations that emulate a virtual trackball (for transforming object graphics in three dimensions).
This object class is implemented in the IDL language. Its source code can be found in the file
trackball__define.pro
in the
lib
subdirectory of the IDL distribution.
See TrackBall::Init
The example code below provides a skeleton for a widget-based application that uses the TrackBall object to interactively change the orientation of graphics.
Create a trackball centered on a 512x512 pixel drawable area, and a view containing the model to be manipulated:
wDraw = WIDGET_DRAW(wBase, XSIZE=xdim, YSIZE=ydim, $
GRAPHICS_LEVEL=2, /BUTTON_EVENTS, $
/MOTION_EVENTS, /EXPOSE_EVENTS, RETAIN=0 )
WIDGET_CONTROL, wBase, /REALIZE
WIDGET_CONTROL, wDraw, GET_VALUE=oWindow
oTrackball = OBJ_NEW('Trackball', [xdim/2.,ydim/2.], xdim/2.)
oModel = OBJ_NEW('IDLgrModel')
You must handle the trackball updates in the widget event-handling code. As the trackball transformation changes, update the transformation for the model object, and redraw the view:
bHaveXform = oTrackball->Update( sEvent, TRANSFORM=TrackXform )
oModel->GetProperty, TRANSFORM=ModelXform
oModel->SetProperty, TRANSFORM=ModelXform # TrackXform
For a complete example, see the file
surf_track.pro
, located in the
object
subdirectory of the
examples
directory of the IDL distribution. The SURF_TRACK procedure uses IDL widgets to create a graphical user interface to an object tree, creates a surface object from user-specified data (or from default data, if none is specified), and places the surface object in an IDL draw widget. The SURF_TRACK interface allows the user to specify several attributes of the object hierarchy via pulldown menus.
The TrackBall:: Init function method initializes the TrackBall object. TrackBall is described above.
TrackBallObj = OBJ_NEW('TrackBall', Center , Radius )
Result =
Obj
->
[TrackBall::]
Init(
Center, Radius
) (
In a subclass' Init method only
.)
Set this keyword to an integer value to indicate the axis about which rotations are to be constrained if the CONSTRAIN keyword is set. Valid values include:
Set this keyword to indicate that the trackball transformations are to be constrained about the axis specified by the AXIS keyword. The default is not to constrain the transformations.
Set this keyword to a bitmask to indicate which mouse button to honor for trackball events. The least significant bit represents the leftmost button, the next highest bit represents the middle button, and the next highest bit represents the right button. The default is 1b, for the left mouse button.
The TrackBall:: Reset procedure method resets the state of the TrackBall object. TrackBall is described above.
TrackBallSet this keyword to an integer value to indicate the axis about which rotations are to be constrained if the CONSTRAIN keyword is set. Valid values include:
Set this keyword to indicate that the trackball transformations are to be constrained about the axis specified by the AXIS keyword. The default is not to constrain the transformations.
Set this keyword to a bitmask to indicate which mouse button to honor for trackball events. The least significant bit represents the leftmost button, the next highest bit represents the middle button, and the next highest bit represents the right button. The default is 1b, for the left mouse button.
The TrackBall:: Update function method updates the state of the TrackBall object based on the information contained in the input widget event structure. The return value is nonzero if a transformation matrix is calculated as a result of the event, or zero otherwise. TrackBall is described above.
TrackBallSet this keyword to a bitmask to indicate which mouse button to honor for trackball events. The least significant bit represents the leftmost button, the next highest bit represents the middle button, and the next highest bit represents the right button. The default is 1b, for the left mouse button.