-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsceneobject.h
More file actions
305 lines (280 loc) · 7.03 KB
/
sceneobject.h
File metadata and controls
305 lines (280 loc) · 7.03 KB
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
#ifndef SCENEOBJECT_H
#define SCENEOBJECT_H
#include <QObject>
#include <QXmlStreamReader>
#include <QVector3D>
#include <QColor>
#include <QMatrix4x4>
#include <spinemlnetworkserver.h>
class sceneTexture;
class sceneObject : public QObject
{
Q_OBJECT
public:
explicit sceneObject(QObject *parent = 0);
~sceneObject();
virtual sceneObject * copy();
// constructor to read from an XML scene description - bool is used to denote an error if set to false
sceneObject(QXmlStreamReader * /* xmlIn */, bool &ok, QObject * parent = 0) {ok = false;}
//~sceneObject() {if (texture) delete texture;}
// default behavior is we don't have a subclass is to say we are not hit
/*!
* \brief isHit
* \return
* Function that checks if the object is hit - if it is then the object stores the hit location so that
* it can be used if a texture request is made (i.e. if the object is the closest hit object)
*/
virtual bool isHit(QVector3D /* ray_loc */, QVector3D /* ray_dir */, float &/* t */) {return false;}
/*!
* \brief setTextureGenerator
* \param texture
* Set the texture generator
*/
void setTextureGenerator (sceneTexture * texture) {this->texture = texture;}
/*!
* \brief getTexture
* \param t
* \return
* Get the texture colour at the last hit location
*/
QColor getTexture(float t, bool lighting);
/*!
* \brief connectObject
* Function to allow the object to connect itself to an input from a model
*/
virtual void connectObject(spineMLNetworkServer *, QString) {return;}
/*!
* \brief getSceneTexture
* \return
* Accessor for texture
*/
sceneTexture * getSceneTexture() {return this->texture;}
QString name;
void debugPrint();
private:
protected:
sceneTexture * texture;
QVector3D location;
QVector3D rotation;
QVector3D scaling;
QVector3D invScaling;
QVector3D lastHit;
float light;
/*!
* \brief vectorToObjectSpace
* \param vect
* \return
* Transform a vector from the object space
*/
QVector3D vectorFromObjectSpace(QVector3D vect) {
QMatrix4x4 m;
m.scale(scaling);
m.rotate(rotation.x(), 1,0,0);
vect = m * vect;
m.setToIdentity();
m.rotate(rotation.y(), 0,1,0);
vect = m * vect;
m.setToIdentity();
m.rotate(rotation.z(), 0,0,1);
vect = m * vect;
m.setToIdentity();
m.translate(location);
vect = m * vect;
return vect;
}
/*!
* \brief vectorToObjectSpaceRS
* \param vect
* \return
* Transform a vector from the object space
*/
QVector3D vectorFromObjectSpaceRS(QVector3D vect) {
QMatrix4x4 m;
m.scale(scaling);
m.rotate(rotation.x(), 1,0,0);
vect = m * vect;
m.setToIdentity();
m.rotate(rotation.y(), 0,1,0);
vect = m * vect;
m.setToIdentity();
m.rotate(rotation.z(), 0,0,1);
//m.translate(location);
vect = m * vect;
return vect;
}
/*!
* \brief vectorFromObjectSpace
* \param vect
* \return
* Transform a vector to the object space
*/
QVector3D vectorToObjectSpace(QVector3D vect) {
QMatrix4x4 m;
m.translate(-location);
vect = m * vect;
m.setToIdentity();
m.rotate(-rotation.z(), 0,0,1);
vect = m * vect;
m.setToIdentity();
m.rotate(-rotation.y(), 0,1,0);
vect = m * vect;
m.setToIdentity();
m.rotate(-rotation.x(), 1,0,0);
vect = m * vect;
m.setToIdentity();
m.scale(invScaling);
vect = m * vect;
return vect;
}
/*!
* \brief vectorFromObjectSpaceRS
* \param vect
* \return
* Transform a vector to the object space
*/
QVector3D vectorToObjectSpaceRS(QVector3D vect) {
QMatrix4x4 m;
//m.translate(-location);
m.rotate(-rotation.z(), 0,0,1);
vect = m * vect;
m.setToIdentity();
m.rotate(-rotation.y(), 0,1,0);
vect = m * vect;
m.setToIdentity();
m.rotate(-rotation.x(), 1,0,0);
vect = m * vect;
m.setToIdentity();
m.scale(invScaling);
vect = m * vect;
return vect;
}
signals:
public slots:
/*!
* \brief setLocationX
* \param x
* Controller input for Location X
*/
void setLocationX(QVector <float> x) {
if (x.size() == 1) {
location.setX(x[0]);
}
}
/*!
* \brief setLocationY
* \param y
* Controller input for Location Y
*/
void setLocationY(QVector <float> y) {
if (y.size() == 1) {
location.setY(y[0]);
}
}
/*!
* \brief setLocationZ
* \param z
* Controller input for Location Z
*/
void setLocationZ(QVector <float> z) {
if (z.size() == 1) {
location.setZ(z[0]);
}
}
/*!
* \brief setLocation
* \param Location
* Controller input for Location
*/
void setLocation(QVector <float> location) {
if (location.size() == 3) {
this->location.setX(location[0]);
this->location.setY(location[1]);
this->location.setZ(location[2]);
}
}
/*!
* \brief setRotationX
* \param x
* Controller input for Rotation X
*/
void setRotationX(QVector <float> x) {
if (x.size() == 1) {
rotation.setX(x[0]);
}
}
/*!
* \brief setRotationY
* \param y
* Controller input for Rotation Y
*/
void setRotationY(QVector <float> y) {
if (y.size() == 1) {
rotation.setY(y[0]);
}
}
/*!
* \brief setRotationZ
* \param z
* Controller input for Rotation Z
*/
void setRotationZ(QVector <float> z) {
if (z.size() == 1) {
rotation.setZ(z[0]);
}
}
/*!
* \brief setRotation
* \param Rotation
* Controller input for Rotation
*/
void setRotation(QVector <float> rotation) {
if (rotation.size() == 3) {
this->rotation.setX(rotation[0]);
this->rotation.setY(rotation[1]);
this->rotation.setZ(rotation[2]);
}
}
/*!
* \brief setScalingX
* \param x
* Controller input for Scaling X
*/
void setScalingX(QVector <float> x) {
if (x.size() == 1) {
scaling.setX(x[0]);
}
}
/*!
* \brief setScalingY
* \param y
* Controller input for Scaling Y
*/
void setScalingY(QVector <float> y) {
if (y.size() == 1) {
scaling.setY(y[0]);
}
}
/*!
* \brief setScalingZ
* \param z
* Controller input for Scaling Z
*/
void setScalingZ(QVector <float> z) {
if (z.size() == 1) {
scaling.setZ(z[0]);
}
}
/*!
* \brief setScaling
* \param Scaling
* Controller input for Scaling
*/
void setScaling(QVector <float> scaling) {
if (scaling.size() == 3) {
this->scaling.setX(scaling[0]);
this->scaling.setY(scaling[1]);
this->scaling.setZ(scaling[2]);
}
}
};
#endif // SCENEOBJECT_H