#pragma once #include "ModelManager.h" void InitModel(VModel * m) { m->PrimitiveType = GL_POINTS; m->NumberOfVertices = 0; m->Vertices = NULL; m->WireFrame = false; m->Color[0] = m->Color[1] = m->Color[2] = m->Color[3] = 1.0; } void CleanUpModel(VModel * m) { if (m->Vertices != NULL) { DisposePtr((Ptr) m->Vertices); m->Vertices = NULL; } m->NumberOfVertices = 0; } Boolean AllocateVertices(VModel * m, int numberOfVertices) { m->Vertices = (Vector *) NewPtrClear(sizeof(Vector) * numberOfVertices); if (m->Vertices == NULL) return 0; m->NumberOfVertices = numberOfVertices; return 1; } void DrawModel(VModel * m) { int wVertex; glColor4f(m->Color[0], m->Color[1], m->Color[2], m->Color[3]); glBegin(m->PrimitiveType); for (wVertex = 0; wVertex < m->NumberOfVertices; wVertex++) { glVertex3f(m->Vertices[wVertex].x, m->Vertices[wVertex].y, m->Vertices[wVertex].z); } glEnd(); if(!m->WireFrame) { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPolygonOffset(1.0, 1.0); glColor4f(0.0, 0.0, 0.0, m->Color[3]); glBegin(m->PrimitiveType); for (wVertex = 0; wVertex < m->NumberOfVertices; wVertex++) { glVertex3f(m->Vertices[wVertex].x, m->Vertices[wVertex].y, m->Vertices[wVertex].z); } glEnd(); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } } void BuildCrossHairModel(VModel * m) { m->PrimitiveType = GL_QUADS; m->WireFrame = 1; if (AllocateVertices(m, 12)) { m->Vertices[0].x = -0.1; m->Vertices[0].y = 0.1; m->Vertices[0].z = -1.6; m->Vertices[1].x = 0.1; m->Vertices[1].y = 0.1; m->Vertices[1].z = -1.6; m->Vertices[2].x = 0.1; m->Vertices[2].y = -0.1; m->Vertices[2].z = -1.6; m->Vertices[3].x = -0.1; m->Vertices[3].y = -0.1; m->Vertices[3].z = -1.6; m->Vertices[4].x = 0.0; m->Vertices[4].y = 0.2; m->Vertices[4].z = -1.6; m->Vertices[5].x = 0.0; m->Vertices[5].y = 0.2; m->Vertices[5].z = -1.6; m->Vertices[6].x = 0.0; m->Vertices[6].y = -0.2; m->Vertices[6].z = -1.6; m->Vertices[7].x = 0.0; m->Vertices[7].y = -0.2; m->Vertices[7].z = -1.6; m->Vertices[8].x = -0.2; m->Vertices[8].y = 0.0; m->Vertices[8].z = -1.6; m->Vertices[9].x = -0.2; m->Vertices[9].y = 0.0; m->Vertices[9].z = -1.6; m->Vertices[10].x = 0.2; m->Vertices[10].y = 0.0; m->Vertices[10].z = -1.6; m->Vertices[11].x = 0.2; m->Vertices[11].y = 0.0; m->Vertices[11].z = -1.6; } } void BuildBulletModel(VModel * m) { m->PrimitiveType = GL_QUADS; if (AllocateVertices(m, 12)) { m->Vertices[0].x = -0.1; m->Vertices[0].y = 0.1; m->Vertices[0].z = 0.0; m->Vertices[1].x = -0.1; m->Vertices[1].y = -0.1; m->Vertices[1].z = 0.0; m->Vertices[2].x = 0.1; m->Vertices[2].y = -0.1; m->Vertices[2].z = 0.0; m->Vertices[3].x = 0.1; m->Vertices[3].y = 0.1; m->Vertices[3].z = 0.0; m->Vertices[4].x = 0.0; m->Vertices[4].y = 0.1; m->Vertices[4].z = -0.1; m->Vertices[5].x = 0.0; m->Vertices[5].y = -0.1; m->Vertices[5].z = -0.1; m->Vertices[6].x = 0.0; m->Vertices[6].y = -0.1; m->Vertices[6].z = 0.1; m->Vertices[7].x = 0.0; m->Vertices[7].y = 0.1; m->Vertices[7].z = 0.1; m->Vertices[8].x = -0.1; m->Vertices[8].y = 0.0; m->Vertices[8].z = -0.1; m->Vertices[9].x = -0.1; m->Vertices[9].y = 0.0; m->Vertices[9].z = 0.1; m->Vertices[10].x = 0.1; m->Vertices[10].y = 0.0; m->Vertices[10].z = 0.1; m->Vertices[11].x = 0.1; m->Vertices[11].y = 0.0; m->Vertices[11].z = -0.1; } } void BuildTargetModel(VModel * m) { m->PrimitiveType = GL_QUADS; m->Color[0] = 1.0; m->Color[1] = 1.0; m->Color[2] = 0.0; m->Color[3] = 1.0; if (AllocateVertices(m, 12)) { m->Vertices[0].x = -0.5; m->Vertices[0].y = 0.5; m->Vertices[0].z = 0.0; m->Vertices[1].x = -0.5; m->Vertices[1].y = -0.5; m->Vertices[1].z = 0.0; m->Vertices[2].x = 0.5; m->Vertices[2].y = -0.5; m->Vertices[2].z = 0.0; m->Vertices[3].x = 0.5; m->Vertices[3].y = 0.5; m->Vertices[3].z = 0.0; m->Vertices[4].x = 0.0; m->Vertices[4].y = 0.5; m->Vertices[4].z = -0.5; m->Vertices[5].x = 0.0; m->Vertices[5].y = -0.5; m->Vertices[5].z = -0.5; m->Vertices[6].x = 0.0; m->Vertices[6].y = -0.5; m->Vertices[6].z = 0.5; m->Vertices[7].x = 0.0; m->Vertices[7].y = 0.5; m->Vertices[7].z = 0.5; m->Vertices[8].x = -0.5; m->Vertices[8].y = 0.0; m->Vertices[8].z = -0.5; m->Vertices[9].x = -0.5; m->Vertices[9].y = 0.0; m->Vertices[9].z = 0.5; m->Vertices[10].x = 0.5; m->Vertices[10].y = 0.0; m->Vertices[10].z = 0.5; m->Vertices[11].x = 0.5; m->Vertices[11].y = 0.0; m->Vertices[11].z = -0.5; } } void BuildRocketModel(VModel * m) { m->PrimitiveType = GL_QUADS; if (AllocateVertices(m, 76)) { int surface; for (surface = 0; surface < 8; surface++) { m->Vertices[(surface * 4)].x = (cos(((pi * 2) / 8) * surface) / 50.0); m->Vertices[(surface * 4)].y = (sin(((pi * 2) / 8) * surface) / 50.0); m->Vertices[(surface * 4)].z = 0.2; m->Vertices[(surface * 4) + 1].x = (cos(((pi * 2) / 8) * (surface + 1)) / 50.0); m->Vertices[(surface * 4) + 1].y = (sin(((pi * 2) / 8) * (surface + 1)) / 50.0); m->Vertices[(surface * 4) + 1].z = 0.2; m->Vertices[(surface * 4) + 2].x = (cos(((pi * 2) / 8) * (surface + 1)) / 50.0); m->Vertices[(surface * 4) + 2].y = (sin(((pi * 2) / 8) * (surface + 1)) / 50.0); m->Vertices[(surface * 4) + 2].z = -0.14; m->Vertices[(surface * 4) + 3].x = (cos(((pi * 2) / 8) * surface) / 50.0); m->Vertices[(surface * 4) + 3].y = (sin(((pi * 2) / 8) * surface) / 50.0); m->Vertices[(surface * 4) + 3].z = -0.14; } for (surface = 0; surface < 3; surface++) { m->Vertices[32 + (surface * 4)].x = (cos(((pi * 2) / 3) * surface) / 50.0); m->Vertices[32 + (surface * 4)].y = (sin(((pi * 2) / 3) * surface) / 50.0); m->Vertices[32 + (surface * 4)].z = 0.10; m->Vertices[32 + (surface * 4) + 1].x = (cos(((pi * 2) / 3) * surface) / 10.0); m->Vertices[32 + (surface * 4) + 1].y = (sin(((pi * 2) / 3) * surface) / 10.0); m->Vertices[32 + (surface * 4) + 1].z = 0.15; m->Vertices[32 + (surface * 4) + 2].x = (cos(((pi * 2) / 3) * surface) / 10.0); m->Vertices[32 + (surface * 4) + 2].y = (sin(((pi * 2) / 3) * surface) / 10.0); m->Vertices[32 + (surface * 4) + 2].z = 0.25; m->Vertices[32 + (surface * 4) + 3].x = (cos(((pi * 2) / 3) * surface) / 50.0); m->Vertices[32 + (surface * 4) + 3].y = (sin(((pi * 2) / 3) * surface) / 50.0); m->Vertices[32 + (surface * 4) + 3].z = 0.2; } /* Kind of a pain to specify these triangles as quads... We need a way to switch primitive type in the middle of the vertex list, methinks. */ for (surface = 0; surface < 8; surface++) { m->Vertices[44 + (surface * 4)].x = (cos(((pi * 2) / 8) * surface) / 50.0); m->Vertices[44 + (surface * 4)].y = (sin(((pi * 2) / 8) * surface) / 50.0); m->Vertices[44 + (surface * 4)].z = -0.14; m->Vertices[44 + (surface * 4) + 1].x = (cos(((pi * 2) / 8) * (surface + 1)) / 50.0); m->Vertices[44 + (surface * 4) + 1].y = (sin(((pi * 2) / 8) * (surface + 1)) / 50.0); m->Vertices[44 + (surface * 4) + 1].z = -0.14; m->Vertices[44 + (surface * 4) + 2].x = 0.0; m->Vertices[44 + (surface * 4) + 2].y = 0.0; m->Vertices[44 + (surface * 4) + 2].z = -0.2; m->Vertices[44 + (surface * 4) + 3] = m->Vertices[44 + (surface * 4) + 2]; } } }