#pragma once #include "WorldManager.h" void InitWorld(VWorld * world) { world->cameraPos.x = 0.0; world->cameraPos.y = 0.0; world->cameraPos.z = 0.0; world->view.x = 0.0; world->view.y = 0.0; world->view.z = -1.0; world->up.x = 0.0; world->up.y = 1.0; world->up.z = 0.0; world->Weapons = NULL; } void CleanUpWorld(VWorld * world) { VWeapon * theWeapon; while (world->Weapons != NULL) { theWeapon = world->Weapons; world->Weapons = theWeapon->next; CleanUpWeapon(theWeapon); DisposePtr((Ptr) theWeapon); } } void OffsetCamera(VWorld * world, Vector * offset, float interval) { world->cameraPos.x += offset->x / interval; world->cameraPos.y += offset->y / interval; world->cameraPos.z += offset->z / interval; world->view.x += offset->x / interval; world->view.y += offset->y / interval; world->view.z += offset->z / interval; } void RotateCamera(VWorld * world, Vector * rotate, float interval) { Quaternion Rotation, QuatView, Result; Vector NewRot, Forwards; NewRot = *rotate; NormalizeVector(&NewRot); RotateQuaternion(&NewRot, VectorMagnitude(rotate) / interval, &Rotation); ForwardsVector(world, 1, &Forwards); Vector2Quaternion(&Forwards, &QuatView); MultiplyQuaternion(&Rotation, &QuatView, &Result); ConjugateQuaternion(&Rotation); MultiplyQuaternion(&Result, &Rotation, &QuatView); world->view.x = world->cameraPos.x + QuatView.v.x; world->view.y = world->cameraPos.y + QuatView.v.y; world->view.z = world->cameraPos.z + QuatView.v.z; } void ForwardsVector(VWorld * w, float Distance, Vector * Forwards) { Forwards->x = (w->view.x - w->cameraPos.x) * Distance; Forwards->y = (w->view.y - w->cameraPos.y) * Distance; Forwards->z = (w->view.z - w->cameraPos.z) * Distance; } void ApplyCamera(VWorld * world) { gluLookAt (world->cameraPos.x, world->cameraPos.y, world->cameraPos.z, world->view.x, world->view.y, world->view.z, world->up.x, world->up.y, world->up.z); } void DrawWorld(VWorld * world) { VWeapon * theWeapon; for (theWeapon = world->Weapons; theWeapon != NULL; theWeapon = theWeapon->next) { DrawWeapon(theWeapon); } } void RunWorld(VWorld * world, float interval) { VWeapon * theWeapon, * previous = NULL; for (theWeapon = world->Weapons; theWeapon != NULL; theWeapon = theWeapon->next) { if (theWeapon->taggedForRemoval) { if (previous == NULL) world->Weapons = theWeapon->next; else previous->next = theWeapon->next; CleanUpWeapon(theWeapon); DisposePtr((Ptr) theWeapon); theWeapon = previous; if (theWeapon == NULL) break; continue; } RunWeapon(theWeapon, interval); previous = theWeapon; } }