The small3d library
Tiny C++ 3D game development library for Win/MacOS/Linux/FreeBSD
Loading...
Searching...
No Matches
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
24namespace 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}
Bounding boxes for collision detection.
File parser virtual class.
Image loading and manipulation.
Logger used in small3d.
Vectors, matrices and other math things.
A 3D model class.
Set of bounding boxes for a SceneObject, calculated based on the vertices of a Model.
Definition BoundingBoxSet.hpp:27
A 3D model. It can be loaded from a WavefrontFile or GlbFile. It can also be constructed procedurally...
Definition Model.hpp:34
Renderer class (OpenGL 3.3 / OpenGL ES 3.0)
Definition Renderer.hpp:34
An object that appears on the 3D scene. It is made up of a Model, together with information for posit...
Definition SceneObject.hpp:38
void stopAnimating()
Stop animating the object.
Definition SceneObject.cpp:151
void animate()
Process animation (progress current frame if necessary)
Definition SceneObject.cpp:164
const std::string & getName() const
Get the name of the object.
Definition SceneObject.cpp:99
std::vector< Model > getBoundingBoxSetModels()
Get the bounding box set as models (for debug-rendering)
Definition SceneObject.cpp:91
std::vector< BoundingBoxSet::extremes > & getBoundingBoxSetExtremes()
Get the bounding box set extremes (min and max coords)
Definition SceneObject.cpp:95
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
void resetAnimation()
Reset the animation sequence (go to the first frame)
Definition SceneObject.cpp:156
void setRotation(const Vec3 &rotation)
: Set the rotation of the object. (Overwrites transformation entered via setTransformation)
Definition SceneObject.cpp:103
~SceneObject()=default
Destructor.
uint64_t getCurrentPose()
Get the current animation pose.
Definition SceneObject.cpp:68
void rotate(const Vec3 &rotation)
: Modify the rotation of the object
Definition SceneObject.cpp:111
Model & getModel()
Get the object's model.
Definition SceneObject.cpp:59
Vec3 position
Definition SceneObject.hpp:134
void startAnimating(bool repeat=true)
Start animating the object.
Definition SceneObject.cpp:145
const Mat4 & getTransformation() const
: Get the tranformation matrix of the object
Definition SceneObject.cpp:134
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
void setAnimation(uint32_t animationIdx)
Set the current animation.
Definition SceneObject.cpp:77
void setFrameDelay(const int delay)
Set the animation speed.
Definition SceneObject.cpp:160
void setTransformation(const Mat4 &rotation)
: Set the transformation matrix of the object. (Overwrites rotation entered via setRotation)
Definition SceneObject.cpp:123
SceneObject(const std::string &name, const Model &model, const uint32_t boundingBoxSubdivisions=0)
Model based constructor (skeletal animation)
Definition SceneObject.cpp:37
const Vec3 getOrientation() const
: Get the orientation of the object
Definition SceneObject.cpp:129
bool contains(const Vec3 &point) const
Check if the bounding boxes of this object contain a given point.
Definition SceneObject.cpp:180
Definition BinaryFile.hpp:15
4x4 float matrix
Definition Math.hpp:112
3 component float vector
Definition Math.hpp:21