| 1 #include "face.h" |
|
| 2 #include "sharky.h" |
|
| 3 #include <GL/gl.h> |
|
| 4 #include <GL/glu.h> |
|
| 5 #include "models.h" |
|
| 6 |
|
| 7 #define NUM_SHARKS 12 |
|
| 8 #define NUM_SHARK_LIDS 10 |
|
| 9 #define NUM_FINS 4 |
|
| 10 #define NUM_SHARK_EYES 1 |
|
| 11 #define NUM_SHARK_PUPILS 1 |
|
| 12 #define NUM_SHARK_IRIS 1 |
|
| 13 #define SHARK_SCALE .025 |
|
| 14 #define SHARK_EYES_Y 7.5*SHARK_SCALE // .295 |
|
| 15 #define SHARK_EYES_X 28.89*SHARK_SCALE // .26 |
|
| 16 #define SHARK_EYES_Z 56*SHARK_SCALE // .38 |
|
| 17 #define SHARK_FINS_X 75*SHARK_SCALE //.65 |
|
| 18 #define SHARK_FINS_Y -44*SHARK_SCALE//.18 |
|
| 19 #define SHARK_FINS_Z -15*SHARK_SCALE //.05 |
|
| 20 #define SHARK_IRIS_X 0*SHARK_SCALE |
|
| 21 #define SHARK_IRIS_Y 1.67*SHARK_SCALE//.015 |
|
| 22 #define SHARK_IRIS_Z 5.0*SHARK_SCALE//.08 |
|
| 23 #define SHARK_PUP_X 0*SHARK_SCALE |
|
| 24 #define SHARK_PUP_Y 0*SHARK_SCALE |
|
| 25 #define SHARK_PUP_Z 2.5*SHARK_SCALE //.028 |
|
| 26 #define SHARK_IRIS_SCALE .10*SHARK_SCALE |
|
| 27 #define SHARK_PUP_SCALE .08*SHARK_SCALE |
|
| 28 #define SHARK_FIN_SCALE .9*SHARK_SCALE |
|
| 29 #define SHARK_EYE_SCALE .7*SHARK_SCALE |
|
| 30 #define SHARK_LID_SCALE .84*SHARK_SCALE |
|
| 31 #define SHARK_HEAD_SCALE .58*SHARK_SCALE |
|
| 32 #define TOP_FIN_X 0*SHARK_SCALE |
|
| 33 #define TOP_FIN_Y 4*SHARK_SCALE |
|
| 34 #define TOP_FIN_Z 25*SHARK_SCALE |
|
| 35 #define BOT_FIN_X 0*SHARK_SCALE |
|
| 36 #define BOT_FIN_Y 9*SHARK_SCALE |
|
| 37 #define BOT_FIN_Z -70*SHARK_SCALE |
|
| 38 #define TOP_FIN_SCALE 2*SHARK_SCALE |
|
| 39 #define MAX_FIN_ANGLE 90.0 |
|
| 40 #define MIN_FIN_ANGLE -20.0 |
|
| 41 #define ANGLE_INC 60 |
|
| 42 float fins=0; |
|
| 43 |
|
| 44 |
|
| 45 char shark_mtl_file[MAX_FILE_LEN] = "dog.mtl"; |
|
| 46 // the initial dog materials |
|
| 47 GLint init_shark_mats[NUM_PARTS] = {1, 2, 3, 4, 5, 3, 5, 0, 0, 0}; |
|
| 48 |
|
| 49 void draw_shark_pupil(FACE f, PART p) { |
|
| 50 struct shark_struct* shark=(struct shark_struct*)f->char_struct; |
|
| 51 glPushMatrix(); |
|
| 52 glTranslatef(SHARK_IRIS_X, -SHARK_IRIS_Z, SHARK_IRIS_Y); |
|
| 53 if(p==LEFT_IRIS) |
|
| 54 glmSetMat(f->materials, f->mat_indeces[LEFT_IRIS]); |
|
| 55 else |
|
| 56 glmSetMat(f->materials, f->mat_indeces[RIGHT_IRIS]); |
|
| 57 glCallList(shark->iris[0]); |
|
| 58 glTranslatef(SHARK_PUP_X, -SHARK_PUP_Z, SHARK_PUP_Y); |
|
| 59 glmSetMat(f->materials, f->mat_indeces[PUPIL]); |
|
| 60 glCallList(shark->pupil[0]); |
|
| 61 glPopMatrix(); |
|
| 62 } |
|
| 63 |
|
| 64 void draw_shark_left_eye(FACE f, BOOL open, int max) { |
|
| 65 struct shark_struct* shark=(struct shark_struct*)f->char_struct; |
|
| 66 if(f->my_mode==CRAZY2) |
|
| 67 shark->curr_left_lid=NUM_SHARK_LIDS-1; |
|
| 68 else |
|
| 69 shark->curr_left_lid = compute_lid(open, shark->curr_left_lid, max); |
|
| 70 glPushMatrix(); |
|
| 71 glTranslatef(-SHARK_EYES_X, 0.0, 0.0); |
|
| 72 glPushMatrix(); |
|
| 73 glTranslatef(0.0, -f->curr_eye_pop, 0.0); |
|
| 74 draw_shark_pupil(f, LEFT_IRIS); |
|
| 75 glmSetMat(f->materials, f->mat_indeces[EYES]); |
|
| 76 glCallList(shark->eyes[shark->curr_left_eye]); |
|
| 77 glPopMatrix(); |
|
| 78 glmSetMat(f->materials, f->mat_indeces[LIDS]); |
|
| 79 glCallList(shark->lids[shark->curr_left_lid]); |
|
| 80 glPopMatrix(); |
|
| 81 } |
|
| 82 |
|
| 83 void draw_shark_right_eye(FACE f, BOOL open, int max) { |
|
| 84 struct shark_struct* shark=(struct shark_struct*)f->char_struct; |
|
| 85 if(f->my_mode==CRAZY2) |
|
| 86 shark->curr_right_lid=NUM_SHARK_LIDS-1; |
|
| 87 else |
|
| 88 shark->curr_right_lid = compute_lid(open, shark->curr_right_lid, max); |
|
| 89 glPushMatrix(); |
|
| 90 glTranslatef(SHARK_EYES_X, 0.0, 0.0); |
|
| 91 glPushMatrix(); |
|
| 92 glTranslatef(0.0, -f->curr_eye_pop, 0.0); |
|
| 93 draw_shark_pupil(f, RIGHT_IRIS); |
|
| 94 glmSetMat(f->materials, f->mat_indeces[EYES]); |
|
| 95 glCallList(shark->eyes[shark->curr_right_eye]); |
|
| 96 glPopMatrix(); |
|
| 97 glmSetMat(f->materials, f->mat_indeces[LIDS]); |
|
| 98 glCallList(shark->lids[shark->curr_right_lid]); |
|
| 99 glPopMatrix(); |
|
| 100 } |
|
| 101 |
|
| 102 void shark_eyes(FACE f, GLfloat angle, GLfloat yangle, BOOL left_open, BOOL right_open, DIRECTION dir) |
|
| 103 { |
|
| 104 struct shark_struct* shark=(struct shark_struct*)f->char_struct; |
|
| 105 int max_eye; |
|
| 106 if(dir==CONST) { //then not moving, eyes are gettin sleepy |
|
| 107 f->eye_count--; |
|
| 108 } |
|
| 109 else{ |
|
| 110 f->eye_count=EYE_TIME*NUM_SHARK_LIDS-1; |
|
| 111 } |
|
| 112 max_eye=f->eye_count/EYE_TIME; |
|
| 113 if(max_eye<0) |
|
| 114 max_eye=0; |
|
| 115 if(f->my_mode==CRAZY2) |
|
| 116 f->curr_eye_pop=f->curr_eye_pop + (MAX_EYE_POP - f->curr_eye_pop)/2; |
|
| 117 else |
|
| 118 f->curr_eye_pop=f->curr_eye_pop - (f->curr_eye_pop-0)/2; |
|
| 119 glPushMatrix(); |
|
| 120 glTranslatef(0, 0, SHARK_EYES_Y); |
|
| 121 glTranslatef(0, -SHARK_EYES_Z,0); |
|
| 122 draw_shark_left_eye(f, left_open, max_eye); |
|
| 123 draw_shark_right_eye(f, right_open, max_eye); |
|
| 124 glPopMatrix(); |
|
| 125 } |
|
| 126 |
|
| 127 void shark_fins(FACE f, DIRECTION dir){ |
|
| 128 struct shark_struct* shark=(struct shark_struct*)f->char_struct; |
|
| 129 |
|
| 130 if(dir==DOWN){ |
|
| 131 if(shark->curr_fin < (NUM_FINS-1)) |
|
| 132 shark->curr_fin++; |
|
| 133 shark->curr_fin_angle = shark->curr_fin_angle+(MAX_FIN_ANGLE-shark->curr_fin_angle)/2; |
|
| 134 } |
|
| 135 if(dir==UP){ |
|
| 136 if(shark->curr_fin > 0) |
|
| 137 shark->curr_fin--; |
|
| 138 shark->curr_fin_angle = shark->curr_fin_angle+(MIN_FIN_ANGLE-shark->curr_fin_angle)/2; |
|
| 139 } |
|
| 140 else if(dir==CONST){ |
|
| 141 shark->curr_fin=1; |
|
| 142 shark->curr_fin_angle = shark->curr_fin_angle+(0-shark->curr_fin_angle)/3; |
|
| 143 } |
|
| 144 |
|
| 145 glPushMatrix(); |
|
| 146 glTranslatef(-SHARK_FINS_X, -SHARK_FINS_Z, SHARK_FINS_Y); |
|
| 147 if(f->my_mode==CRAZY1) |
|
| 148 glRotatef(MAX_FIN_ANGLE, 0.0, 1.0, 0.0); |
|
| 149 else |
|
| 150 glRotatef(shark->curr_fin_angle, 0.0, 1.0, 0.0); |
|
| 151 glmSetMat(f->materials, f->mat_indeces[APPENDAGE]); |
|
| 152 glCallList(shark->fins[shark->curr_fin]); |
|
| 153 glPopMatrix(); |
|
| 154 glPushMatrix(); |
|
| 155 glTranslatef(SHARK_FINS_X, -SHARK_FINS_Z, SHARK_FINS_Y); |
|
| 156 glScalef(-1, 1, 1); |
|
| 157 if(f->my_mode==CRAZY1) |
|
| 158 glRotatef(MIN_FIN_ANGLE, 0.0, 1.0, 0.0); |
|
| 159 else |
|
| 160 glRotatef(shark->curr_fin_angle, 0.0, 1.0, 0.0); |
|
| 161 glCallList(shark->fins[shark->curr_fin]); |
|
| 162 glPopMatrix(); |
|
| 163 } |
|
| 164 |
|
| 165 void draw_back_fins(FACE f){ |
|
| 166 struct shark_struct* shark=(struct shark_struct*)f->char_struct; |
|
| 167 glPushMatrix(); |
|
| 168 glTranslatef(0, fins, TOP_FIN_Y); |
|
| 169 glRotatef(180, 0.0, 1.0, 0.0); |
|
| 170 glScalef(.5*TOP_FIN_SCALE,TOP_FIN_SCALE,TOP_FIN_SCALE); |
|
| 171 glmSetMat(f->materials, f->mat_indeces[APPENDAGE]); |
|
| 172 glCallList(shark->fins[2]); |
|
| 173 glPopMatrix(); |
|
| 174 |
|
| 175 } |
|
| 176 |
|
| 177 void draw_shark(FACE f, GLfloat angle, GLfloat yangle, BOOL left_open, BOOL right_open, GLfloat open, DIRECTION dir, OUTPUT_MODE mode){ |
|
| 178 int next_face; |
|
| 179 struct shark_struct* shark; |
|
| 180 |
|
| 181 f->crazy_count--; |
|
| 182 if(f->crazy_count==0){ |
|
| 183 f->my_mode = mode; |
|
| 184 if(mode!=NORMAL) |
|
| 185 f->crazy_count = CRAZY_COUNT; |
|
| 186 else |
|
| 187 f->crazy_count = 1; |
|
| 188 } |
|
| 189 apply_output_mode(f, &angle, &yangle, &left_open, &right_open, &open, &dir); |
|
| 190 next_face = NUM_SHARKS - open*NUM_SHARKS - 1; |
|
| 191 shark = (struct shark_struct*)f->char_struct; |
|
| 192 if(next_face > shark->curr_face) |
|
| 193 shark->curr_face++; |
|
| 194 else if(next_face < shark->curr_face) |
|
| 195 shark->curr_face--; |
|
| 196 |
|
| 197 glPushMatrix(); |
|
| 198 glRotatef(-90, 1.0, 0.0, 0.0); |
|
| 199 glRotatef(-yangle, 0.0, 0.0, -1.0); |
|
| 200 glRotatef(-angle, 0, 1, 0); |
|
| 201 shark_eyes(f, angle, yangle, left_open, right_open, dir); |
|
| 202 shark_fins(f, dir); |
|
| 203 //draw_back_fins(f); |
|
| 204 glmSetMat(f->materials, f->mat_indeces[HEAD]); |
|
| 205 glCallList(shark->faces[shark->curr_face]); |
|
| 206 glPopMatrix(); |
|
| 207 } |
|
| 208 |
|
| 209 |
|
| 210 void init_shark(FACE f){ |
|
| 211 int i; |
|
| 212 struct shark_struct* shark; |
|
| 213 f->char_struct = (struct shark_struct*)malloc(sizeof(struct shark_struct)); |
|
| 214 f->materials = glmMTL(shark_mtl_file); |
|
| 215 f->mat_indeces=(GLint*)malloc(sizeof(GLint)*NUM_PARTS); |
|
| 216 //initialize all of the parts to some colors |
|
| 217 change_materials(f, init_shark_mats, NUM_PARTS); |
|
| 218 f->my_mode = NORMAL; |
|
| 219 f->eye_count = EYE_TIME*NUM_SHARK_LIDS-1; |
|
| 220 f->crazy_count = 1; |
|
| 221 f->curr_z_angle = 0; |
|
| 222 f->curr_eye_pop = 0; |
|
| 223 f->name = strdup("sharky"); |
|
| 224 f->draw_func = draw_shark; |
|
| 225 shark = (struct shark_struct*)f->char_struct; |
|
| 226 |
|
| 227 printf("\nReading models: "); |
|
| 228 fflush(0); |
|
| 229 |
|
| 230 //initialize the draw lists |
|
| 231 init_lists(&shark->faces, &shark->m_faces, NUM_SHARKS, f->name, SHARK_HEAD_SCALE); |
|
| 232 init_lists(&shark->lids, &shark->m_lids, NUM_SHARK_LIDS, "sharkylid", SHARK_LID_SCALE); |
|
| 233 init_lists(&shark->fins, &shark->m_fins, NUM_FINS, "sharkyfin", SHARK_FIN_SCALE); |
|
| 234 init_lists(&shark->eyes, &shark->m_eyes, NUM_SHARK_EYES, "sharkyeye", SHARK_EYE_SCALE); |
|
| 235 init_lists(&shark->pupil, &shark->m_pupil, NUM_SHARK_PUPILS, "sharkypupil", SHARK_PUP_SCALE); |
|
| 236 init_lists(&shark->iris, &shark->m_iris, NUM_SHARK_IRIS, "sharkyiris", SHARK_IRIS_SCALE); |
|
| 237 |
|
| 238 printf("\n"); |
|
| 239 fflush(0); |
|
| 240 |
|
| 241 shark->curr_face = 0; |
|
| 242 shark->curr_fin = 1; |
|
| 243 shark->curr_left_lid = 0; |
|
| 244 shark->curr_right_lid = 0; |
|
| 245 shark->curr_left_eye = 0; |
|
| 246 shark->curr_right_eye = 0; |
|
| 247 shark->curr_pupil = 0; |
|
| 248 shark->curr_fin_angle = 0; |
|
| 249 } |
|