Physics Simulation & Visualization Tool 0.1
A C++ physics simulation engine with real-time 3D visualization
Loading...
Searching...
No Matches
SceneObject Class Reference

#include <SceneObject.h>

Inheritance diagram for SceneObject:
[legend]
Collaboration diagram for SceneObject:
[legend]

Public Types

using PosMap = std::unordered_map< Physics::PhysicsBody *, glm::vec3 >
 

Public Member Functions

 SceneObject (SceneManager *sceneManager, const std::string &meshName, Shader *sdr, const CreationOptions &options, QObject *parent=nullptr)
 
 ~SceneObject ()
 
void setPosition (const glm::vec3 &pos)
 
void setRotation (const glm::vec3 &rot)
 
void setRotationQuat (const glm::quat &q)
 
void setScale (const glm::vec3 &scl)
 
glm::vec3 getPosition () const
 
glm::vec3 getRotation () const
 
glm::quat getRotationQuat () const
 
glm::vec3 getScale () const
 
ShadergetShader () const override
 Gets the shader used to render this object.
 
Rendering::InstanceData getInstanceData () const override
 Gets the complete per-instance data for GPU upload.
 
Physics::PhysicsBodygetPhysicsBody () const
 
std::optional< float > intersectsRay (const Math::Ray &ray) const override
 Tests if a ray intersects this object's geometry.
 
glm::mat4 getModelMatrix () const override
 Gets the model transformation matrix for this instance.
 
void handleClick (const Math::Ray &ray, float distance) override
 Handles a mouse click on this object.
 
void setHovered (bool hovered) override
 Sets the hover state of this object.
 
bool getHovered () const override
 Gets the current hover state of this object.
 
MeshgetMesh () const override
 Gets the mesh geometry for this object.
 
uint32_t getObjectID () const override
 Gets the unique identifier for this object.
 
const std::string & getName () const
 
const std::string & getMeshName () const
 
void setName (std::string name)
 
CreationOptions getCreationOptions () const
 
- Public Member Functions inherited from IDrawable
virtual ~IDrawable ()=default
 Virtual destructor for proper cleanup of derived classes.
 
- Public Member Functions inherited from IPickable
virtual ~IPickable ()=default
 Virtual destructor for proper cleanup of derived classes.
 

Static Public Member Functions

static void setPhysicsPosMap (const PosMap &m)
 
static void setRenderOrigin (const glm::vec3 &origin)
 
static glm::vec3 getRenderOrigin ()
 
static glm::mat4 worldToRenderMatrix ()
 

Detailed Description

Definition at line 22 of file SceneObject.h.

Member Typedef Documentation

◆ PosMap

using SceneObject::PosMap = std::unordered_map<Physics::PhysicsBody*, glm::vec3>

Definition at line 53 of file SceneObject.h.

Constructor & Destructor Documentation

◆ SceneObject()

SceneObject::SceneObject ( SceneManager sceneManager,
const std::string &  meshName,
Shader sdr,
const CreationOptions options,
QObject *  parent = nullptr 
)

Definition at line 17 of file SceneObject.cpp.

Here is the call graph for this function:

◆ ~SceneObject()

SceneObject::~SceneObject ( )

Definition at line 71 of file SceneObject.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ getCreationOptions()

CreationOptions SceneObject::getCreationOptions ( ) const
inline

Definition at line 51 of file SceneObject.h.

Here is the caller graph for this function:

◆ getHovered()

bool SceneObject::getHovered ( ) const
overridevirtual

Gets the current hover state of this object.

Returns
true if the object is currently being hovered over, false otherwise.

Implements IPickable.

Definition at line 244 of file SceneObject.cpp.

◆ getInstanceData()

Rendering::InstanceData SceneObject::getInstanceData ( ) const
overridevirtual

Gets the complete per-instance data for GPU upload.

Constructs an InstanceData structure containing the model matrix, object ID, and any additional per-instance attributes. This data is uploaded to the GPU's instance buffer for instanced rendering.

The default implementation provides model matrix and object ID. Override to add custom attributes (e.g., per-instance color).

Returns
InstanceData structure for this object.
Note
The InstanceData layout must match the vertex attribute setup in Mesh::setupInstanceAttributes().
See also
Rendering::InstanceData
Mesh::drawInstanced()

Implements IInstancedDrawable.

Definition at line 252 of file SceneObject.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getMesh()

Mesh * SceneObject::getMesh ( ) const
inlineoverridevirtual

Gets the mesh geometry for this object.

The mesh is used as part of the batch key for instanced rendering, grouping objects that share the same shader and mesh.

Returns
Pointer to the Mesh object. Must not be null.
See also
ResourceManager::getMesh()
Scene::draw()

Implements IDrawable.

Definition at line 46 of file SceneObject.h.

Here is the caller graph for this function:

◆ getMeshName()

const std::string & SceneObject::getMeshName ( ) const
inline

Definition at line 49 of file SceneObject.h.

Here is the caller graph for this function:

◆ getModelMatrix()

glm::mat4 SceneObject::getModelMatrix ( ) const
overridevirtual

Gets the model transformation matrix for this instance.

The model matrix transforms vertices from model space to render space. World-space drawables should subtract SceneObject::getRenderOrigin() before uploading instance data. Simulation, picking, and serialization must keep using world-space transforms.

Returns
The 4x4 model transformation matrix.
Note
This is called once per frame during batch preparation.

Implements IInstancedDrawable.

Definition at line 78 of file SceneObject.cpp.

Here is the caller graph for this function:

◆ getName()

const std::string & SceneObject::getName ( ) const
inline

Definition at line 48 of file SceneObject.h.

Here is the caller graph for this function:

◆ getObjectID()

uint32_t SceneObject::getObjectID ( ) const
overridevirtual

Gets the unique identifier for this object.

This ID is used for:

  • Object picking and selection
  • Hover state highlighting via shader uniforms
  • Per-instance identification in the rendering pipeline
Returns
The object's unique identifier.
See also
Scene::allocateObjectID()
Scene::freeObjectID()

Implements IDrawable.

Definition at line 248 of file SceneObject.cpp.

Here is the caller graph for this function:

◆ getPhysicsBody()

Physics::PhysicsBody * SceneObject::getPhysicsBody ( ) const
inline

Definition at line 39 of file SceneObject.h.

Here is the caller graph for this function:

◆ getPosition()

glm::vec3 SceneObject::getPosition ( ) const

Definition at line 213 of file SceneObject.cpp.

Here is the caller graph for this function:

◆ getRenderOrigin()

static glm::vec3 SceneObject::getRenderOrigin ( )
inlinestatic

Definition at line 64 of file SceneObject.h.

Here is the caller graph for this function:

◆ getRotation()

glm::vec3 SceneObject::getRotation ( ) const

Definition at line 219 of file SceneObject.cpp.

Here is the caller graph for this function:

◆ getRotationQuat()

glm::quat SceneObject::getRotationQuat ( ) const

Definition at line 232 of file SceneObject.cpp.

Here is the caller graph for this function:

◆ getScale()

glm::vec3 SceneObject::getScale ( ) const

Definition at line 236 of file SceneObject.cpp.

Here is the caller graph for this function:

◆ getShader()

Shader * SceneObject::getShader ( ) const
overridevirtual

Gets the shader used to render this object.

The shader is used as part of the batch key for instanced rendering, grouping objects that share the same shader and mesh.

Returns
Pointer to the Shader object. Must not be null.
See also
ResourceManager::getShader()
Scene::draw()

Implements IDrawable.

Definition at line 223 of file SceneObject.cpp.

Here is the caller graph for this function:

◆ handleClick()

void SceneObject::handleClick ( const Math::Ray ray,
float  distance 
)
overridevirtual

Handles a mouse click on this object.

Called by the scene manager when the user clicks on this object. Implementations can respond by:

  • Changing selection state
  • Spawning interaction gizmos
  • Triggering object-specific behaviors
  • Emitting signals for UI updates
Parameters
rayThe picking ray that intersected this object.
distanceThe distance along the ray to the intersection point.
Note
This is only called if rayIntersection() returned a valid distance.
See also
SceneManager::handleMouseButton()
SceneObject::handleClick()
Gizmo::handleClick()

Implements IPickable.

Definition at line 179 of file SceneObject.cpp.

Here is the call graph for this function:

◆ intersectsRay()

std::optional< float > SceneObject::intersectsRay ( const Math::Ray ray) const
overridevirtual

Tests if a ray intersects this object's geometry.

Implementations should test the ray against the object's bounding volume or exact geometry and return the distance to the intersection point if hit.

Parameters
rayThe picking ray in world space coordinates.
Returns
std::optional<float> containing the distance along the ray to the intersection point if hit, or std::nullopt if no intersection.
Note
For performance, implementations should first test against an AABB before performing exact mesh intersection tests.

Example implementation:

std::optional<float> SceneObject::intersectsRay(const MathUtils::Ray& ray) const {
float aabbDist;
if (!intersectsAABB(ray, aabbDist)) {
return std::nullopt;
}
float meshDist;
if (intersectsMesh(ray, meshDist)) {
return meshDist;
}
return std::nullopt;
}
std::optional< float > intersectsRay(const Math::Ray &ray) const override
Tests if a ray intersects this object's geometry.
See also
SceneObject::intersectsRay()
Gizmo::intersectsRay()
MathUtils::intersectsRay()

Implements IPickable.

Definition at line 166 of file SceneObject.cpp.

◆ setHovered()

void SceneObject::setHovered ( bool  hovered)
overridevirtual

Sets the hover state of this object.

Called by the scene manager when the mouse cursor enters or leaves this object. Implementations should update their internal state and may trigger visual feedback (e.g., highlighting).

The actual visual feedback is typically handled through the rendering system via uniform buffers (isHovered[objectID]).

Parameters
hoveredtrue if the mouse is hovering over this object, false otherwise.
See also
SceneManager::updateHoverState()
Scene::draw()

Implements IPickable.

Definition at line 240 of file SceneObject.cpp.

◆ setName()

void SceneObject::setName ( std::string  name)
inline

Definition at line 50 of file SceneObject.h.

Here is the caller graph for this function:

◆ setPhysicsPosMap()

static void SceneObject::setPhysicsPosMap ( const PosMap m)
inlinestatic

Definition at line 55 of file SceneObject.h.

Here is the caller graph for this function:

◆ setPosition()

void SceneObject::setPosition ( const glm::vec3 &  pos)

Definition at line 183 of file SceneObject.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setRenderOrigin()

static void SceneObject::setRenderOrigin ( const glm::vec3 &  origin)
inlinestatic

Definition at line 60 of file SceneObject.h.

Here is the caller graph for this function:

◆ setRotation()

void SceneObject::setRotation ( const glm::vec3 &  rot)

Definition at line 196 of file SceneObject.cpp.

Here is the call graph for this function:

◆ setRotationQuat()

void SceneObject::setRotationQuat ( const glm::quat &  q)

Definition at line 227 of file SceneObject.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setScale()

void SceneObject::setScale ( const glm::vec3 &  scl)

Definition at line 202 of file SceneObject.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ worldToRenderMatrix()

static glm::mat4 SceneObject::worldToRenderMatrix ( )
inlinestatic

Definition at line 68 of file SceneObject.h.

Here is the caller graph for this function:

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