README CPSC 414 - PROJECT 1: ARTICULATED ELEPHANT Raymond Lee 74444993 Lab 1B ______________________________________________ ______________________________________________ 1. OVERVIEW 2. FEATURES 2.1 Modelling 2.2 Animation 2.3 Interaction 3. MECHANICS 3.1 Modelling 3.1.1 Troubleshooting 3.2 Animation 3.3 Interaction 3.3.1 Troubleshooting ______________________________________________ ______________________________________________ -------------------------------------------------------------------------------- ______________________________________________ 1. OVERVIEW This project creates an articulated elephant. There are 3 main parts: modelling, animation, and interaction - these are further described in the 2. FEATURES. The elephant first appears in a resting position on a 'side view' where the elephant head is on the right of the viewer/user. -------------------------------------------------------------------------------- ______________________________________________ 2. FEATURES The viewer/user is able to alter between 6 different views and has a quiting option: i) 'r' - resting position (this is the default view) ii) 's' - side view, where the elephant is upright (head on the left and tail on the right of user) iii) 'f' - front view, where user is looking at the upright elephant at the front (looking at face) iv) 'b' - rear view, where user is looking at the upright elephant at the back (looking at tail) v) 'a' - above view, where user is looking at elephant in default position (head on left) from bird's eye view (above elephant) vi) 'u' - under view, where user is looking at elephant in default position (head on left) from underneath (below elephant) vii) 'q' - to exit the program The features of the elephant can be split into 3 areas: modelling (how the elephant looks), animation (how the elephant moves), and interaction (how the user can interact w/the elephant program). ................................................................................ 2.1 Modelling Using the geometric shapes of a sphere and cube, a model of an elephant is created. The spheres and cubes will be modified to reflect the shape of different parts of an elephant. The parts included: the body, the tail, the neck, the head, the ears, 4 legs (which will have an upper leg, lower leg, and foot), and a trunk (which will be split into sections to allow for a curling animation). ................................................................................ 2.2 Animation The joints of the elephant will be animated. There is: i) a tail wag - moves up and down, wrt to the body ii) a neck and head (includes ears and trunk) nod - moves up and down wrt to body iii) leg raise - 2 stage rotation where upper leg rotates at the 'hip', and the lower leg rotates up under the upper leg iv) trunk roll - trunk curls (3 segment movement) Additional: v) ears wiggle - opens up so inner ear is seen from front view vi) a head (includes ears and trunk) shake - moves left and right wrt to body ................................................................................ 2.3 Interaction Key bindings allow user to animate elephant. i) 't' - tail wag ii) 'h' - neck and head nod iii) 'l' - front right, wrt to elephant, leg raise; 'n' - back right, wrt to elephant, leg raise 'm' - front left, wrt to elephant, leg raise; 'o' - back left, wrt to elephant, leg raise iv) 'k' - curls trunk towards elephant and back Additional: v) 'e' - ears wiggle vi) ',' - head shake left wrt to elephant; '.' - head shake right wrt to elephant vii) '0' (zero) - changes figure from solid fill to wire outline viii) '1' - changes color from grey to blue -------------------------------------------------------------------------------- ______________________________________________ 3. MECHANICS The original code that was given to use included the features to change views and to exit. The latter of the features - modelling, animation, and interaction - were the parts that I coded. ................................................................................ 3.1 Modelling The different parts of the elephant, which were modified spheres and cubes, was done using glutSolidSphere(...), glutWireSphere(...), glutSolidCube(...), and glutWireCube(...). I was not able to write my own draw functions which worked properly for this part of the code and so used the glut library. 3.1.1 Troubleshooting In particular, it was the drawSphere() function that I was unable to get to work. I read on some tutorials online of using stacks and slices but was still unsuccessful in making a sphere. The drawCube() function I was able to write with the assistance of the textbook (Appendix A.9 Page 652): Glfloat vertices[][3] = .... Void polygon( ... ){ glBegin(GL_POLYGON); ...} Void lineloop( ... ){ glBegin(GL_LINE_LOOP); ...} Void drawSolidCube(){ polygon( ... ); ...} Void drawWireCube(){ polygon( ...); ...} However, I did not use this in my working code as my original code used the glutSolidCube and glutWireCube and I realized that I did not have enough time (before the deadline) to modify all the scaling and rotaion to get my elephant to look correct. Thus, it is commented out in my code. ................................................................................ 3.2 Animation In this part of the code, I wrote a separate draw function for each part: i) drawBody(..) - drew the body of the elephant ii) drawTail(..) - drew the tail, along w/the hair at the end of the tail iii) 2 draw functions for each leg - one to draw the upper leg, ad the other to draw the lower leg ( which includes the foot) iv) drawNHarea(..) -which drew the neck, head, ears, and trunk of the elephant ................................................................................ 3.3 Interaction In this part of the code, I wrote a separate move function which allowed for movement. These move functions would be called by the switch statements in the KeyboardCallBack(..). Once called, the move function modifies flags which are set, designated for each area. For example, tail has 3 flags controlling it - an angle_flag, a x-direction_flag, and a y-direction_flag. Initially, these flags are all set to 0.0 (zero). Inside the drawTail(..) function, there are calls which uses these flags: glRotate( angle_flag, ...), and glTranslate( x-direction_flag, y-direction_flag, ..). Now, when a key is pushed, the KeyboardCallBack(..) function checks the cases in the switch statement to see which letter was pressed and which part of the elephant to modify. If it was the tail key that was pressed, the flags are modified by moveTail() and then when drawTail(..) is called, the altered flags will result in a new tail being drawn at the new location. This is to give the affect of movement/animation. Likewise, the other parts move in a similar way - some have less flags (ie. only an angle_flag), while others may need more flags (ie. a z-direction_flag). Along with the required interaction features, there are also additional interaction features - refer to 2.3 Interaction. 3.3.1 Troubleshooting For the interaction criteria, I was uable to get the the smooth animation to work properly. I ran into 2 problems - using glutIdleFunc(..) and glutPostRedisplay() correctly, and setting my loop correctly to allow for transition movement. I tried to use glutIdleFunc(..) and glutPostRedisplay() but was unsucessful. In particular, I think I used the functions in the wrong places. For example, glutIdleFunc( NULL) should be called when I want to stop changing the variables (ie. the flags). When I used these functions, and pressed the space bar, the response I got from the elephant was a stalled movement. For example, I would have to press the key 't' several times before it moved. As for my loop which calculated the changes to the variables( ie. the flags), I was able to calculate the movement for one direction correctly, but not for the other. For example, calculating the movement for the tail. I was able to make the tail move up and back down once. But when the tail key was pressed again to move the tail back up, it instead continued to move in the downward direction and every subsequent tail key pressings, the tail would simply do a counter-clockwise rotation. I then modified the contraints of the loop to try to fix the rotation error but was unable to get it to work properly. Parts of the code that I tried to use glutPostRedisplay() and glutIdleFunc(), along with the loops to try for smooth transition animation are commented out.