1 module testbed.fpcamera; 2 3 import derelict.opengl.gl; 4 5 import dlib.core.memory; 6 import dlib.math.vector; 7 import dlib.math.matrix; 8 import dlib.math.transformation; 9 import dlib.math.utils; 10 11 import dgl.core.interfaces; 12 13 class FirstPersonCamera: Modifier 14 { 15 Matrix4x4f transformation; 16 Matrix4x4f characterMatrix; 17 Matrix4x4f worldTransInv; 18 Vector3f position; 19 float turn = 0.0f; 20 float pitch = 0.0f; 21 float roll = 0.0f; 22 23 this(Vector3f position) 24 { 25 this.position = position; 26 } 27 28 Matrix4x4f worldTrans(double dt) 29 { 30 Matrix4x4f m = translationMatrix(position + Vector3f(0, 1, 0)); 31 m *= rotationMatrix(Axis.y, degtorad(turn)); 32 characterMatrix = m; 33 m *= rotationMatrix(Axis.x, degtorad(pitch)); 34 m *= rotationMatrix(Axis.z, degtorad(roll)); 35 return m; 36 } 37 38 override void bind(double dt) 39 { 40 transformation = worldTrans(dt); 41 worldTransInv = transformation.inverse; 42 glPushMatrix(); 43 glMultMatrixf(worldTransInv.arrayof.ptr); 44 } 45 46 override void unbind() 47 { 48 glPopMatrix(); 49 } 50 51 void free() 52 { 53 Delete(this); 54 } 55 } 56