CAT_TRACKBALL__DEFINE Name
CAT_TRACKBALL Purpose
This object translates widget events for draw widgets into
transformations that emulate a virtual trackball (for transforming
object graphics in three dimensions).
Category
Object Graphics.
Calling Sequence
To initially create:
oTrackball = OBJ_NEW('Cat_Trackball', Center, Radius)
To update the trackball state based on a widget event:
oCat_Trackball->Update, sEvent
To re-initialize the trackball state:
oCat_Trackball->Reset, Center, Radius
To destroy:
OBJ_DESTROY, oCat_Trackball Inputs
CAT_TRACKBALL::INIT:
Center: A two-dimensional vector, [x,y], representing the requested
center (measured in device units) of the trackball.
Radius: The requested radius (measured in device units) of the
trackball.
CAT_TRACKBALL::UPDATE:
sEvent: The widget event structure. The event type indicates
how the trackball state should be updated.
CAT_TRACKBALL::RESET:
Center: A two-dimensional vector, [x,y], representing the requested
center (measured in device units) of the trackball.
Radius: The requested radius (measured in device units) of the
trackball.
Keyword Parameters
CAT_TRACKBALL::INIT:
AXIS: Set this keyword to indicate the axis about which
rotations are to be constrained if the CONSTRAIN
keyword is set to a nonzer value. Valid values
include:
0 = X-Axis
1 = Y-Axis
2 = Z-Axis (default)
CONSTRAIN: Set this keyword to a nonzero value to indicate that
the trackball transformations are to be constrained
about a given axis (as specified by the AXIS
keyword). The default is zero (no constraints).
MOUSE: 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.
CAT_TRACKBALL::UPDATE:
MOUSE: 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.
TRANSFORM: Set this keyword to a named variable that upon
return will contain a floating point 4x4 array
if a transformations matrix is calculated as
a result of the widget event.
TRANSLATE: Set this keyword to indicate that the trackball
movement should be constrained to x and y translation
rather than rotation about an axis.
CAT_TRACKBALL::RESET:
AXIS: Set this keyword to indicate the axis about which
rotations are to be constrained if the CONSTRAIN
keyword is set to a nonzer value. Valid values
include:
0 = X-Axis
1 = Y-Axis
2 = Z-Axis (default)
CONSTRAIN: Set this keyword to a nonzero value to indicate that
the trackball transformations are to be constrained
about a given axis (as specified by the AXIS
keyword). The default is zero (no constraints).
MOUSE: 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.
Outputs
CAT_TRACKBALL::UPDATE:
This function returns a 1 if a transformation matrix is calculated
as a result of the widget event, or 0 otherwise.
Example
Create a trackball centered on a 512x512 pixel drawable area, and
a view containing the model to be manipulated:
xdim = 512
ydim = 512
wBase = WIDGET_BASE()
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
oCat_Trackball = OBJ_NEW('Cat_Trackball', [xdim/2.,ydim/2.], xdim/2.)
oView = OBJ_NEW('IDLgrView')
oModel = OBJ_NEW('IDLgrModel')
oView->Add, oModel
XMANAGER, 'TrackEx', wBase
In the widget event handler, handle trackball updates.
As the trackball transformation changes, update the transformation
for a model object (instance of IDLgrModel), and redraw the view:
PRO TrackEx_Event, sEvent
...
bHaveXform = oCat_Trackball->Update( sEvent, TRANSFORM=TrackXform )
IF (bHaveXform) THEN BEGIN
oModel->GetProperty, TRANSFORM=ModelXform
oModel->SetProperty, TRANSFORM=ModelXform # TrackXform
oWindow->Draw, oView
ENDIF
...
END Modification History
Written by: DD, December 1996
Modified by David Fanning, Aug 9, 2003 to work with Catalyst System.
Required modification to UPDATE method to allow events from objects.