#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; } 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) { gluLookAt (c->Position.x, c->Position.y, c->Position.z, c->Look.x, c->Look.y, c->Look.z, c->Up.x, c->Up.y, c->Up.z); }