CSE 694A: Lab 1
Due Oct. 1
LAB 1: Implement a rotating cube that's rotating around a central axis
PRELIMINARY NOTES
- The emphasis in this class is on motion control algorithms. Attention to display quality and user interface will be minimal.
- This first lab will be graded leniently because I'm only using it to make sure everybody in class is up to speed on OpenGL.
- Organize your software according to the notes below. The objective is to develop a Control program that can be reused in all the lab assignments. It will be responsible for:
- initializing the OpenGL environment
- managing user interaction
- calling a standard set of routines to control the simulation
- See below for more notes on the suggested softare structure.
- NOTE: this quarter I will be giving out the OpenGL commands in C that implement the control (main) program.
ASSIGNMENT
The basic task is to write a program to rotate a cube around one of its own axes as it rotates around the y-axis (in three dimensions).
The animation part of this lab is trivial. This lab is mainly intended to get everybody to organize a simulation system and associated support routines that they can use in future labs and to make sure everyone has the programming and OpenGL skills necessary for the class.
For the viewer (camera/observer/eye position) implement a polar coordinate view specification with initial parameters corresponding to the observer along the positive z-axis, 10 units from the origin looking at the origin.
Use polar coordinates of (a,b) where a is the rotation around the x-axis and b is the rotation around the y-axis.
Set up a couple of light sources at, for example, (0,10,-10) and (-10,-10,5).
Rotate a cube (+/- 0.5, +/- 0.5, +/- 0.5) around the y-axis displaced 5 units away from the axis.
Represent the y-axis by a cuboid (+/- 0.5, +/- 10.0, +/- 0.5)
SOFTWARE
For the labs in this class, there will 3 types of files:
-
Control:
- Once written, this procedure can be used in each of the labs to follow will either minimal or no change.
- 'main()' sets up interactive OpenGL view environment: camera, lights, calling the simulation routines below. Calls 'init()'
- includes interaction handling routines to handle:
- mouse (left): mouse up-down, right-left -> polar coordinats of camera
- mouse (middle): mouse up and down -> zoom-in and zoom-out
- buttons or key strokes:
- reset simulation parameters,
- reset view parameters: handled in the Control program,
- stop/start simulation: toggles between calling 'run()' and 'render()',
- step simulation: put in 'stop()' mode and call 'step()'.
-
Simulation - the lab-specific algorithm to be implemented. The actual algorithm will obviously change from lab to lab, but each will have the same interface to the main routine. The simulation routine should support the following functions callable by Main:
- init() - initializes the simulation (allocates memory, sets up data structures, initializes parameters)
- reset() - resets the simulation to start over (reinitializes parameters and data structure values)
- run() - advance the simulation and render. It may be the case for some simulations that not every call to this will update the world-space data.
- step() - (optional) advance the simulation until a new render is needed and then renders. This differs from run only when there are more one iteration per render; useful for debugging.
- render() - render the simulation system (without taking any steps)
-
Support - making these separate files is optional, but it will facilitate reuse in other labs
Classes of utility routines:
- Drawing geometry such as cubes and prisms. For this lab you only need 'draw_cube()', but later on 'draw_tetrahedron()' and others will be useful.
- Setting material properties (e.g., set_material("bluePlastic")')
- Performing vector, matrix and quaternion operations - For this lab, you don't need any other than what's provided by OpenGL. In any case, you don't have to write your own if you have access to some other matrix/vector library (although it's not that hard to do and it's not a bad exercise to do).
OpenGL Commands
These are the OpenGL commands that I used. I make no claims about these being the only commands to use or the best commands to use or even that you need to use all of them. They are simply the ones I used.
- Used in the Control routine
- initialize window
- glutInitDisplayMode()
- glutInitWindowPosition()
- glutInitWindowSize()
- glutCreateWindow()
- setup callbacks
- glutDisplayFunc()
- glutReshapeFunc()
- glutIdleFunc()
- glutKeyboardFunc()
- glutSpecialFunc()
- glutMouseFunc()
- glutMotionFunc()
- glutMainLoop()
- initialize display
- glShadeModel()
- glFrontFace()
- glEnable()
- glPolygonMode()
- light setup
- view/camera/eye
- glMatrixMode()
- glLoadIdentity()
- glFrustum()
- gluLookAt()
- display routines
- glClear()
- glFlush()
- glutSwapBuffers()
- Used in the Simulation routine
- render
- glPushMatrix()
- glRotatef()
- glTranslatef()
- glScalef()
- glPopMatrix()
- Used in the Support routine
- Polygon drawing
- glBeginPolygon()
- glVertex3fv()
- glEnd()