CS475 Assignment: SmallE, Part 1

\$ make
\$ ./simple

Hierarchical Model:

(Nodes in all CAPITALS represent primitives: explained later)

```Smalle:
----Torso
|----CUBOID
|----Arm1
|    |----CYLINDER
|    |----Wrist
|         |----SPHERE
|         |----Finger
|              |----CUBOID (lower finger)
|              |----CUBOID (upper finger)
|
|----Arm2
|    |----CYLINDER
|    |----Wrist
|         |----SPHERE
|         |----Finger
|              |----CUBOID (lower finger)
|              |----CUBOID (upper finger)
|
|----Wheel1
|    |----CYLINDER (disk)
|
|----Wheel2
|    |----CYLINDER (disk)
|
|----CYLINDER (lower neck)
|----CYLINDER (upper neck)
|----CUBOID (nose)
|----Eye1
|    |----Cornea
|    |    |----POLYGON
|    |
|    |----Iris
|         |----CYLINDER
|
|----Eye2
|    |----Cornea
|    |    |----POLYGON
|    |
|    |----Iris
|         |----CYLINDER
```

Keyboard Mapping

(use capitals (shift+key) to rotate in opposite direction)

• z: rotate smalle about z axis
• x: rotate smalle about x axis
• c: rotate smalle about y axis
• q,w,e: lower neck x,y,z rotations
• a,s,d: upper neck x,y,z rotations
• t,y: rotate right arm
• u,i: rotate left arm
• f,g,h: rotate right wrist
• j,k,l: rotate left wrist
• v,b: rotate upper fingers of right wrist
• n,m: rotate upper fingers of left wrist
• o: rotate right wheel
• p: rotate left wheel
• 1,2,3: rotate head about x,y,z axis (use shift+number for opposite direction)
• UP_ARROW_KEY: translate smalle forward
• DOWN_ARROW_KEY: translate smalle backward
• LEFT_ARROW_KEY: rotate smalle left about vertical axis
• RIGHT_ARROW_KEY: rotate smalle right about vertical axis
• r: reset all degrees of freedom to default orientation

Implementation Details

1. simple.cpp contains the main program, and all the OpenGL callbacks. It also contains two global variables:
1. SmallE smalle, which encapsulates all the commands for drawing the bot, and
2. DisplayLists dl, which encapsulates OpenGL display lists for drawing primitives.
2. smalle.h and smalle.cpp
• This file contains definition of class SmallE, and also other classes corresponding to parts of SmallE.
• A class corresponding to a body part will contain as members objects of primitive types (see below) as well as objects of other body parts, depending upon the hierarchical model.
• For example, SmallE contains a Cuboid primitive object, two Arm objects, two Wheels, and one Head. In turn, an Arm object contains one Cylinder and one Wrist, etc.
• Each class has extra data members for each rotational degree of freedom of that body part.
• Also, there is a draw() function for each class which draws all the nodes in the subtree rooted at that body part, in the hierarchical model.
3. config.h
• This file contains constants which define the structural parameters of the SmallE robot. The smalle.h implementation uses only these constants for the purpose of drawing the robot.
• This ensures that any changes to the dimensions of SmallE can be made by modifying only this file.
4. primitives.h and primitives.cpp
• This file defines certain geometric primitive objects which are used by the smalle body parts for drawing purposes.
• These include: Circle, Cylinder, Cuboid, Sphere, Polygon.
• The smalle.h implementation uses these primitives for drawing various body parts. This ensures that there is zero code duplication for drawing same kind of shapes.
• This file also defines the class DisplayLists, which provides an interface for accessing precompiled OpenGL display lists for drawing certain primitives. The DisplayLists object is used by the primitive classes to speedup the rendering of commonly used shapes.
• The primitives.h file is independant of the config.h file, and it provides a logically abstract interface for drawing the various geometric primitives in any context. So essentially, the smalle.h classes take the parameters from config.h file and geometric primitives from primitives.h classes, to draw the robot, of required shape, structure and dimensions.