/** * Compute the normals for all faces of this mesh object. * The result is stored in 'FaceNormalList'. * Assume that 'TriIndices' and 'PositionList' have been populated. */ void MeshData::computeFaceNormals() { for (unsigned int triIndex = 0; triIndex < TriIndices.size(); triIndex ++) { Vec3i tri = TriIndices[triIndex]; tri[0] -= 1; tri[1] -= 1; tri[2] -= 1; Vec3f p1 = PositionList[tri[0]]; Vec3f p2 = PositionList[tri[1]]; Vec3f p3 = PositionList[tri[2]]; float v1[3] = {p1[0] - p3[0], p1[1] - p3[1], p1[2] - p3[2]}; float v2[3] = {p2[0] - p3[0], p2[1] - p3[1], p2[2] - p3[2]}; float result[3]; calculateCrossProduct(v1, v2, result); FaceNormalList.push_back(result); } }
// Draw an individual bone void Skeleton::drawBoneSegment(bone* root, GLUquadric* q) { if (root == NULL) { return; } GLfloat a = 0.0; // Find rotation vector normal. G308_Point v1 = { 0, 0, 1 }; G308_Point v2 = { root->dirx, root->diry, root->dirz }; G308_Point normal = { 0, 0, 0 }; calculateCrossProduct(v1, v2, &normal); // Calculate rotation angle from bone's direction vector (degrees). a = calculateAngleFromDotProduct(v1, v2); // Draw spheres to represent joints if (jointsOn == true) { drawJoints(root); } // Rotate local coordinates glRotatef(root->rotz, 0, 0, 1); glRotatef(root->roty, 0, 1, 0); glRotatef(root->rotx, 1, 0, 0); // Rotate current frame/pose doCurrentMove(root); // Rotate local coordinates glRotatef(-root->rotx, 1, 0, 0); glRotatef(-root->roty, 0, 1, 0); glRotatef(-root->rotz, 0, 0, 1); // Draw axis of each individual joint if (jointAxisOn == true) { glPushMatrix(); glRotatef(a, normal.x, normal.y, normal.z); drawJointAxis(q); glPopMatrix(); } glPushMatrix(); glColor3f(1, 1, 1); // Rotate bone. glRotatef(a, normal.x, normal.y, normal.z); // Draw face on the 'head' bone if (headOn == true && strcmp(root->name, "head") == 0) { displayFace(root); } // Draw the actual bone gluCylinder(q, 0.3, 0.3, root->length, 3, 3); // If using second character // Draw cuboid limbs if (currentCharacter == 1) { glScalef(0.2, 0.2, 1); glTranslatef(0,-2,0); glTranslatef(0, 0, root->length /2); // Draw chest if (strcmp(root->name,"lowerback") == 0 || strcmp(root->name,"upperback") == 0 || strcmp(root->name,"thorax") == 0) { glPushMatrix(); glScalef(12, 2, 1); glutSolidCube(root->length); glPopMatrix(); } else glutSolidCube(root->length); // Draw lower(root) chest if (strcmp(root->name,"lowerback") == 0) { glPushMatrix(); glTranslatef(0,0,-root->length); glScalef(12, 3, 1); glutSolidCube(root->length); glPopMatrix(); } } glPopMatrix(); // Move bone to correct location glTranslatef(root->length * root->dirx, root->length * root->diry, root->length * root->dirz); }