#include "Camera.h" void InitCamera(VCamera * c) { c->Position.x = 0; c->Position.y = 5; c->Position.z = 0; c->Look.x = 0; c->Look.y = 5; c->Look.z = -1; c->Up.x = 0; c->Up.y = 1; c->Up.z = 0; c->Shake = 0.0; } void OffsetCamera(VCamera * c, Vector * offset, float interval) { c->Position.x += offset->x / interval; c->Position.y += offset->y / interval; c->Position.z += offset->z / interval; c->Look.x += offset->x / interval; c->Look.y += offset->y / interval; c->Look.z += offset->z / interval; } void RotateCamera(VCamera * c, Vector * rotate, float interval) { Quaternion QuatView; Vector NewRot, Forwards; NewRot = *rotate; NormalizeVector(&NewRot); ForwardsVector(c, 1, &Forwards); QuaternionRotateVector(VectorMagnitude(rotate), interval, &NewRot, &Forwards, &QuatView); c->Look.x = c->Position.x + QuatView.v.x; c->Look.y = c->Position.y + QuatView.v.y; c->Look.z = c->Position.z + QuatView.v.z; QuaternionRotateVector(VectorMagnitude(rotate), interval, &NewRot, &c->Up, &QuatView); c->Up.x = QuatView.v.x; c->Up.y = QuatView.v.y; c->Up.z = QuatView.v.z; NormalizeVector(&c->Up); } void ForwardsVector(VCamera * c, float Distance, Vector * Forwards) { Forwards->x = (c->Look.x - c->Position.x) * Distance; Forwards->y = (c->Look.y - c->Position.y) * Distance; Forwards->z = (c->Look.z - c->Position.z) * Distance; } void ApplyCamera(VCamera * c) { Vector LookAtPoint; int shake; int randomInt; float randomValue; LookAtPoint = c->Look; if (c->Shake > 0.001) { shake = (c->Shake * 1000); randomInt = Random(); if (shake != 0) { randomInt %= shake; } randomValue = (randomInt / ((1.0 - c->Shake) * 50000.0)); LookAtPoint.x += randomValue; randomInt = Random(); if (shake != 0) { randomInt %= shake; } randomValue = (randomInt / ((1.0 - c->Shake) * 50000.0)); LookAtPoint.y += randomValue; randomInt = Random(); if (shake != 0) { randomInt %= shake; } randomValue = (randomInt / ((1.0 - c->Shake) * 50000.0)); LookAtPoint.z += randomValue; c->Shake -= 0.01; if (c->Shake < 0.0) c->Shake = 0.0; } gluLookAt (c->Position.x, c->Position.y, c->Position.z, LookAtPoint.x, LookAtPoint.y, LookAtPoint.z, c->Up.x, c->Up.y, c->Up.z); }