The small3d library
SceneObject.hpp
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <vector>
13 #include <sstream>
14 #include <iomanip>
15 #include <stdexcept>
16 #include <memory>
17 #include "Model.hpp"
18 #include "Logger.hpp"
19 #include "Image.hpp"
20 #include "BoundingBoxSet.hpp"
21 #include "Math.hpp"
22 #include "File.hpp"
23 
24 namespace small3d
25 {
38  {
39  private:
40  bool skeletal;
41  bool animating;
42  bool repeatAnimation = true;
43  int frameDelay;
44  uint64_t currentPose;
45  int framesWaited;
46  uint64_t getNumPoses();
47  std::string name;
48  Mat4 transformation = Mat4(1);
49  Vec3 rotationXYZ = Vec3(0.0f);
50  bool rotationByMatrix = false;
51  std::vector<std::shared_ptr<Model>> models;
52  std::shared_ptr<BoundingBoxSet> boundingBoxSet = std::shared_ptr<BoundingBoxSet>(new BoundingBoxSet());
53  void init(const std::string& name, const uint32_t boundingBoxSubdivisions);
54  public:
55 
65  SceneObject(const std::string& name, const Model& model, const uint32_t boundingBoxSubdivisions = 0);
66 
76  SceneObject(const std::string& name, const Model&& model, const uint32_t boundingBoxSubdivisions = 0);
77 
78 
88  SceneObject(const std::string& name, const std::vector<std::shared_ptr<Model>>& models, const uint32_t boundingBoxSubdivisions = 0);
89 
93  ~SceneObject() = default;
94 
99  Model& getModel();
100 
105  uint64_t getCurrentPose();
106 
111  void setAnimation(uint32_t animationIdx);
112 
117  std::vector<Model> getBoundingBoxSetModels();
118 
123  std::vector<BoundingBoxSet::extremes>& getBoundingBoxSetExtremes();
124 
129  const std::string getName() const;
130 
134  Vec3 position = Vec3(0.0f, 0.0f, 0.0f);
135 
142  void setRotation(const Vec3& rotation);
143 
149  void rotate(const Vec3& rotation);
150 
157  void setTransformation(const Mat4& rotation);
158 
164  const Vec3 getOrientation() const;
165 
171  const Mat4& getTransformation() const;
172 
180  const Vec3& getRotationXYZ() const;
181 
186  void startAnimating(bool repeat = true);
187 
191  void stopAnimating();
192 
196  void resetAnimation();
197 
203  void setFrameDelay(const int delay);
204 
208  void animate();
209 
218  bool contains(const Vec3& point) const;
219 
230  bool containsCorners(const SceneObject& otherObject) const;
231 
232  friend class Renderer;
233 
234  };
235 
236 }
small3d::SceneObject::getName
const std::string getName() const
Get the name of the object.
Definition: SceneObject.cpp:99
small3d::SceneObject::getTransformation
const Mat4 & getTransformation() const
: Get the tranformation matrix of the object
Definition: SceneObject.cpp:134
Math.hpp
Vectors, matrices and other math things.
small3d::SceneObject::setTransformation
void setTransformation(const Mat4 &rotation)
: Set the transformation matrix of the object. (Overwrites rotation entered via setRotation)
Definition: SceneObject.cpp:123
Model.hpp
A 3D model class.
small3d::SceneObject::~SceneObject
~SceneObject()=default
Destructor.
small3d::SceneObject::getBoundingBoxSetModels
std::vector< Model > getBoundingBoxSetModels()
Get the bounding box set as models (for debug-rendering)
Definition: SceneObject.cpp:91
small3d::Model
A 3D model. It can be loaded from a WavefrontFile or GlbFile. It can also be constructed procedurally...
Definition: Model.hpp:34
small3d::SceneObject::getBoundingBoxSetExtremes
std::vector< BoundingBoxSet::extremes > & getBoundingBoxSetExtremes()
Get the bounding box set extremes (min and max coords)
Definition: SceneObject.cpp:95
BoundingBoxSet.hpp
Bounding boxes for collision detection.
small3d::SceneObject::getOrientation
const Vec3 getOrientation() const
: Get the orientation of the object
Definition: SceneObject.cpp:129
small3d::SceneObject::setFrameDelay
void setFrameDelay(const int delay)
Set the animation speed.
Definition: SceneObject.cpp:160
small3d::SceneObject::SceneObject
SceneObject(const std::string &name, const Model &model, const uint32_t boundingBoxSubdivisions=0)
Model based constructor (skeletal animation)
Definition: SceneObject.cpp:37
small3d::SceneObject::contains
bool contains(const Vec3 &point) const
Check if the bounding boxes of this object contain a given point.
Definition: SceneObject.cpp:180
Image.hpp
Image loading and manipulation.
small3d::SceneObject::containsCorners
bool containsCorners(const SceneObject &otherObject) const
Check if the bounding boxes of this object contain a corner of the bounding boxes of another object.
Definition: SceneObject.cpp:189
small3d::Renderer
Renderer class (OpenGL 3.3 / OpenGL ES 3.0)
Definition: Renderer.hpp:38
small3d::BoundingBoxSet
Set of bounding boxes for a SceneObject, calculated based on the vertices of a Model.
Definition: BoundingBoxSet.hpp:27
small3d::SceneObject::position
Vec3 position
Definition: SceneObject.hpp:134
small3d::SceneObject::getModel
Model & getModel()
Get the object's model.
Definition: SceneObject.cpp:59
small3d::SceneObject::stopAnimating
void stopAnimating()
Stop animating the object.
Definition: SceneObject.cpp:151
File.hpp
File parser virtual class.
small3d::SceneObject::rotate
void rotate(const Vec3 &rotation)
: Modify the rotation of the object
Definition: SceneObject.cpp:111
small3d::SceneObject::setAnimation
void setAnimation(uint32_t animationIdx)
Set the current animation.
Definition: SceneObject.cpp:77
small3d::SceneObject::animate
void animate()
Process animation (progress current frame if necessary)
Definition: SceneObject.cpp:164
small3d
Definition: BinaryFile.hpp:15
small3d::SceneObject::setRotation
void setRotation(const Vec3 &rotation)
: Set the rotation of the object. (Overwrites transformation entered via setTransformation)
Definition: SceneObject.cpp:103
small3d::SceneObject::getCurrentPose
uint64_t getCurrentPose()
Get the current animation pose.
Definition: SceneObject.cpp:68
small3d::SceneObject::getRotationXYZ
const Vec3 & getRotationXYZ() const
: Get the rotation of the object in x, y, z representation. This will NOT work if the rotation was se...
Definition: SceneObject.cpp:138
small3d::Vec3
3 component float vector
Definition: Math.hpp:19
small3d::SceneObject
An object that appears on the 3D scene. It is made up of a Model, together with information for posit...
Definition: SceneObject.hpp:38
small3d::Mat4
4x4 float matrix
Definition: Math.hpp:99
small3d::SceneObject::resetAnimation
void resetAnimation()
Reset the animation sequence (go to the first frame)
Definition: SceneObject.cpp:156
Logger.hpp
Logger used in small3d.
small3d::SceneObject::startAnimating
void startAnimating(bool repeat=true)
Start animating the object.
Definition: SceneObject.cpp:145