Kemena3D
Loading...
Searching...
No Matches
kcamera.h
Go to the documentation of this file.
1
5
6#ifndef KCAMERA_H
7#define KCAMERA_H
8
9#include <iostream>
10#include <string>
11#include <vector>
12
13#include <glm/glm.hpp>
14#include <glm/gtc/matrix_transform.hpp>
15#include <glm/gtc/type_ptr.hpp>
16
17#include "kdatatype.h"
18#include "kmesh.h"
19
20namespace kemena
21{
32 class kCamera : public kObject
33 {
34 public:
41
47
53
58 void setLookAt(kVec3 newLookAt);
59
65
70 void setFOV(float newFOV);
71
76 float getFOV();
77
82 void setNearClip(float newNearClip);
83
88 float getNearClip();
89
94 void setFarClip(float newFarClip);
95
100 float getFarClip();
101
106 void setAspectRatio(float newAspectRatio);
107
113
120
126
132
141 void rotateByMouse(kQuat rotation, float deltaX, float deltaY, float sensitivity = 0.005f, float pitchLimit = 89.0f);
142
162 void screenToRay(float mouseX, float mouseY,
163 float viewWidth, float viewHeight,
164 kVec3 &outOrigin, kVec3 &outDirection);
165
167 void setPosition(kVec3 newPosition);
169 void setRotation(kQuat newRotation);
170
176
181 void deserialize(json data);
182
184 kString getSceneUuid() const { return sceneUuid; }
186 void setSceneUuid(const kString &uuid) { sceneUuid = uuid; }
187
188 protected:
189 private:
190 kCameraType cameraType;
191 kVec3 lookAt = kVec3(0.0f, 0.0f, 0.0f);
192 float fov = 45.0f;
193 float nearClip = 0.1f;
194 float farClip = 100.0f;
195 float aspectRatio = 1.0f;
196 kString sceneUuid = "";
197 };
198}
199
200#endif // KCAMERA_H
kVec3 getLookAt()
Returns the look-at target.
kString getSceneUuid() const
UUID of the scene this camera renders (empty = auto/default).
Definition kcamera.h:184
float getNearClip()
Returns the near clipping plane distance.
kMat4 calculateMVP(kMesh *mesh)
Computes the combined Model-View-Projection matrix for a mesh.
void setRotation(kQuat newRotation)
Sets the local rotation and updates all dependent matrices.
float getAspectRatio()
Returns the viewport aspect ratio.
void rotateByMouse(kQuat rotation, float deltaX, float deltaY, float sensitivity=0.005f, float pitchLimit=89.0f)
Applies mouse-delta rotation to a free-look camera.
void setPosition(kVec3 newPosition)
Sets the local position and updates all dependent matrices.
void setSceneUuid(const kString &uuid)
Sets the UUID of the scene this camera renders (empty = auto/default).
Definition kcamera.h:186
void setNearClip(float newNearClip)
Sets the near clipping plane distance.
float getFarClip()
Returns the far clipping plane distance.
kMat4 getViewMatrix()
Returns the view matrix for this camera.
void setAspectRatio(float newAspectRatio)
Sets the viewport aspect ratio (width / height).
void screenToRay(float mouseX, float mouseY, float viewWidth, float viewHeight, kVec3 &outOrigin, kVec3 &outDirection)
Converts a viewport-relative pixel coordinate into a world-space ray.
kCamera(kObject *parentNode=nullptr, kCameraType type=kCameraType::CAMERA_TYPE_FREE)
Constructs a camera and optionally attaches it to a parent.
kMat4 getProjectionMatrix()
Returns the projection matrix for this camera.
float getFOV()
Returns the vertical field of view.
void setFOV(float newFOV)
Sets the vertical field of view.
void setLookAt(kVec3 newLookAt)
Sets the look-at target used when the camera is locked.
json serialize()
Serialises the camera to JSON.
void deserialize(json data)
Restores the camera state from a JSON object.
kCameraType getCameraType()
Returns the current camera mode.
void setCameraType(kCameraType newType)
Sets the camera mode.
void setFarClip(float newFarClip)
Sets the far clipping plane distance.
Scene-graph node that holds renderable geometry.
Definition kmesh.h:35
kObject(kObject *parentNode=nullptr)
Constructs a kObject and optionally attaches it to a parent.
Core type aliases, enumerations, structs, and utility functions used throughout the engine.
Polygonal mesh node with skeletal animation support.
nlohmann::json json
Definition kobject.h:30
Top-level Kemena3D engine namespace.
Definition kanimation.h:23
kCameraType
Camera behaviour mode.
Definition kdatatype.h:97
@ CAMERA_TYPE_FREE
Free-fly; position and orientation are set independently.
Definition kdatatype.h:98
std::string kString
Standard string alias.
Definition kdatatype.h:42
glm::quat kQuat
Unit quaternion.
Definition kdatatype.h:40
glm::vec3 kVec3
3-component float vector.
Definition kdatatype.h:33
glm::mat4 kMat4
4x4 float matrix.
Definition kdatatype.h:39