Exercise 2 Part I - Arcball User Interface
Submission date 11/12/05
This exercise can be submitted in pairs
Introduction:
In this exercise you will create an application to intuitively view 3D object. The program can rotate the object, change its position and zoom in and out. You will use OpenMesh to represent the 3D objects and to read them from disk (no parser to write in this exercise !). In part II of ex2 we'll perform complex operations on the mesh (which will be much more difficult to achieve without OpenMesh).
Reference Material
Arcball:
OpenMesh:
- OpenMesh web site
- Some important classes for this exercise:
- Vector ,a class to represent an n-dimensional vector (we'll need 2D and 3D for this exercise)
- PolyMesh a generic class to represent polygonal mesh.
Detailed description:
- After reading the object estimate its dimensions and resize (scale) it such that it will fit entirely within the Arcball's circle and in the viewing frustum. Also translate the object's center to the origin.
- Start with field of view angle to be 30 degrees.
- Reshape policy: the window has to resize its contents when it is being resized. Yet you should keep the aspect ratio of the window and of the frustum the same (so no distortions will occur). - Resize the school solution's window to get a feeling of how it should work.
- Mouse Operations:
- Left button - Rotates the object according the Arcball algorithm.
- Middle button - Zoom in / out (up & down with mouse) by changing the field-of-view angle (don't use scale).
- Right button - Moves the object on the plane parallel to the camera (projection plane).
- A few points regarding the Arcball:
- You should paint a green circle showing the Arcball / window intersection circle. This circle's radius should be 40% of the min{width, height} (the window's dimensions). This circle is a 2D drawing. It should be drawn above the 3D object
- Choose a value for OBJECT_DEPTH (constant). Also choose values for OBJECT_B_RAD such that OBJECT_DEPTH - OBJECT_B_RAD > 0.
- Then set clipping planes: near to be OBJECT_DEPTH - OBJECT_B_RAD and far to be OBJECT_DEPTH + OBJECT_B_RAD.
-
Make sure that the object will rotate around the point in 3D: (0,0,-OBJECT_DEPTH).
Important Note: The total transformation of the object by the Arcball, should be the accumulation of COMPLETED transformations done by the user so far + the current transformation (assuming the user is clicking the mouse button). Completed Transformation is defined as the final transformation between the mouse down event and the mouse up event. The current transformation is the transformation performed by the user while dragging the mouse (motion event). Do not accumulate transformations done during motion event, but display them. Accumulate only the the mouse button is released.
Using OpenMesh:
In ~cg/www/exercises/ex2/stuff/code you can find example code and makefile that uses OpenMesh to accomplish several simple tasks. In the main() function there are several commented function calls. Uncomment them one by one and make sure that you understand how to operate them. OpenMesh library is located at ~cg/ww/exercises/ex2/ you can include it from there. OpenMesh is compiled as a dynamic library.
In order to run it you'll have to set the environment variable LD_LIBRARY_PATH to include the location of the libraries.
In the same folder you'll find a file named setpath.csh - run it (source setpath.csh) in order to set this variable correctly. You also need to run this script before running the school solution
Displaying the mesh:
The mesh is drawn in wire frame mode meaning that only the edges are drawn. The easiest way to do that is to iterate over all the edges and display them. You can also iterate over all the faces and display the mesh this way. It is your choice.
Program Syntax (usage)
ex2 <input-file>
- The program should load the mesh and display it in a window, the behavior should follow the description above.
- Since OpenMesh reads the mesh for us we can supply all the formats that OpenMesh supports: .OBJ .OFF .STL .OM.
- If you find on the web (or create yourself) meshes in PLY or 3ds format you can convert to OBJ using the executables ply2obj and 3ds2obj placed in the exercise's folder.
- Open one of theses files in a text editor to make sure that you understand their syntax.
- Note that files that you download from the web (or create in a 3D package such as Maya or 3DS MAX may contain information such as normals, texture coordinates, material information, etc. trying to read these files using OpenMesh may generate warnings - you can ignore them for now.
School solution + models
The school solution and some models are placed at: ~cg/www/exercises/ex2/stuff
General Requirements
- Pressing the 'q' or 'Q' should exit the program.
- Pressing 'r' or 'R' should reset to the initial view of the model: including the rotation, translation and zoom (field of view)
- Use double buffering and RGB modes for display i.e. (GLUT_DOUBLE | GLUT_RGB).
- Be kind and use a meaningful names for your variables and functions, use remarks wherever you feel the its not clear enough. Remember that your code we be read. unreadable code will loose points !
Submission requirements:
- All the source files + makefile
- Any interesting models you created (not
downloaded!!)
Tips
- Design program structure before you start programming
- Add the program's features one by one:
- Start by implementing the Arcball while displaying a predefined object (for example : glutWireTeapot ()).
- Only then integrate with OpenMesh and display the mesh.
- You may want to review chapter 3 from the 'red book'.
- Think about transformations order - when adding the current transformation to the accumulated transformation - on which order it should be applied ?
Good Luck And Have Fun!!!