-
Notifications
You must be signed in to change notification settings - Fork 5
/
SceneObject.hpp
198 lines (165 loc) · 5.13 KB
/
SceneObject.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
* SceneObject.hpp
*
* Created on: 2014/10/19
* Author: Dimitri Kourkoulis
* http://dimitros.be
* License: BSD 3-Clause License (see LICENSE file)
*/
#pragma once
#include <vector>
#include "Model.hpp"
#include <memory>
#include "Logger.hpp"
#include "Image.hpp"
#include "BoundingBoxes.hpp"
#include <dimitrikourk/glm/glm/glm.hpp>
using namespace std;
namespace small3d
{
/**
* @class SceneObject
*
* @brief 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.
*
*/
class SceneObject
{
private:
vector<Model> model;
bool animating;
int frameDelay;
int currentFrame;
int framesWaited;
int numFrames;
shared_ptr<Image> texture;
string name;
shared_ptr<glm::vec4> colour;
shared_ptr<glm::vec3> offset;
shared_ptr<glm::vec3> rotation;
void initPropVectors();
public:
/**
* Constructor for object with texture
* @param name The name of the object
* @param modelPath The path to the file containing the object's model
* @param texturePath The path to the file containing the object's texture. If the object
* is animated, it has to be the path up to the name part of the model.
* The program will append an underscore, a 6-digit index number and the
* .obj suffix for each frame. (e.g. goatAnim will become goatAnim_000001.obj,
* goatAnim_000002.obj, etc.)
* @param numFrames The 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.
* @param boundingBoxesPath The path to the file containing the object's bounding boxes. If no such
* path is given, the object cannot be checked for collision detection.
*/
SceneObject(const string &name, const string &modelPath,
const int &numFrames = 1, const string &texturePath = "",
const string &boundingBoxesPath = "");
/**
* Destructor
*/
virtual ~SceneObject();
/**
* Get the object's model
* @return The object's model
*/
Model& getModel() ;
/**
* Get the object's texture
* @return The object's texture
*/
const shared_ptr<Image>& getTexture() const;
/**
* Get the name of the object
* @return The name of the object
*/
const string getName();
/**
* Get the object's colour.
* @return The object's colour.
*/
const shared_ptr<glm::vec4>& getColour();
/**
* Set the object's colour. This will only have an effect if the
* object is not textured.
* @param r The red component
* @param g The green component
* @param b The blue component
* @param a The alpha component
*/
void setColour(const float &r, const float &g, const float &b, const float &a);
/**
* Get the offset of the object's position
* @return The offset
*/
const shared_ptr<glm::vec3>& getOffset() const;
/**
* Set the offset of the object's position
* @param x The offset's x coordinate
* @param y The offset's y coordinate
* @param z The offset's z coordinate
*/
void setOffset(const float &x, const float &y, const float &z);
/**
* Get the object's rotation
* @return
*/
const shared_ptr<glm::vec3>& getRotation() const;
/**
* Set the object's rotation
* @param x The orientation's x rotation
* @param y The orientation's y rotation
* @param z The orientation's z rotation
*/
void setRotation(const float &x, const float &y, const float &z);
/**
* Start animating the object
*/
void startAnimating();
/**
* Stop animating the object
*/
void stopAnimating();
/**
* Reset the animation sequence (go to first frame)
*/
void resetAnimation();
/**
* Set the animation speed
* @param delay The delay between each animation frame, expressed in number of game frames
*/
void setFrameDelay(const int &delay);
/**
* Process animation (progress current frame if necessary)
*/
void animate();
/**
* @brief The bounding boxes for the object, used for collision detection.
*/
shared_ptr<BoundingBoxes> boundingBoxes;
/**
* Check if the object collides with a point of the given
* coordinates
*
* @param x The x coordinate of the point
* @param y The y coordinate of the point
* @param z The z coordinate of the point
*
* @return true if a collision is detected, false otherwise.
*/
bool collidesWithPoint(float x, float y, float z);
/**
* @fn bool SceneObject::collidesWithSceneObject(SceneObject otherObject);
*
* @brief Check if the object collides with another given object.
*
* @param otherObject The other object.
*
* @return true if there is a collision, false if not.
*/
bool collidesWithSceneObject(shared_ptr<SceneObject> otherObject);
};
}