Kemena3D
Loading...
Searching...
No Matches
kemena::kCamera Class Reference

Scene-graph camera node. More...

#include <kcamera.h>

Inheritance diagram for kemena::kCamera:
Collaboration diagram for kemena::kCamera:

Public Member Functions

 kCamera (kObject *parentNode=nullptr, kCameraType type=kCameraType::CAMERA_TYPE_FREE)
 Constructs a camera and optionally attaches it to a parent.
void setCameraType (kCameraType newType)
 Sets the camera mode.
kCameraType getCameraType ()
 Returns the current camera mode.
void setLookAt (kVec3 newLookAt)
 Sets the look-at target used when the camera is locked.
kVec3 getLookAt ()
 Returns the look-at target.
void setFOV (float newFOV)
 Sets the vertical field of view.
float getFOV ()
 Returns the vertical field of view.
void setNearClip (float newNearClip)
 Sets the near clipping plane distance.
float getNearClip ()
 Returns the near clipping plane distance.
void setFarClip (float newFarClip)
 Sets the far clipping plane distance.
float getFarClip ()
 Returns the far clipping plane distance.
void setAspectRatio (float newAspectRatio)
 Sets the viewport aspect ratio (width / height).
float getAspectRatio ()
 Returns the viewport aspect ratio.
kMat4 calculateMVP (kMesh *mesh)
 Computes the combined Model-View-Projection matrix for a mesh.
kMat4 getViewMatrix ()
 Returns the view matrix for this camera.
kMat4 getProjectionMatrix ()
 Returns the projection matrix for this camera.
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 screenToRay (float mouseX, float mouseY, float viewWidth, float viewHeight, kVec3 &outOrigin, kVec3 &outDirection)
 Converts a viewport-relative pixel coordinate into a world-space ray.
void setPosition (kVec3 newPosition)
 Sets the local position and updates all dependent matrices.
void setRotation (kQuat newRotation)
 Sets the local rotation and updates all dependent matrices.
json serialize ()
 Serialises the camera to JSON.
void deserialize (json data)
 Restores the camera state from a JSON object.
kString getSceneUuid () const
 UUID of the scene this camera renders (empty = auto/default).
void setSceneUuid (const kString &uuid)
 Sets the UUID of the scene this camera renders (empty = auto/default).
Public Member Functions inherited from kemena::kObject
 kObject (kObject *parentNode=nullptr)
 Constructs a kObject and optionally attaches it to a parent.
virtual ~kObject ()
 Destroys the object.
kObjectgetParent ()
 Returns the parent node.
void setParent (kObject *newParent)
 Reparents this object under newParent.
void detachFromParent ()
 Removes this object from its parent's children list.
void setParentKeepTransform (kObject *newParent)
 Reparents this object while keeping its world transform.
std::vector< kObject * > getChildren ()
 Returns the list of direct children.
std::vector< kScript > & getScripts ()
 Returns a mutable reference to the list of attached scripts.
void addScript (const kScript &script)
 Appends a script descriptor to this object.
void removeScript (const kString &uuid)
 Removes the script with the given UUID from this object.
std::vector< kParticle > & getParticles ()
 Returns a mutable reference to the list of attached particle systems.
void addParticle (const kParticle &particle)
 Appends a particle system descriptor to this object.
void removeParticle (const kString &uuid)
 Removes the particle system with the given UUID from this object.
std::vector< kAudioSource > & getAudioSources ()
 Returns a mutable reference to the list of attached audio sources.
void addAudioSource (const kAudioSource &source)
 Appends an audio source descriptor to this object.
void removeAudioSource (const kString &uuid)
 Removes the audio source with the given UUID from this object.
std::vector< kAudioListener > & getAudioListeners ()
 Returns a mutable reference to the list of audio listener components (0 or 1).
void addAudioListener (const kAudioListener &listener)
 Attaches an audio listener descriptor to this object.
void removeAudioListener (const kString &uuid)
 Removes the audio listener with the given UUID from this object.
bool getHasPhysicsDesc () const
 Returns true if this object has a physics body descriptor configured.
void setHasPhysicsDesc (bool val)
 Sets whether this object has a physics body descriptor.
kPhysicsObjectDescgetPhysicsDesc ()
 Returns a mutable reference to the physics body descriptor.
bool getHasCharacterDesc () const
 Returns true if this object has a character controller configured.
void setHasCharacterDesc (bool val)
 Sets whether this object has a character controller descriptor.
kCharacterControllerDescgetCharacterDesc ()
 Returns a mutable reference to the character controller descriptor.
bool getHasNavMeshDesc () const
 Returns true if this object carries a navigation surface.
void setHasNavMeshDesc (bool val)
 Sets whether this object carries a navigation surface.
kNavMeshDescgetNavMeshDesc ()
 Returns a mutable reference to the navigation surface descriptor.
kNodeType getType ()
 Returns the scene-graph node type tag.
void setType (kNodeType newType)
 Sets the node type tag.
bool getActive ()
 Returns whether this object is active (visible/processed).
void setActive (bool newActive)
 Activates or deactivates the object.
bool getStatic ()
 Returns whether this object is marked as static (immobile geometry).
void setStatic (bool newStatic)
 Marks the object as static or dynamic.
bool getDebugMode ()
 Returns whether editor debug visualization is enabled.
void setDebugMode (bool newMode)
 Enables or disables editor debug visualization for this object.
unsigned int getId ()
 Returns the numeric identifier of this object.
void setId (unsigned int newId)
 Sets the numeric identifier.
kString getUuid ()
 Returns the UUID kString of this object.
void setUuid (kString newUuid)
 Sets the UUID kString.
kString getName ()
 Returns the display name of this object.
void setName (kString newName)
 Sets the display name.
kString getPrefabRef () const
 Returns the prefab asset UUID this object is an instance of, or empty.
void setPrefabRef (const kString &ref)
 Sets the prefab asset UUID this object is an instance of.
kString getTemplateUuid () const
 Returns the UUID of the corresponding node in the prefab template.
void setTemplateUuid (const kString &uuid)
 Sets the corresponding template UUID for this prefab instance node.
kVec3 getPosition ()
 Returns the local position.
kQuat getRotation ()
 Returns the local rotation as a quaternion.
kVec3 getRotationEuler ()
 Returns the local rotation as Euler angles in degrees.
kVec3 getScale ()
 Returns the local scale.
virtual void setScale (kVec3 newScale)
 Sets the local scale.
kVec3 calculateRight ()
 Computes the local right (+X) direction in world space.
kVec3 calculateForward ()
 Computes the local forward (-Z) direction in world space.
kVec3 calculateUp ()
 Computes the local up (+Y) direction in world space.
void rotate (kVec3 rotationAxis, float angularSpeed)
 Rotates the object around an axis by a given angular speed.
kVec3 getGlobalPosition ()
 Returns the world-space position derived from the world transform.
kQuat getGlobalRotation ()
 Returns the world-space rotation derived from the world transform.
kVec3 getGlobalScale ()
 Returns the world-space scale derived from the world transform.
void setMaterial (kMaterial *newMaterial, bool setChildren=true)
 Assigns a material to this object and optionally its children.
kMaterialgetMaterial ()
 Returns the assigned material.
void setMaterialUuid (const kString &uuid)
 Sets the source asset UUID of the assigned material.
kString getMaterialUuid () const
 Returns the source asset UUID of the assigned material.
void setImportChild (bool v)
 Marks this node as an import-derived sub-mesh.
bool getImportChild () const
 Whether this node is an import-derived sub-mesh (see setImportChild).
void calculateModelMatrix ()
 Recomputes the local and world-space model matrices.
kMat4 getModelMatrixWorld ()
 Returns the world-space model matrix.
kMat4 getModelMatrixLocal ()
 Returns the local model matrix (relative to the parent).
virtual void draw ()
 Draws the object.
void attachPhysics (kPhysicsObject *physicsObj)
 Attaches a physics body to this object.
void detachPhysics ()
 Detaches the physics body without destroying it.
kPhysicsObjectgetPhysicsObject ()
 Returns the attached physics body, or nullptr if none is attached.
void syncFromPhysics ()
 Copies the physics body's current position and rotation into this object's local transform.
void attachCharacter (kCharacterController *character)
 Attaches a runtime character controller to this object.
void detachCharacter ()
 Detaches the character controller without destroying it.
kCharacterControllergetCharacterController ()
 Returns the attached character controller, or nullptr.
void syncFromCharacter ()
 Copies the character controller's position into this object's local transform. Call once per frame after the physics update.

Detailed Description

Scene-graph camera node.

Supports two modes selected at construction:

  • CAMERA_TYPE_FREE — orientation is controlled by position + rotation.
  • CAMERA_TYPE_LOCKED — orientation always faces the look-at target.

View and projection matrices are computed on demand via getViewMatrix() and getProjectionMatrix().

Constructor & Destructor Documentation

◆ kCamera()

kemena::kCamera::kCamera ( kObject * parentNode = nullptr,
kCameraType type = kCameraType::CAMERA_TYPE_FREE )

Constructs a camera and optionally attaches it to a parent.

Parameters
parentNodeParent scene-graph node, or nullptr.
typeCamera mode (free-look or locked look-at).
Here is the call graph for this function:

Member Function Documentation

◆ calculateMVP()

kMat4 kemena::kCamera::calculateMVP ( kMesh * mesh)

Computes the combined Model-View-Projection matrix for a mesh.

Parameters
meshTarget mesh whose model matrix is used.
Returns
MVP matrix.

◆ deserialize()

void kemena::kCamera::deserialize ( json data)
virtual

Restores the camera state from a JSON object.

Parameters
dataJSON produced by serialize().

Reimplemented from kemena::kObject.

◆ getAspectRatio()

float kemena::kCamera::getAspectRatio ( )

Returns the viewport aspect ratio.

Returns
Aspect ratio (width / height).

◆ getCameraType()

kCameraType kemena::kCamera::getCameraType ( )

Returns the current camera mode.

Returns
Camera type enum value.

◆ getFarClip()

float kemena::kCamera::getFarClip ( )

Returns the far clipping plane distance.

Returns
Far plane distance.

◆ getFOV()

float kemena::kCamera::getFOV ( )

Returns the vertical field of view.

Returns
FOV in degrees.

◆ getLookAt()

kVec3 kemena::kCamera::getLookAt ( )

Returns the look-at target.

Returns
World-space target point.

◆ getNearClip()

float kemena::kCamera::getNearClip ( )

Returns the near clipping plane distance.

Returns
Near plane distance.

◆ getProjectionMatrix()

kMat4 kemena::kCamera::getProjectionMatrix ( )

Returns the projection matrix for this camera.

Returns
Perspective projection matrix.

◆ getSceneUuid()

kString kemena::kCamera::getSceneUuid ( ) const
inline

UUID of the scene this camera renders (empty = auto/default).

◆ getViewMatrix()

kMat4 kemena::kCamera::getViewMatrix ( )

Returns the view matrix for this camera.

Returns
World-to-view transform.

◆ rotateByMouse()

void kemena::kCamera::rotateByMouse ( kQuat rotation,
float deltaX,
float deltaY,
float sensitivity = 0.005f,
float pitchLimit = 89.0f )

Applies mouse-delta rotation to a free-look camera.

Parameters
rotationCurrent orientation quaternion.
deltaXHorizontal mouse delta in pixels.
deltaYVertical mouse delta in pixels.
sensitivityRadians-per-pixel multiplier (default 0.005).
pitchLimitMaximum pitch angle in degrees (default 89).

◆ screenToRay()

void kemena::kCamera::screenToRay ( float mouseX,
float mouseY,
float viewWidth,
float viewHeight,
kVec3 & outOrigin,
kVec3 & outDirection )

Converts a viewport-relative pixel coordinate into a world-space ray.

Use the returned ray with kPhysicsManager::raycast() for game-play picking, or with kRenderer::pickObject() for editor picking.

kVec3 origin, dir;
camera->screenToRay(mouseX, mouseY, viewWidth, viewHeight, origin, dir);
auto hit = physics->raycast(origin, dir, 1000.0f);
glm::vec3 kVec3
3-component float vector.
Definition kdatatype.h:33
Parameters
mouseXViewport-relative X (0 = left edge).
mouseYViewport-relative Y (0 = top edge).
viewWidthViewport width in pixels.
viewHeightViewport height in pixels.
outOriginWorld-space ray origin (camera position).
outDirectionNormalised world-space ray direction.

◆ serialize()

json kemena::kCamera::serialize ( )
virtual

Serialises the camera to JSON.

Returns
JSON object with all camera fields.

Reimplemented from kemena::kObject.

◆ setAspectRatio()

void kemena::kCamera::setAspectRatio ( float newAspectRatio)

Sets the viewport aspect ratio (width / height).

Parameters
newAspectRatioAspect ratio.

◆ setCameraType()

void kemena::kCamera::setCameraType ( kCameraType newType)

Sets the camera mode.

Parameters
newTypeNew camera mode.

◆ setFarClip()

void kemena::kCamera::setFarClip ( float newFarClip)

Sets the far clipping plane distance.

Parameters
newFarClipFar plane distance (positive, in world units).

◆ setFOV()

void kemena::kCamera::setFOV ( float newFOV)

Sets the vertical field of view.

Parameters
newFOVFOV in degrees.

◆ setLookAt()

void kemena::kCamera::setLookAt ( kVec3 newLookAt)

Sets the look-at target used when the camera is locked.

Parameters
newLookAtWorld-space point the camera faces.

◆ setNearClip()

void kemena::kCamera::setNearClip ( float newNearClip)

Sets the near clipping plane distance.

Parameters
newNearClipNear plane distance (positive, in world units).

◆ setPosition()

void kemena::kCamera::setPosition ( kVec3 newPosition)
virtual

Sets the local position and updates all dependent matrices.

Reimplemented from kemena::kObject.

◆ setRotation()

void kemena::kCamera::setRotation ( kQuat newRotation)
virtual

Sets the local rotation and updates all dependent matrices.

Reimplemented from kemena::kObject.

◆ setSceneUuid()

void kemena::kCamera::setSceneUuid ( const kString & uuid)
inline

Sets the UUID of the scene this camera renders (empty = auto/default).


The documentation for this class was generated from the following file: