TrackBall

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.

Superclasses

This class has no superclasses.

Subclasses

This class has no subclasses.

Creation

See TrackBall::Init

Methods

Intrinsic Methods

This class has the following methods:

Example

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:

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

 

oTrackball = OBJ_NEW('Trackball', [xdim/2.,ydim/2.], xdim/2.)

oView = OBJ_NEW('IDLgrView')

oModel = OBJ_NEW('IDLgrModel')

oView->Add, oModel

XMANAGER, 'TrackEx', wBase

 

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:

 

PRO TrackEx_Event, sEvent

...

bHaveXform = oTrackball->Update( sEvent, TRANSFORM=TrackXform )

IF (bHaveXform) THEN BEGIN

oModel->GetProperty, TRANSFORM=ModelXform

oModel->SetProperty, TRANSFORM=ModelXform # TrackXform

oWindow->Draw, oView

ENDIF

...

END

 

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.


TrackBall::Init

The TrackBall:: Init function method initializes the TrackBall object. TrackBall is described above.

TrackBall

Calling Sequence

Obj = OBJ_NEW('TrackBall', Center , Radius )

or

Result = Obj -> [TrackBall::] Init( Center, Radius )         ( In a subclass' Init method only .)

Arguments

Center

A two-dimensional vector, [ X , Y ], specifying the center coordinates of the trackball. X and Y should be specified in device units.

Radius

The radius of the trackball, specified in device units.

Keywords

AXIS

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:

CONSTRAIN

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.

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.


Trackball::Reset

The TrackBall:: Reset procedure method resets the state of the TrackBall object. TrackBall is described above.

TrackBall

Calling Sequence

Obj -> [TrackBall::] Reset( Center, Radius )

Arguments

Center

A two-dimensional vector, [ X , Y ], specifying the center coordinates of the trackball. X and Y should be specified in device units.

Radius

The radius of the trackball, specified in device units.

Keywords

AXIS

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:

CONSTRAIN

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.

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.


TrackBall::Update

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.

TrackBall

Calling Sequence

Result = Obj -> [TrackBall::] Update( sEvent )

Arguments

sEvent

The widget event structure.

Keywords

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 will contain a 4 x 4 element floating-point array if a new 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 translation in the X-Y plane rather than rotation about an axis.