Programming for GVIS

 

Introduction

    GVIS is a small C++ source code repository which forms the basis of the first homework
assignment.  When built, GVIS provides a simple application for the display and manipulatation of user-defined geometric  data structures.  The goal of GVIS is to remove the tedious work of coding a user-interface, and encourage people to focus on the implementation of data structures and algorithms.
    Create GVIS by creating typing "make" in the main directory, and run the resulting executable "gvis".  Try manipulating both the two-dimensional and three-dimensional scenes using the mouse buttons.  Instructions for the functionality of each mouse button is displayed in your terminal by GVIS.  There are some subtle UI gestures.  For example to create an object press the middle mouse button without moving the mouse.  To delete an object, press the right mouse button on an object without moving the mouse.

C++ Class Hierarchy

     For people who are already up to speed in C++, here is a quick overview of the class hierarchy in GVIS.
     AppView is a base class which provides basic OpenGL viewing functionality.  App2DView and App3DView derive from AppView, and provide an orthographic (2D) viewing canvas, and a perspective (3D) viewing canvas, respectively.  See app.[CH] to see how these subclasses selectively overload AppView's virtual functions.
    GeomObject is a base class which defines the interface for geometric objects.   Objects, at minimum, have a position and a color, and a set of "pure virtual"  functions which must be defined for any new class you choose to create.  For examples, see object.[CH], in which the XYRect and Sphere classes derive from GeomObject by fulfilling the pure virtual function definitions.
 

Main Event Loop

     The main event loop processes all user events ( mouse button press, mouse button release, mouse motion, window resizing, etc. ).  There are two major functions which provide the basis for object
manipulation, UserAction ( ) and User Handle ( ).
 
 

     UserAction() is called during a mouse button press or release.  In GVIS, the application implements
UserAction so that it calculates the intersection of all the objects based on the eye-far ray which is generated from the event loop.  If an object is found to intersect the eye-far ray, the function returns
the value "1" to notify the event loop of a modification, resulting in a screen redraw.  If there was an object-ray intersection, UserAction sets an internal pointer called "_currObject" to the intersected object.  This code can be found in app.[CH]
 

 
    UserHandle() is called during a mouse motion event.  This may seem strange at first, but there is a good reason for this.  If you have used GVIS, you may have noticed some special behavior.  If an object is selected, rotation and translation are disabled, the object is manipulated according to the mouse motion.  If no object is selected, then GVIS translates or rotates the scene during the mouse motion.  The way GVIS "knows" whether to perform object manipulation or scene rotation/translation is through the UserHandle ( ) routine.  If the UserHandle ( ) routine returns NULL, then GVIS will perform a rotaion or translation on the scene.  Otherwise if UserHandle ( ) returns a pointer to a user-defined object then GVIS will call routines for object manipulation via UserAction.  These routines are supplied by the user.
 
 

Extending the user interface

     The user interface is based on the XForms library, which is a GUI toolkit based on
Xlib for X Window Systems.  You do not need to know anything about XForms or X programming in order to work with GVIS.  If you are already familiar with Xforms, you are encouraged to make changes/additions to the user-interface to support any creative ideas you might have.  If you don't know about XForms, and are interested in learning more, you can begin by running :
 

>    fdesign    gvis_xforms.fd

    The command "fdesign"  stands for Form Designer.  The Form Designer allows a user to input buttons, windows, text, etc. without any coding.   "fdesign" can be found in the XForms library in the Athena 6.838 locker, under "6.838/geomtools/packages/XForms/DESIGN".   

Questions?

Don't hesitate to email neel@graphics.lcs.mit.edu, if you have any questions or comments.