The small3d framework
Public Member Functions | Public Attributes | List of all members
small3d::SceneObject Class Reference

An object that appears on the 3D scene. It is made up of one or more models (the latter for animation), together with information about positioning and rotation and collision detection functionality. More...

#include <SceneObject.hpp>

Public Member Functions

 SceneObject (const std::string name, const std::string modelPath, const int numFrames=1, const std::string boundingBoxSetPath="", const int startFrameIndex=1)
 Constructor. More...
 
 ~SceneObject ()=default
 Destructor.
 
Model & getModel ()
 Get the object's model. More...
 
bool isAnimated () const
 Is this an animated or a static object (is it associated with more than one frames/models)? More...
 
const std::string getName () const
 Get the name of the object. More...
 
void startAnimating ()
 Start animating the object.
 
void stopAnimating ()
 Stop animating the object.
 
void resetAnimation ()
 Reset the animation sequence (go to the first frame)
 
void setFrameDelay (const int delay)
 Set the animation speed. More...
 
void animate ()
 Process animation (progress current frame if necessary)
 
bool collidesWith (const glm::vec3 point) const
 Check if the object collides with a given point. More...
 
bool collidesWith (SceneObject otherObject) const
 Check if the object collides with another given object. More...
 

Public Attributes

std::vector< Model > models
 The models making up the object's animation. Do not manipulate directly.
 
glm::vec3 offset
 
glm::vec3 rotation
 
BoundingBoxSet boundingBoxSet
 The bounding boxes for the object, used for collision detection.
 

Detailed Description

An object that appears on the 3D scene. It is made up of one or more models (the latter for animation), together with information about positioning and rotation and collision detection functionality.

Constructor & Destructor Documentation

◆ SceneObject()

small3d::SceneObject::SceneObject ( const std::string  name,
const std::string  modelPath,
const int  numFrames = 1,
const std::string  boundingBoxSetPath = "",
const int  startFrameIndex = 1 
)

Constructor.

Parameters
nameThe name of the object
modelPathThe path to the file containing the object's model. When animating (also see numFrames parameter) it is assumed that multiple files will be loaded, the name of which contains a 6 digit suffix (after an underscore) representing the animation sequence, and terminates with the .obj extension. This is also the format used by Blender when exporting animations to Wavefront files. When loading multiple models for animation do not enter a full filename. Skip the suffix and the extension. For example an animation sequence made up of files named frog_000001.obj, frog_000002.obj etc. should be loaded using the parameter "directory/frog" here.
numFramesThe number of frames, if the object is animated. A single animation sequence is supported per object and the first frame is considered to be the non-moving state.
boundingBoxSetPathThe path to the file containing the object's bounding box set. If no such path is given, the object cannot be checked for collision detection.
startFrameIndexThe index number in the filename of the first file of the animation sequence. The default value is 1. If not loading an animation sequence, this parameter is ignored.

Member Function Documentation

◆ collidesWith() [1/2]

bool small3d::SceneObject::collidesWith ( const glm::vec3  point) const

Check if the object collides with a given point.

Parameters
pointThe point
Returns
True if a collision is detected, False otherwise.

◆ collidesWith() [2/2]

bool small3d::SceneObject::collidesWith ( SceneObject  otherObject) const

Check if the object collides with another given object.

Parameters
otherObjectThe other object.
Returns
True if there is a collision, False if not.

◆ getModel()

Model & small3d::SceneObject::getModel ( )

Get the object's model.

Returns
The object's model

◆ getName()

const std::string small3d::SceneObject::getName ( ) const

Get the name of the object.

Returns
The name of the object

◆ isAnimated()

bool small3d::SceneObject::isAnimated ( ) const

Is this an animated or a static object (is it associated with more than one frames/models)?

Returns
True if animated, False otherwise.

◆ setFrameDelay()

void small3d::SceneObject::setFrameDelay ( const int  delay)

Set the animation speed.

Parameters
delayThe delay between each animation frame, expressed in number of game frames

Member Data Documentation

◆ offset

glm::vec3 small3d::SceneObject::offset

Offset (position) of the object

◆ rotation

glm::vec3 small3d::SceneObject::rotation

Rotation of the object (on x, y, z axes respectively)


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