#include "ObjectManager.h" #include "WorldManager.h" void InitObject(VObject * o) { o->Position.x = 0.0; o->Position.y = 0.0; o->Position.z = 0.0; o->Front.x = 0.0; o->Front.y = 0.0; o->Front.z = 1.0; o->Right.x = 1.0; o->Right.y = 0.0; o->Right.z = 0.0; o->Up.x = 0.0; o->Up.y = 1.0; o->Up.z = 0.0; o->next = NULL; o->Durability = 2; o->PowerupType = POWERUPTYPENONE; o->PowerupAmount = 0; o->taggedForRemoval = 0; o->Radius = 0.0; o->Billboard = false; o->MustBeDestroyed = false; InitModel(&o->Model); } void CleanUpObject(VObject * o) { CleanUpModel(&o->Model); } void RunObject(VObject * o, void * world) { VWorld * w; float shields; Boolean wasHit = 0; w = (VWorld *)world; if (fabs(((o->Position.x - w->Camera.Position.x) * (o->Position.x - w->Camera.Position.x)) + ((o->Position.y - w->Camera.Position.y) * (o->Position.y - w->Camera.Position.y)) + ((o->Position.z - w->Camera.Position.z) * (o->Position.z - w->Camera.Position.z))) <= (o->Radius + PLAYERSHIPRADIUS)) { wasHit = 1; shields = w->Player.Shields; DamagePlayer(w, o->Durability); o->Durability -= shields; } if (wasHit) { VObjectWrapper * anotherObject; anotherObject = GetWrapperByObject(w->Objects, o); if (anotherObject != NULL) { if (o->Durability <= 0) { anotherObject->exploded = 1; anotherObject->taggedForRemoval = 1; } else { anotherObject->exploded = 2; } } } } void MoveObjectToPoint(VObject * o, Vector * p) { o->Position.x = p->x; o->Position.y = p->y; o->Position.z = p->z; } void RotateObject(VObject * o, Vector * r) { #pragma unused(o, r) /* How to do this? */ } void DrawObject(VObject * o) { GLfloat matrix[16]; glPushMatrix(); if(o->Billboard) { glTranslatef(o->Position.x, o->Position.y, o->Position.z); glGetFloatv(GL_MODELVIEW_MATRIX, matrix); matrix[0]=1.0; matrix[1] = 0.0; matrix[2] = 0.0; matrix[4]=0.0; matrix[5] = 1.0; matrix[6] = 0.0; matrix[8]=0.0; matrix[9] = 0.0; matrix[10] = 1.0; glLoadMatrixf(matrix); glScalef(3, 3, 1); } else { matrix[0] = o->Right.x; matrix[1] = o->Right.y; matrix[2] = o->Right.z; matrix[3] = 0.0f; matrix[4] = o->Up.x; matrix[5] = o->Up.y; matrix[6] = o->Up.z; matrix[7] = 0.0f; matrix[8] = o->Front.x; matrix[9] = o->Front.y; matrix[10] = o->Front.z; matrix[11] = 0.0f; matrix[12] = 0.0f; matrix[13] = 0.0f; matrix[14] = 0.0; matrix[15] = 1.0f; glTranslatef(o->Position.x, o->Position.y, o->Position.z); glMultMatrixf(matrix); } DrawModel(&o->Model); glPopMatrix(); } void CalculateRadius(VObject * o) { int wVertex; float tempRadius; o->Radius = 0.0; for (wVertex = 0; wVertex < o->Model.NumberOfVertices; wVertex++) { tempRadius = fabs((o->Model.Vertices[wVertex].x * o->Model.Vertices[wVertex].x) + (o->Model.Vertices[wVertex].y * o->Model.Vertices[wVertex].y) + (o->Model.Vertices[wVertex].z * o->Model.Vertices[wVertex].z)); if (tempRadius > o->Radius) o->Radius = tempRadius; } } void CopyObject(VObject * src, VObject * dest) { BlockMove(src, dest, sizeof(VObject)); dest->next = NULL; }