![]() |
Lysa Nodes
0.0
Lysa Nodes — Scene Graph for the Lysa Engine
|
lysa::nodes::Camera Camera extends both Node and lysa::Camera. Its updateGlobalTransform() override keeps lysa::Camera::transform equal to globalTransform and immediately calls SceneTree::setCamera(*this), so the renderer always sees the current world-space camera transform without any manual synchronisation step.
The projection matrix is computed when the camera is attached to a scene tree that is itself attached to a render target. Camera::_attachToScene reads the render target's current aspect ratio and subscribes to RESIZED so the projection is automatically rebuilt whenever the window is resized.
For this reason the camera must be added to the scene tree after SceneTree::attach(window) has been called (see Scene tree).
The camera is placed inside a two-node hierarchy that separates yaw from pitch to avoid gimbal lock:
[MAX_CAMERA_ANGLE_DOWN, MAX_CAMERA_ANGLE_UP] to prevent the camera from flipping upside-down.updateGlobalTransform override automatically propagates the combined yaw+pitch to lysa::Camera::transform and to SceneTree::setCamera.When cameraAttachment->setTransform(…) is called, the transform change propagates through the entire subtree. By the time the call returns, the renderer's camera is already updated. No explicit camera push is needed.
rotateCamera() implementation A Y-axis rotation is pre-multiplied onto the attachment's current transform (pre-multiply because mul(A, B) applies A first; putting the rotation first turns the camera in world space). The same technique applies pitch to the pivot, followed by a clamp step that corrects over-rotation.
Each call to setTransform triggers updateGlobalTransform cascading down to camera, which updates the renderer. The three calls in rotateCamera each trigger a cascade; this is harmless because the renderer reads the camera only at render time.
Movement is accumulated during the fixed-timestep onPhysicsProcess ticks and interpolated to the variable-rate onProcess frame:
Translating by pre-multiplying a pure-translation matrix onto the current transform moves the camera in world space (the translation rows of attachment->getTransform() are in world space).
setPosition writes directly to localTransform[3] and calls updateGlobalTransform. Since the attachment has no parent at this point, localTransform = globalTransform, placing the camera 4 units in front of the world origin.