| 1 #include "face.h" |
|
| 2 #include "doggy.h" |
|
| 3 #include <GL/gl.h> |
|
| 4 #include <GL/glu.h> |
|
| 5 #include "models.h" |
|
| 6 |
|
| 7 #define NUM_DOGS 11 |
|
| 8 #define NUM_DOG_LIDS 10 |
|
| 9 #define NUM_EARS 3 |
|
| 10 #define NUM_EYES 1 |
|
| 11 #define NUM_PUPILS 1 |
|
| 12 #define NUM_IRIS 1 |
|
| 13 #define SCALE .020 |
|
| 14 #define EYES_Y 32.78*SCALE // .295 |
|
| 15 #define EYES_X 28.89*SCALE // .26 |
|
| 16 #define EYES_Z 42.22*SCALE // .38 |
|
| 17 #define EARS_X 60*SCALE //.65 |
|
| 18 #define EARS_Y 20*SCALE//.18 |
|
| 19 #define EARS_Z -5.56*SCALE //.05 |
|
| 20 #define IRIS_X 0*SCALE |
|
| 21 #define IRIS_Y 1.67*SCALE//.015 |
|
| 22 #define IRIS_Z 7*SCALE//.08 |
|
| 23 #define PUP_X 0*SCALE |
|
| 24 #define PUP_Y 0*SCALE |
|
| 25 #define PUP_Z 1.2*SCALE //.028 |
|
| 26 #define IRIS_SCALE .12*SCALE |
|
| 27 #define PUP_SCALE .11*SCALE |
|
| 28 #define EAR_SCALE .7*SCALE |
|
| 29 #define EYE_SCALE .7*SCALE |
|
| 30 #define LID_SCALE .77*SCALE |
|
| 31 #define DOG_SCALE .58*SCALE |
|
| 32 #define MAX_FILE_LEN 64 |
|
| 33 #define MAX_EAR_ANGLE 90.0 |
|
| 34 #define MIN_EAR_ANGLE -20.0 |
|
| 35 |
|
| 36 |
|
| 37 char dog_mtl_file[MAX_FILE_LEN] = "dog.mtl"; |
|
| 38 // the initial dog materials |
|
| 39 GLint init_dog_mats[NUM_PARTS] = {1, 2, 2, 4, 0, 3, 5, 0, 0, 0}; |
|
| 40 |
|
| 41 void draw_pupil(FACE f, PART p) { |
|
| 42 struct doggy_struct* dog=(struct doggy_struct*)f->char_struct; |
|
| 43 glPushMatrix(); |
|
| 44 glTranslatef(IRIS_X, -IRIS_Z, IRIS_Y); |
|
| 45 if(p==LEFT_IRIS) |
|
| 46 glmSetMat(f->materials, f->mat_indeces[LEFT_IRIS]); |
|
| 47 else |
|
| 48 glmSetMat(f->materials, f->mat_indeces[RIGHT_IRIS]); |
|
| 49 glCallList(dog->iris[0]); |
|
| 50 glTranslatef(PUP_X, -PUP_Z, PUP_Y); |
|
| 51 glmSetMat(f->materials, f->mat_indeces[PUPIL]); |
|
| 52 glCallList(dog->pupil[0]); |
|
| 53 glPopMatrix(); |
|
| 54 } |
|
| 55 |
|
| 56 void draw_left_eye(FACE f, BOOL open, int max) { |
|
| 57 struct doggy_struct* dog=(struct doggy_struct*)f->char_struct; |
|
| 58 if(f->my_mode==CRAZY2) |
|
| 59 dog->curr_left_lid=NUM_DOG_LIDS-1; |
|
| 60 else |
|
| 61 dog->curr_left_lid = compute_lid(open, dog->curr_left_lid, max); |
|
| 62 glPushMatrix(); |
|
| 63 glTranslatef(-EYES_X, 0.0, 0.0); |
|
| 64 glPushMatrix(); |
|
| 65 glTranslatef(0.0, -f->curr_eye_pop, 0.0); |
|
| 66 draw_pupil(f, LEFT_IRIS); |
|
| 67 glmSetMat(f->materials, f->mat_indeces[EYES]); |
|
| 68 glCallList(dog->eyes[dog->curr_left_eye]); |
|
| 69 glPopMatrix(); |
|
| 70 glmSetMat(f->materials, f->mat_indeces[LIDS]); |
|
| 71 glCallList(dog->lids[dog->curr_left_lid]); |
|
| 72 glPopMatrix(); |
|
| 73 } |
|
| 74 |
|
| 75 void draw_right_eye(FACE f, BOOL open, int max) { |
|
| 76 struct doggy_struct* dog=(struct doggy_struct*)f->char_struct; |
|
| 77 if(f->my_mode==CRAZY2) |
|
| 78 dog->curr_right_lid=NUM_DOG_LIDS-1; |
|
| 79 else |
|
| 80 dog->curr_right_lid = compute_lid(open, dog->curr_right_lid, max); |
|
| 81 glPushMatrix(); |
|
| 82 glTranslatef(EYES_X, 0.0, 0.0); |
|
| 83 glScalef(-1, 1, 1); |
|
| 84 glPushMatrix(); |
|
| 85 glTranslatef(0.0, -f->curr_eye_pop, 0.0); |
|
| 86 draw_pupil(f, RIGHT_IRIS); |
|
| 87 glmSetMat(f->materials, f->mat_indeces[EYES]); |
|
| 88 glCallList(dog->eyes[dog->curr_right_eye]); |
|
| 89 glPopMatrix(); |
|
| 90 glmSetMat(f->materials, f->mat_indeces[LIDS]); |
|
| 91 glCallList(dog->lids[dog->curr_right_lid]); |
|
| 92 glPopMatrix(); |
|
| 93 } |
|
| 94 |
|
| 95 void dog_eyes(FACE f, GLfloat angle, GLfloat yangle, BOOL left_open, BOOL right_open, DIRECTION dir) |
|
| 96 { |
|
| 97 struct doggy_struct* dog=(struct doggy_struct*)f->char_struct; |
|
| 98 int max_eye; |
|
| 99 if(dir==CONST) { //then not moving, eyes are gettin sleepy |
|
| 100 f->eye_count--; |
|
| 101 } |
|
| 102 else{ |
|
| 103 f->eye_count=EYE_TIME*NUM_DOG_LIDS-1; |
|
| 104 } |
|
| 105 max_eye=f->eye_count/EYE_TIME; |
|
| 106 if(max_eye<0) |
|
| 107 max_eye=0; |
|
| 108 if(f->my_mode==CRAZY2) |
|
| 109 f->curr_eye_pop=f->curr_eye_pop + (MAX_EYE_POP - f->curr_eye_pop)/2; |
|
| 110 else |
|
| 111 f->curr_eye_pop=f->curr_eye_pop - (f->curr_eye_pop-0)/2; |
|
| 112 glPushMatrix(); |
|
| 113 glTranslatef(0, 0, EYES_Y); |
|
| 114 glTranslatef(0, -EYES_Z,0); |
|
| 115 draw_left_eye(f, left_open, max_eye); |
|
| 116 draw_right_eye(f, right_open, max_eye); |
|
| 117 glPopMatrix(); |
|
| 118 } |
|
| 119 |
|
| 120 void dog_ears(FACE f, DIRECTION dir){ |
|
| 121 struct doggy_struct* dog=(struct doggy_struct*)f->char_struct; |
|
| 122 //printf("ears %f\n", ears); |
|
| 123 if(dir==DOWN){ |
|
| 124 if(dog->curr_ear < (NUM_EARS-1)) |
|
| 125 dog->curr_ear++; |
|
| 126 dog->curr_ear_angle = dog->curr_ear_angle+(MAX_EAR_ANGLE-dog->curr_ear_angle)/2; |
|
| 127 } |
|
| 128 if(dir==UP){ |
|
| 129 if(dog->curr_ear > 0) |
|
| 130 dog->curr_ear--; |
|
| 131 dog->curr_ear_angle = dog->curr_ear_angle+(MIN_EAR_ANGLE-dog->curr_ear_angle)/2; |
|
| 132 } |
|
| 133 else if(dir==CONST){ |
|
| 134 dog->curr_ear=1; |
|
| 135 dog->curr_ear_angle = dog->curr_ear_angle+(0-dog->curr_ear_angle)/3; |
|
| 136 } |
|
| 137 |
|
| 138 glPushMatrix(); |
|
| 139 glTranslatef(-EARS_X, -EARS_Z, EARS_Y); |
|
| 140 if(f->my_mode==CRAZY1) |
|
| 141 glRotatef(MAX_EAR_ANGLE, 0.0, 1.0, 0.0); |
|
| 142 else |
|
| 143 glRotatef(dog->curr_ear_angle, 0.0, 1.0, 0.0); |
|
| 144 glmSetMat(f->materials, f->mat_indeces[APPENDAGE]); |
|
| 145 glCallList(dog->ears[dog->curr_ear]); |
|
| 146 glPopMatrix(); |
|
| 147 glPushMatrix(); |
|
| 148 glTranslatef(EARS_X, -EARS_Z, EARS_Y); |
|
| 149 glScalef(-1, 1, 1); |
|
| 150 if(f->my_mode==CRAZY1) |
|
| 151 glRotatef(MIN_EAR_ANGLE, 0.0, 1.0, 0.0); |
|
| 152 else |
|
| 153 glRotatef(dog->curr_ear_angle, 0.0, 1.0, 0.0); |
|
| 154 glCallList(dog->ears[dog->curr_ear]); |
|
| 155 glPopMatrix(); |
|
| 156 } |
|
| 157 |
|
| 158 void draw_dog(FACE f, GLfloat angle, GLfloat yangle, BOOL left_open, BOOL right_open, GLfloat open, DIRECTION dir, OUTPUT_MODE mode){ |
|
| 159 int next_face; |
|
| 160 struct doggy_struct* dog; |
|
| 161 f->crazy_count--; |
|
| 162 if(f->crazy_count==0){ |
|
| 163 f->my_mode = mode; |
|
| 164 if(mode!=NORMAL) |
|
| 165 f->crazy_count = CRAZY_COUNT; |
|
| 166 else |
|
| 167 f->crazy_count = 1; |
|
| 168 } |
|
| 169 apply_output_mode(f, &angle, &yangle, &left_open, &right_open, &open, &dir); |
|
| 170 next_face = NUM_DOGS - open*NUM_DOGS - 1; |
|
| 171 dog = (struct doggy_struct*)f->char_struct; |
|
| 172 if(next_face > dog->curr_face) |
|
| 173 dog->curr_face++; |
|
| 174 else if(next_face < dog->curr_face) |
|
| 175 dog->curr_face--; |
|
| 176 |
|
| 177 glPushMatrix(); |
|
| 178 glRotatef(-90, 1.0, 0.0, 0.0); |
|
| 179 glRotatef(-yangle, 0.0, 0.0, -1.0); |
|
| 180 glRotatef(-angle, 0, 1, 0); |
|
| 181 dog_eyes(f, angle, yangle, left_open, right_open, dir); |
|
| 182 dog_ears(f, dir); |
|
| 183 glmSetMat(f->materials, f->mat_indeces[HEAD]); |
|
| 184 glCallList(dog->faces[dog->curr_face]); |
|
| 185 glPopMatrix(); |
|
| 186 } |
|
| 187 |
|
| 188 void init_dog(FACE f){ |
|
| 189 int i; |
|
| 190 struct doggy_struct* dog; |
|
| 191 f->char_struct = (struct doggy_struct*)malloc(sizeof(struct doggy_struct)); |
|
| 192 f->materials = glmMTL(dog_mtl_file); |
|
| 193 f->mat_indeces=(GLint*)malloc(sizeof(GLint)*NUM_PARTS); |
|
| 194 //initialize all of the parts to some colors |
|
| 195 change_materials(f, init_dog_mats, NUM_PARTS); |
|
| 196 f->my_mode = NORMAL; |
|
| 197 f->eye_count = EYE_TIME*NUM_DOG_LIDS-1; |
|
| 198 f->crazy_count = 1; |
|
| 199 f->curr_z_angle = 0; |
|
| 200 f->curr_eye_pop = 0; |
|
| 201 f->name = strdup("dog"); |
|
| 202 f->draw_func = draw_dog; |
|
| 203 dog = (struct doggy_struct*)f->char_struct; |
|
| 204 |
|
| 205 printf("\nReading models: "); |
|
| 206 fflush(0); |
|
| 207 |
|
| 208 //initialize the draw lists |
|
| 209 init_lists(&dog->faces, &dog->m_faces, NUM_DOGS, f->name, DOG_SCALE); |
|
| 210 init_lists(&dog->lids, &dog->m_lids, NUM_DOG_LIDS, "lid", LID_SCALE); |
|
| 211 init_lists(&dog->ears, &dog->m_ears, NUM_EARS, "ear", EAR_SCALE); |
|
| 212 init_lists(&dog->eyes, &dog->m_eyes, NUM_EYES, "dogeye", EYE_SCALE); |
|
| 213 init_lists(&dog->pupil, &dog->m_pupil, NUM_PUPILS, "dogpupil", PUP_SCALE); |
|
| 214 init_lists(&dog->iris, &dog->m_iris, NUM_IRIS, "dogiris", IRIS_SCALE); |
|
| 215 |
|
| 216 printf("\n"); |
|
| 217 fflush(0); |
|
| 218 |
|
| 219 dog->curr_face = 0; |
|
| 220 dog->curr_ear = 1; |
|
| 221 dog->curr_left_lid = 9; |
|
| 222 dog->curr_right_lid = 0; |
|
| 223 dog->curr_left_eye = 0; |
|
| 224 dog->curr_right_eye = 0; |
|
| 225 dog->curr_pupil = 0; |
|
| 226 dog->curr_ear_angle = 0; |
|
| 227 } |
|