3#define LNC_PI 3.14159265358979323846
4#define LNC_RADIANS(deg) (deg * LNC_PI / 180.0)
39 bool movingFront{
false };
40 bool movingBack{
false };
41 bool movingLeft{
false };
42 bool movingRight{
false };
45 float mouseX{ -1.0f }, mouseY{ -1.0f };
46 bool mouseEnabled{
false };
54 void updateDirection() {
72 Camera(
Vec3 position,
float moveSpeed = 0.015f,
float mouseSens = 0.15f,
Vec3 worldUp =
Vec3(0.0f, 1.0f, 0.0f)) {
73 this->position = position;
74 this->moveSpeed = moveSpeed;
75 this->mouseSens = mouseSens;
76 this->worldUp = worldUp;
107 mouseEnabled =
false;
108 mouseX = mouseY = -1.0f;
124 else if (mouseX == -1.0f && mouseY == -1.0f) {
130 float xOffset = (xPosition - mouseX) * mouseSens;
131 float yOffset = (mouseY - yPosition) * mouseSens;
139 if (pitch > 89.0f) pitch = 89.0f;
140 else if (pitch < -89.0f) pitch = -89.0f;
153 if (movingFront) position = position + (direction * moveSpeed);
154 if (movingBack) position = position - (direction * moveSpeed);
155 if (movingRight) position = position + (right * moveSpeed);
156 if (movingLeft) position = position - (right * moveSpeed);
164 return Mat4::lookAt(position, position + direction, up);
#define LNC_RADIANS(deg)
Definition Camera.h:4
4×4 matrix template for 3D transformations, projections, and stereo sets.
Mat4t< float > Mat4
Single-precision 4×4 matrix.
Definition Mat4.h:567
3D vector template with arithmetic, geometry helpers, and RNG utilities.
Vec3t< float > Vec3
3D float vector (x,y,z).
Definition Vec3.h:424
void moveBack(bool b)
Toggle backward motion along the view direction.
Definition Camera.h:86
void mouseMove(float xPosition, float yPosition)
Update yaw/pitch from a new cursor position.
Definition Camera.h:120
void moveLeft(bool b)
Toggle motion to the left (strafe).
Definition Camera.h:92
Mat4 viewMatrix()
Compute the view (camera) matrix.
Definition Camera.h:163
void enableMouse()
Enable mouse-look processing in mouseMove().
Definition Camera.h:98
void disableMouse()
Disable mouse-look and reset the internal cursor cache.
Definition Camera.h:106
Camera(Vec3 position, float moveSpeed=0.015f, float mouseSens=0.15f, Vec3 worldUp=Vec3(0.0f, 1.0f, 0.0f))
Construct a camera at position with speeds/sensitivity and an up axis.
Definition Camera.h:72
void updatePosition()
Integrate position one step based on active movement flags.
Definition Camera.h:152
void moveFront(bool b)
Toggle forward motion along the view direction.
Definition Camera.h:83
void moveRight(bool b)
Toggle motion to the right (strafe).
Definition Camera.h:89
static Mat4t lookAt(const Vec3t< float > &vEye, const Vec3t< float > &vAt, const Vec3t< float > &vUp)
Definition Mat4.h:491
static Vec3t cross(const Vec3t &a, const Vec3t &b)
Definition Vec3.h:247
static Vec3t normalize(const Vec3t &a)
Definition Vec3.h:258