void init() { draw_head(); draw_eyes(); draw_smile(); draw_frown(); glNewList(SMILEY_FACE, GL_COMPILE); glCallList(HEAD); glCallList(EYES); glCallList(SMILE); glEndList(); glNewList(FROWNY_FACE, GL_COMPILE); glCallList(HEAD); glCallList(EYES); glCallList(FROWN); glEndList(); }
void object(void) { // allows fox to move across the screen glTranslatef(body_pos, 0.0, 0.0); // rotate body by body_rotate degrees glRotatef(body_rotate, 0.0, 0.0, 1.0); glPushMatrix(); // draw body and body parts of fox draw_torso(); glTranslatef(-40.0, 70.0, 0.0); // M_(torso to head) draw_head(); glTranslatef(-12.0, 34.0, 0.0); // M_(head to left ear) draw_ear(); glTranslatef(23.0, 0.0, 0.0); // M_(left ear to right ear) // rotate tail by tail_pos degrees glRotatef(tail_pos, 0, 0, 1); draw_ear(); glTranslatef(90.0, -60.0, 0.0); // M_(right ear to tail) draw_tail(); // using its own matrix allows the front leg to pivot independently of the back leg glPushMatrix(); glTranslatef(-110, -45, 0); // M_(tail to front leg) // rotate front leg by front_leg_pos degrees glRotatef(front_leg_pos, 0.0, 0.0, 1.0); draw_leg(); glPopMatrix(); glPushMatrix(); glTranslatef(-25, -45, 0); // M_(front leg to back leg) // rotate back leg by back_leg_pos degrees glRotatef(back_leg_pos, 0.0, 0.0, 1.0); draw_leg(); glPopMatrix(); glPopMatrix(); }
static void draw_squid (ModeInfo *mi, squid *sq) { int wire = MI_IS_WIREFRAME(mi); int i; glPushMatrix(); glRotatef (90, 1, 0, 0); if (opacity_arg < 1.0) draw_head (mi, sq, 0.75); for (i = 0; i < sq->ntentacles; i++) { tentacle *t = &sq->tentacles[i]; int j; glColor4fv (t->color); glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, t->color); if (wire) { glBegin (GL_LINE_STRIP); for (j = 0; j < t->length; j++) glVertex3f (t->nodes[j].pos.x, t->nodes[j].pos.y, t->nodes[j].pos.z); glEnd(); mi->polygon_count += t->length; } else { GLfloat radius = t->radius * thickness_arg; GLfloat rstep = radius / t->length; int faces = 8; glFrontFace (GL_CCW); for (j = 0; j < t->length-1; j++) { int k; node *n1 = &t->nodes[j]; node *n2 = &t->nodes[j+1]; GLfloat X = (n1->pos.x - n2->pos.x); GLfloat Y = (n1->pos.y - n2->pos.y); GLfloat Z = (n1->pos.z - n2->pos.z); GLfloat L = sqrt (X*X + Y*Y + Z*Z); GLfloat r2 = radius - rstep; glPushMatrix(); glTranslatef (n1->pos.x, n1->pos.y, n1->pos.z); glRotatef (-atan2 (X, Y) * (180 / M_PI), 0, 0, 1); glRotatef ( atan2 (Z, sqrt(X*X + Y*Y)) * (180 / M_PI), 1, 0, 0); glBegin (wire ? GL_LINE_LOOP : GL_QUAD_STRIP); for (k = 0; k <= faces; k++) { GLfloat th = k * M_PI * 2 / faces; GLfloat c = cos(th); GLfloat s = sin(th); GLfloat x1 = radius * c; GLfloat y1 = radius * s; GLfloat z1 = 0; GLfloat x2 = r2 * c; GLfloat y2 = r2 * s; GLfloat z2 = L; glNormal3f (x1, z1, y1); glVertex3f (x1, z1, y1); glVertex3f (x2, z2, y2); mi->polygon_count++; } glEnd(); glPopMatrix(); radius = r2; } } } draw_head (mi, sq, 1.0); glPopMatrix(); }
void GreenInvader::draw(float x, float y, int debug){ _x = x; _y = y; GreenInvader inv; glPushMatrix(); glTranslated(x, y, 0.0f); glPushMatrix(); GLfloat material[] = {0.5,1.0,0,1}; GLfloat specular[] = {0,0,0,0}; GLfloat emission[] = {0,0,0,0}; GLfloat shininess[] = {0}; glMaterialfv(GL_FRONT, GL_AMBIENT, material); glMaterialfv(GL_FRONT, GL_DIFFUSE, material); glMaterialfv(GL_FRONT, GL_SPECULAR, specular); glMaterialfv(GL_FRONT, GL_EMISSION, emission); glMaterialfv(GL_FRONT, GL_SHININESS, shininess); glColor3f(0.5f, 1.0f, 0.0f); glPushMatrix(); if (debug) glutWireSphere(_radius, 13, 5); glPopMatrix(); glPushMatrix(); draw_legs(); // pernas glPopMatrix(); glPushMatrix(); glScalef(2, 1, 2); glTranslated(0,-2,0); glutSolidCube(1); glPopMatrix(); glPushMatrix(); glScalef(6, 1, 2); glTranslated(0,-1,0); //base do corpo glutSolidCube(1); glPopMatrix(); glPushMatrix(); draw_body(); //corpo glPopMatrix(); glPushMatrix(); draw_head(); //cabeca glPopMatrix(); GLfloat eye_ambient[] = {0,0,0,1}; GLfloat eye_diffuse[] = {0,0,0,1}; GLfloat eye_specular[] = {0,0,0,0}; GLfloat eye_emission[] = {0,0,0,0}; GLfloat eye_shininess[] = {0}; glMaterialfv(GL_FRONT, GL_AMBIENT, eye_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, eye_ambient); glMaterialfv(GL_FRONT, GL_SPECULAR, eye_specular); glMaterialfv(GL_FRONT, GL_EMISSION, eye_emission); glMaterialfv(GL_FRONT, GL_SHININESS, eye_shininess); glColor3f(0.0f, 0.0f, 0.0f); //preto glPushMatrix(); draw_eyes(); //olhos glPopMatrix(); glPopMatrix(); glPopMatrix(); }
void draw_object(){ glPushMatrix(); glPushMatrix(); glTranslatef(0,bally,ballz); //which is used for ball animation glTranslatef(0,5,50); draw_ball(); glPopMatrix (); glTranslatef(posx,0.0,posz); //robot's animation glTranslatef(0,19.0,0); draw_body(); //draw a man's body draw_body2(); glPushMatrix(); glPushMatrix(); glPushMatrix(); glPushMatrix(); glTranslatef(0.0,17.0,0.0); glRotatef(-90,1.0,0.0,0.0); draw_head(); //draw a man's head glPopMatrix(); glTranslatef(-8.0,12.0,0.0); glRotatef(theta_arm_left,1.0,0.0,0.0); //the left arm will rotate during the animation draw_arm(); //draw the left arm glTranslatef(0.0,-12.0,0.0); draw_palm(); //draw the left palm glPopMatrix(); glTranslatef(8.0,12.0,0.0); glRotatef(theta_arm_right,1.0,0.0,0.0);//the right arm will rotate in the opposite direction with the left arm glScalef(-1.0,1.0,1.0); draw_arm(); //draw the right arm glTranslatef(0.0,-12.0,0.0); draw_palm(); //draw the right palm glPopMatrix(); glTranslatef(-3.0,0.0,0.0); glRotatef(theta_thigh_left,1.0,0.0,0.0); draw_thigh(); //draw the left thigh glTranslatef(0.0,-8.0,0.0); glRotatef(theta_shank_left,1.0,0.0,0.0); draw_shank(); //draw the left shank glTranslatef(0.0,-11.0,0.0); draw_foot(); //draw the left foot glPopMatrix(); glTranslatef(3.0,0.0,0.0); glRotatef(theta_thigh_right,1.0,0.0,0.0); draw_thigh(); //draw the left thigh glTranslatef(0.0,-8.0,0.0); glRotatef(theta_shank_right,1.0,0.0,0.0); draw_shank(); //draw the left shank glTranslatef(0.0,-11.0,0.0); draw_foot(); //draw the left foot glPopMatrix(); }