reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofNode.h
Go to the documentation of this file.
1
2#pragma once
3
4#include "ofParameter.h"
5#include <glm/gtc/quaternion.hpp>
6#include "ofConstants.h"
7#include "glm/mat4x4.hpp"
8#include <array>
9
10class ofBaseRenderer;
11
13
14class ofNode {
15public:
17
18 ofNode();
19 virtual ~ofNode();
20 ofNode(const ofNode & node);
21 ofNode(ofNode && node);
22 ofNode & operator=(const ofNode & node);
23 ofNode & operator=(ofNode && node);
24
26
29
35 void setParent(ofNode& parent, bool bMaintainGlobalTransform = false);
36
41 void clearParent(bool bMaintainGlobalTransform = false);
42
46 ofNode* getParent() const;
47
51
55 glm::vec3 getPosition() const;
56
60 float getX() const;
61
65 float getY() const;
66
70 float getZ() const;
71
75 glm::vec3 getXAxis() const;
76
80 glm::vec3 getYAxis() const;
81
85 glm::vec3 getZAxis() const;
86
90 glm::vec3 getSideDir() const;
91
95 glm::vec3 getLookAtDir()const;
96
100 glm::vec3 getUpDir() const;
101
102 OF_DEPRECATED_MSG("Use Deg/Rad versions.", float getPitch() const);
103 OF_DEPRECATED_MSG("Use Deg/Rad versions.", float getHeading() const);
104 OF_DEPRECATED_MSG("Use Deg/Rad versions.", float getRoll() const);
105
108 float getPitchDeg() const;
109
112 float getHeadingDeg() const;
113
116 float getRollDeg() const;
117
120 float getPitchRad() const;
121
124 float getHeadingRad() const;
125
128 float getRollRad() const;
129
132 glm::quat getOrientationQuat() const;
133
134 OF_DEPRECATED_MSG("Use the Deg/Rad version.", glm::vec3 getOrientationEuler() const);
135
138 glm::vec3 getOrientationEulerDeg() const;
139
142 glm::vec3 getOrientationEulerRad() const;
143
147 glm::vec3 getScale() const;
148
153 const glm::mat4& getLocalTransformMatrix() const;
154
155 // TODO: optimize and cache these
156 // (parent would need to know about its children so it can inform them
157 // to update their global matrices if it itself transforms)
158
162 glm::mat4 getGlobalTransformMatrix() const;
163
166 glm::vec3 getGlobalPosition() const;
167
170 glm::quat getGlobalOrientation() const;
171
175 glm::vec3 getGlobalScale() const;
176
180
186 void setPosition(float px, float py, float pz);
187
191 void setPosition(const glm::vec3& p);
192
198 void setGlobalPosition(float px, float py, float pz);
199
203 void setGlobalPosition(const glm::vec3& p);
204
208 void setOrientation(const glm::quat& q);
209
215 void setOrientation(const glm::vec3& eulerAngles);
216
220 void setGlobalOrientation(const glm::quat& q);
221
225 void setScale(float s);
226
232 void setScale(float sx, float sy, float sz);
233
237 void setScale(const glm::vec3& s);
238
242
248 void move(float x, float y, float z);
249
252 void move(const glm::vec3& offset);
253
257 void truck(float amount);
258
262 void boom(float amount);
263
267 void dolly(float amount);
268
269 OF_DEPRECATED_MSG("Use the Deg/Rad version.", void tilt(float degrees));
270
274 void tiltDeg(float degrees);
275
279 void tiltRad(float radians);
280
281 OF_DEPRECATED_MSG("Use the Deg/Rad version.", void pan(float degrees));
282
286 void panDeg(float degrees);
287
291 void panRad(float radians);
292
293 OF_DEPRECATED_MSG("Use the Deg/Rad version.", void roll(float degrees));
294
298 void rollDeg(float degrees);
299
303 void rollRad(float radians);
304
308 void rotate(const glm::quat& q);
309
310 OF_DEPRECATED_MSG("Use the Deg/Rad version.", void rotate(float degrees, const glm::vec3& v));
311
316 void rotateDeg(float degrees, const glm::vec3& v);
317
322 void rotateRad(float radians, const glm::vec3& v);
323
324 OF_DEPRECATED_MSG("Use the Deg/Rad version.", void rotate(float degrees, float vx, float vy, float vz));
325
332 void rotateDeg(float degrees, float vx, float vy, float vz);
333
340 void rotateRad(float radians, float vx, float vy, float vz);
341
346 void rotateAround(const glm::quat& q, const glm::vec3& point);
347
348 OF_DEPRECATED_MSG("Use the Deg/Rad version.", void rotateAround(float degrees, const glm::vec3& axis, const glm::vec3& point));
349
355 void rotateAroundDeg(float degrees, const glm::vec3& axis, const glm::vec3& point);
356
362 void rotateAroundRad(float radians, const glm::vec3& axis, const glm::vec3& point);
363
369 void lookAt(const glm::vec3& lookAtPosition);
370
374 void lookAt(const glm::vec3& lookAtPosition, glm::vec3 upVector);
375
378 // \param lookAtNode A reference to the node to look at.
381 void lookAt(const ofNode& lookAtNode);
382
386 void lookAt(const ofNode& lookAtNode, const glm::vec3& upVector);
387
388 OF_DEPRECATED_MSG("Use the Deg/Rad version.", void orbit(float longitude, float latitude, float radius, const glm::vec3& centerPoint = glm::vec3(0, 0, 0)));
389 OF_DEPRECATED_MSG("Use the Deg/Rad version.", void orbit(float longitude, float latitude, float radius, ofNode& centerNode));
390
398 void orbitDeg(float longitude, float latitude, float radius, const glm::vec3& centerPoint = glm::vec3(0, 0, 0));
399
406 void orbitDeg(float longitude, float latitude, float radius, ofNode& centerNode);
407
415 void orbitRad(float longitude, float latitude, float radius, const glm::vec3& centerPoint = glm::vec3(0, 0, 0));
416
423 void orbitRad(float longitude, float latitude, float radius, ofNode& centerNode);
424
428
434 void transformGL(ofBaseRenderer * renderer = nullptr) const;
435
438 void restoreTransformGL(ofBaseRenderer * renderer = nullptr) const;
439
440
442 void resetTransform();
443
447
452 virtual void customDraw(const ofBaseRenderer * renderer) const;
453
457 virtual void customDraw();
458
459
464 virtual void draw() const;
465
467
468protected:
469 void createMatrix();
470 void updateAxis();
471
474 virtual void onPositionChanged() {}
475
478 virtual void onOrientationChanged() {}
479
482 virtual void onScaleChanged() {}
483
484 ofNode * parent = nullptr;
485
486private:
487 void onParentPositionChanged(glm::vec3 & position) {onPositionChanged();}
488 void onParentOrientationChanged(glm::quat & orientation) {onOrientationChanged();}
489 void onParentScaleChanged(glm::vec3 & scale) {onScaleChanged();}
490
491 ofParameter<glm::vec3> position;
492 ofParameter<glm::quat> orientation;
494
495 std::array<glm::vec3,3> axis;
496
497 glm::mat4 localTransformMatrix;
498 bool legacyCustomDrawOverrided;
499 std::set<ofNode*> children;
500
501 void addListener(ofNode & node);
502 void removeListener(ofNode & node);
503// glm::mat4 globalTransformMatrix;
504};
The base renderer interface.
Definition ofGraphicsBaseTypes.h:279
A generic 3d object in space with transformation (position, rotation, scale).
Definition ofNode.h:14
glm::vec3 getUpDir() const
Get direction of node's top aka local y axis, as 3d vector.
Definition ofNode.cpp:496
void panRad(float radians)
Rotate left+right relative to current orientation (around local y axis).
Definition ofNode.cpp:348
OF_DEPRECATED_MSG("Use the Deg/Rad version.", void rotate(float degrees, float vx, float vy, float vz))
float getHeadingDeg() const
Get heading of node, aka the rotation along local y axis.
Definition ofNode.cpp:521
glm::vec3 getZAxis() const
Get the node's local z axis as 3d vector.
Definition ofNode.cpp:481
const glm::mat4 & getLocalTransformMatrix() const
Get node's local transformations (position, orientation, scale).
Definition ofNode.cpp:546
void rollRad(float radians)
Roll left+right relative to current orientation (around local z axis).
Definition ofNode.cpp:353
glm::mat4 getGlobalTransformMatrix() const
Get node's global transformations (position, orientation, scale).
Definition ofNode.cpp:551
glm::vec3 getScale() const
Get local scale of node in xyz axes where 1 is default.
Definition ofNode.cpp:281
float getZ() const
Get node's local z position.
Definition ofNode.cpp:214
virtual void customDraw()
If you extend ofNode and wish to change the way it draws, extend this.
Definition ofNode.cpp:651
glm::quat getGlobalOrientation() const
Get the global orientation of the node as a quaternion.
Definition ofNode.cpp:562
OF_DEPRECATED_MSG("Use the Deg/Rad version.", void orbit(float longitude, float latitude, float radius, ofNode &centerNode))
glm::vec3 getYAxis() const
Get the node's local y axis as 3d vector.
Definition ofNode.cpp:476
void setScale(float s)
Set local uniform scale (x, y, and z are equally scaled).
Definition ofNode.cpp:264
OF_DEPRECATED_MSG("Use Deg/Rad versions.", float getPitch() const)
void setOrientation(const glm::quat &q)
Set local orientation with a quaternion.
Definition ofNode.cpp:219
void tiltDeg(float degrees)
Tilt up+down relative to current orientation (around local x axis).
Definition ofNode.cpp:328
OF_DEPRECATED_MSG("Use the Deg/Rad version.", void roll(float degrees))
ofNode * getParent() const
Get the parent node of this node.
Definition ofNode.cpp:167
virtual void onOrientationChanged()
Classes extending ofNode can override this methods to get notified when the orientation changed.
Definition ofNode.h:478
void setGlobalOrientation(const glm::quat &q)
Set global orientation with a quaternion.
Definition ofNode.cpp:232
OF_DEPRECATED_MSG("Use the Deg/Rad version.", glm::vec3 getOrientationEuler() const)
float getPitchDeg() const
Get pitch of node, aka the rotation along local x axis.
Definition ofNode.cpp:516
OF_DEPRECATED_MSG("Use the Deg/Rad version.", void rotateAround(float degrees, const glm::vec3 &axis, const glm::vec3 &point))
glm::vec3 getGlobalPosition() const
Get node's global position as a 3D vector.
Definition ofNode.cpp:557
void tiltRad(float radians)
Tilt up+down relative to current orientation (around local x axis).
Definition ofNode.cpp:343
void restoreTransformGL(ofBaseRenderer *renderer=nullptr) const
Restore opengl renderer's previous modelview transform matrix.
Definition ofNode.cpp:665
void lookAt(const glm::vec3 &lookAtPosition)
Orient node to look at point (-z axis pointing to global position).
Definition ofNode.cpp:423
void truck(float amount)
Move node left+right relative to current position (in local x axis).
Definition ofNode.cpp:298
OF_DEPRECATED_MSG("Use the Deg/Rad version.", void tilt(float degrees))
void transformGL(ofBaseRenderer *renderer=nullptr) const
Set opengl renderer's modelview matrix to this nodes transform.
Definition ofNode.cpp:656
virtual void draw() const
Draw the node as a white cube with xyz axes.
Definition ofNode.cpp:637
void setPosition(float px, float py, float pz)
Set the local position of the node using xyz coordinates.
Definition ofNode.cpp:172
void setGlobalPosition(float px, float py, float pz)
Set the global position of the node using xyz coordinates.
Definition ofNode.cpp:184
void createMatrix()
Definition ofNode.cpp:673
float getRollDeg() const
Get roll of node, aka the rotation along local z axis.
Definition ofNode.cpp:526
OF_DEPRECATED_MSG("Use Deg/Rad versions.", float getRoll() const)
void orbitDeg(float longitude, float latitude, float radius, const glm::vec3 &centerPoint=glm::vec3(0, 0, 0))
Orbit node around a global position at a specific radius.
Definition ofNode.cpp:589
void move(float x, float y, float z)
Move node by relative amount with xyz coordinates.
Definition ofNode.cpp:286
void dolly(float amount)
Move node backward+forward relative to current position (in local z axis).
Definition ofNode.cpp:308
virtual void onScaleChanged()
Classes extending ofNode can override this methods to get notified when the scale changed.
Definition ofNode.h:482
float getY() const
Get node's local y position.
Definition ofNode.cpp:209
void rotateAroundRad(float radians, const glm::vec3 &axis, const glm::vec3 &point)
Rotate relative to current orientation around arbitrary axis around point.
Definition ofNode.cpp:418
float getRollRad() const
Get roll of node, aka the rotation along local z axis.
Definition ofNode.cpp:541
glm::vec3 getPosition() const
Get node's local position as a 3D vector.
Definition ofNode.cpp:199
glm::vec3 getLookAtDir() const
Get direction the node looks at aka local -z axis, as 3d vector.
Definition ofNode.cpp:491
ofNode * parent
Definition ofNode.h:484
void rotateAround(const glm::quat &q, const glm::vec3 &point)
Rotate relative to current orientation by quaternion around point.
Definition ofNode.cpp:395
OF_DEPRECATED_MSG("Use the Deg/Rad version.", void orbit(float longitude, float latitude, float radius, const glm::vec3 &centerPoint=glm::vec3(0, 0, 0)))
virtual void onPositionChanged()
Classes extending ofNode can override this method to get notified when the position changed.
Definition ofNode.h:474
float getPitchRad() const
Get pitch of node, aka the rotation along local x axis.
Definition ofNode.cpp:531
void clearParent(bool bMaintainGlobalTransform=false)
Remove parent node linking.
Definition ofNode.cpp:148
OF_DEPRECATED_MSG("Use the Deg/Rad version.", void pan(float degrees))
void rotate(const glm::quat &q)
Rotate relative to current orientation by quaternion.
Definition ofNode.cpp:358
glm::quat getOrientationQuat() const
Get the local orientation of the node as a quaternion.
Definition ofNode.cpp:243
void rollDeg(float degrees)
Roll left+right relative to current orientation (around local z axis).
Definition ofNode.cpp:338
OF_DEPRECATED_MSG("Use Deg/Rad versions.", float getHeading() const)
void rotateRad(float radians, const glm::vec3 &v)
Rotate relative to current orientation around arbitrary axis.
Definition ofNode.cpp:375
void rotateAroundDeg(float degrees, const glm::vec3 &axis, const glm::vec3 &point)
Rotate relative to current orientation around arbitrary axis around point.
Definition ofNode.cpp:413
void orbitRad(float longitude, float latitude, float radius, const glm::vec3 &centerPoint=glm::vec3(0, 0, 0))
Orbit node around a global position at a specific radius.
Definition ofNode.cpp:612
void resetTransform()
Reset this node's transformations, position, rotation and scale.
Definition ofNode.cpp:630
void boom(float amount)
Move node up+down relative to current position (in local y axis).
Definition ofNode.cpp:303
void setParent(ofNode &parent, bool bMaintainGlobalTransform=false)
Set parent for the node. The node will inherit transformations from parent.
Definition ofNode.cpp:126
void rotateDeg(float degrees, const glm::vec3 &v)
Rotate relative to current orientation around arbitrary axis.
Definition ofNode.cpp:370
glm::vec3 getSideDir() const
Get direction of node's side aka local x axis, as 3d vector.
Definition ofNode.cpp:486
void panDeg(float degrees)
Rotate left+right relative to current orientation (around local y axis).
Definition ofNode.cpp:333
OF_DEPRECATED_MSG("Use the Deg/Rad version.", void rotate(float degrees, const glm::vec3 &v))
glm::vec3 getGlobalScale() const
Get global scale of node in xyz axes where 1 is default.
Definition ofNode.cpp:568
float getX() const
Get node's local x position.
Definition ofNode.cpp:204
glm::vec3 getOrientationEulerDeg() const
Get local orientation of node in degrees around x, y, and z axes.
Definition ofNode.cpp:253
glm::vec3 getXAxis() const
Get the node's local x axis as 3d vector.
Definition ofNode.cpp:471
float getHeadingRad() const
Get heading of node, aka the rotation along local y axis.
Definition ofNode.cpp:536
glm::vec3 getOrientationEulerRad() const
Get local orientation of node in degrees around x, y, and z axes.
Definition ofNode.cpp:259
void updateAxis()
Definition ofNode.cpp:464
ofParameter holds a value and notifies its listeners when it changes.
Definition ofParameter.h:492
#define px
#define pz
#define py