Neo  0.5.0
Developer Documentation
Object3d.h
Go to the documentation of this file.
1 //========================================================================
2 // Copyright (c) 2003-2011 Anael Seghezzi <www.maratis3d.com>
3 // Copyright (c) 2014-2015 Yannick Pflanzer <www.neo-engine.de>
4 //
5 // This software is provided 'as-is', without any express or implied
6 // warranty. In no event will the authors be held liable for any damages
7 // arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it
11 // freely, subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented; you must not
14 // claim that you wrote the original software. If you use this software
15 // in a product, an acknowledgment in the product documentation would
16 // be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such, and must not
19 // be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source
22 // distribution.
23 //
24 //========================================================================
25 
26 #ifndef __OBJECT3D_H
27 #define __OBJECT3D_H
28 
29 namespace Neo
30 {
31 
43 class NEO_ENGINE_EXPORT Object3d
44 {
45 public:
46 
47  // constructor
48  Object3d(void);
49 
50  // destructor
51  virtual ~Object3d(void);
52 
53  // copy constructor
54  Object3d(const Object3d & object);
55 
56 protected:
57 
60 
63 
66 
69 
72 
74  vector<Object3d*> m_children;
75 
76  // Attributes
77  #if __cplusplus >= 201103L
78  typedef unordered_map<string, NeoVariable>::iterator AttributeIterator ;
79  unordered_map <string, NeoVariable> m_attributes;
80  #else
81  typedef map<string, NeoVariable>::iterator AttributeIterator;
82  map <string, NeoVariable> m_attributes;
83  #endif
84 
85  // properties
86  bool m_isActive;
89 
90  unsigned long m_id;
91 
92  // linking
94 
96  vector <Behavior *> m_behaviors;
97 
98 public:
99  // Definition of some additional data
100  class AdditionalData {};
101 
102 private:
103 
105  AdditionalData* m_additionalData;
106 
110  void removeChild(Object3d* child);
111 
112 protected:
113 
114  void clearObject3d(void);
115 
116 public:
117 
118  AdditionalData* getAdditionalData() { return m_additionalData; }
119  void setAdditionalData(AdditionalData* d) { m_additionalData = d; }
120 
124  void updateMatrix(void);
125 
129  void computeLocalMatrix(void);
130 
136  inline Matrix4x4 * getMatrix(void){ return &m_matrix; }
137 
141  void unlinkChildren(void);
142 
146  void computeChildrenMatrices(void);
147 
153  inline void setAttribute(const char* name, NeoVariable variable)
154  {
155  m_attributes[name] = variable;
156  }
157 
163  inline NeoVariable getAttribute(const char* name)
164  {
165  return m_attributes[name];
166  };
167 
175  Vector3 getUniformRotatedVector(const Vector3 & vector);
176 
182  inline Vector3 getInverseRotatedVector(const Vector3& vector) const
183  {
184  return m_matrix.getInverseRotatedVector3(vector);
185  }
186 
192  inline Vector3 getRotatedVector(const Vector3& vector) const
193  {
194  return m_matrix.getRotatedVector3(vector);
195  }
196 
206  inline Vector3 getInversePosition(const Vector3& position) const
207  {
208  return m_matrix.getInverse() * position;
209  }
210 
219  inline Vector3 getTransformedVector(const Vector3& vector) const
220  {
221  return m_matrix * vector;
222  }
223 
228  void setPosition(const Vector3& position);
229 
239  inline void translate(const Vector3& vec, bool local = false)
240  {
241  m_position += (local ? (vec + getTransformedVector(vec)) : vec);
242  m_needToUpdate = true;
243  }
244 
255  inline void rotate(const Vector3& axis, float angle, bool local = false)
256  {
257  addAxisAngleRotation((local) ? (getInverseRotatedVector(axis)) : axis,
258  angle);
259  }
260 
265  inline Vector3 getTransformedPosition(void) const
266  {
267  return Vector3(m_matrix.entries[12], m_matrix.entries[13],
268  m_matrix.entries[14]);
269  }
270 
275  inline Vector3 getPosition(void) const { return m_position; }
276 
283  void setEulerRotation(const Vector3& euler);
284 
295  void setAxisAngleRotation(const Vector3& axis, float angle);
296 
307  void addAxisAngleRotation(const Vector3& axis, float angle);
308 
314  void setRotation(const Quaternion& rotation);
315 
320  inline Vector3 getTransformedRotation(void) const
321  {
322  return m_matrix.getEulerAngles();
323  }
324 
329  inline Vector3 getEulerRotation(void) const
330  {
331  return m_rotation.getEulerAngles();
332  }
333 
339  inline Quaternion getRotation(void) const { return m_rotation; }
340 
345  void setScale(const Vector3& scale);
346 
351  inline Vector3 getTransformedScale(void) const
352  {
353  return m_matrix.getScale();
354  }
355 
360  inline Vector3 getScale(void) const { return m_scale; }
361 
371  void linkTo(Object3d* parent);
372 
377  void unLink(void);
378 
386  inline void setParent(Object3d* object) { m_parent = object; }
387 
392  inline void addChild(Object3d* child) { m_children.push_back(child); }
393 
398  inline bool hasParent(void) { return (m_parent != NULL); }
399 
404  inline unsigned int getChildrenNumber(void) { return m_children.size(); }
405 
410  inline Object3d* getParent(void) { return m_parent; }
411 
418  inline Object3d* getChild(unsigned int id) { return m_children[id]; }
419 
424  unsigned long getId() { return m_id; }
425 
430  void setId(unsigned long id) { m_id = id; }
431 
435  void updateBehaviors(void);
436 
440  void drawBehaviors(void);
441 
446  void deleteBehavior(unsigned int id);
447 
453  void invertBehavior(unsigned int idA, unsigned int idB);
454 
460  void changeBehavior(unsigned int id, Behavior* behavior);
461 
469  inline void addBehavior(Behavior* behavior)
470  {
471  m_behaviors.push_back(behavior);
472  }
473 
478  inline unsigned int getBehaviorsNumber(void) { return m_behaviors.size(); }
479 
485  inline Behavior* getBehavior(unsigned int id) { return m_behaviors[id]; }
486 
491  inline bool needToUpdate(void) { return m_needToUpdate; }
492 
497  virtual void setActive(bool active) { m_isActive = active; }
498 
503  inline bool isActive(void) { return m_isActive; }
504 
514  inline void setVisible(bool visible) { m_isVisible = visible; }
515 
521  inline bool isVisible(void) { return m_isVisible; }
522 
529  virtual void updateVisibility(OCamera* camera) {}
530 
537  void setName(const char* name);
538 
543  inline const char* getName(void) { return m_name.getSafeString(); }
544 
549  virtual int getType(void) { return OBJECT3D; }
550 
554  virtual void update(void);
555 };
556 }
557 
558 #endif
Definition: Object3d.h:100
Quaternion getRotation(void) const
Returns the rotation of the object.
Definition: Object3d.h:339
Vector3 getRotatedVector3(const Vector3 &vec) const
Definition: Matrix4x4.h:144
Object3d * m_parent
Definition: Object3d.h:93
Vector3 getTransformedScale(void) const
Returns the transformed scale of the object.
Definition: Object3d.h:351
unsigned int getBehaviorsNumber(void)
Returns the number of registered Behaviors.
Definition: Object3d.h:478
bool hasParent(void)
Checks if the object has a parent.
Definition: Object3d.h:398
String m_name
The name of the object.
Definition: Object3d.h:59
Quaternion m_rotation
The rotation.
Definition: Object3d.h:68
virtual void setActive(bool active)
Changes if the object is being active or inactive.
Definition: Object3d.h:497
Behavior * getBehavior(unsigned int id)
Returns the Behavior with the given ID.
Definition: Object3d.h:485
bool m_isActive
Definition: Object3d.h:86
Matrix4x4 * getMatrix(void)
Returns the current matrix.
Definition: Object3d.h:136
Vector3 getTransformedVector(const Vector3 &vector) const
Transforms the given vector using the internal matrix.
Definition: Object3d.h:219
Vector3 getTransformedRotation(void) const
Returns the transformed rotation.
Definition: Object3d.h:320
Matrix4x4 getInverse(void) const
Vector3 getPosition(void) const
Returns the position as a Vector3.
Definition: Object3d.h:275
virtual int getType(void)
Returns the type of the object.
Definition: Object3d.h:549
Vector3 getScale(void) const
vector< Object3d * > m_children
List of children.
Definition: Object3d.h:74
Vector3 getEulerRotation(void) const
Returns the Euler rotation in a Vector3 in degrees.
Definition: Object3d.h:329
Definition: Matrix4x4.h:31
Definition: Vector3.h:31
Vector3 getScale(void) const
Returns the scale of the object.
Definition: Object3d.h:360
Matrix4x4 m_matrix
The matrix.
Definition: Object3d.h:71
Vector3 getInversePosition(const Vector3 &position) const
Multiplies the inverse matrix with the given vector and return the result.
Definition: Object3d.h:206
NeoVariable getAttribute(const char *name)
Returns the value of the attribute variable with the given name.
Definition: Object3d.h:163
Implements a framework for string manipulation that operates directly on C strings.
Definition: NeoString.h:35
void rotate(const Vector3 &axis, float angle, bool local=false)
Rotates the object.
Definition: Object3d.h:255
float entries[16]
Definition: Matrix4x4.h:35
void setVisible(bool visible)
Changes if the object is visible or not.
Definition: Object3d.h:514
void setAdditionalData(AdditionalData *d)
Definition: Object3d.h:119
void setParent(Object3d *object)
Sets the parent object.
Definition: Object3d.h:386
Object3d * getParent(void)
Returns the parent object.
Definition: Object3d.h:410
Definition: NeoEngine.h:44
Vector3 getRotatedVector(const Vector3 &vector) const
Rotates the given vector and returns the result.
Definition: Object3d.h:192
Vector3 getInverseRotatedVector(const Vector3 &vector) const
Calculates the inverse rotated vector.
Definition: Object3d.h:182
vector< Behavior * > m_behaviors
List of behaviors.
Definition: Object3d.h:96
Vector3 getEulerAngles(void) const
unsigned long m_id
Definition: Object3d.h:90
void setAttribute(const char *name, NeoVariable variable)
Sets the value of the attribute with the given name.
Definition: Object3d.h:153
The Object3d class represents a general object in a 3D scene.
Definition: Object3d.h:43
const char * getSafeString(void)
Returns the C string. This method is ensured to return a valid C string and never NULL...
Vector3 getEulerAngles(void) const
map< string, NeoVariable > m_attributes
Definition: Object3d.h:82
void addBehavior(Behavior *behavior)
Adds a new behavior to the list of behaviors.
Definition: Object3d.h:469
const char * getName(void)
Returns the object name.
Definition: Object3d.h:543
void addChild(Object3d *child)
Adds an Object3d to the list of children.
Definition: Object3d.h:392
Object3d * getChild(unsigned int id)
Returns the child with the given ID.
Definition: Object3d.h:418
unordered_map< string, NeoVariable > m_attributes
Definition: Object3d.h:79
void translate(const Vector3 &vec, bool local=false)
Translates the object.
Definition: Object3d.h:239
unsigned long getId()
Returns the ID of the object.
Definition: Object3d.h:424
Vector3 getInverseRotatedVector3(const Vector3 &vec) const
bool m_isVisible
Definition: Object3d.h:87
bool isActive(void)
Checks if the object is active.
Definition: Object3d.h:503
unordered_map< string, NeoVariable >::iterator AttributeIterator
Definition: Object3d.h:78
bool needToUpdate(void)
Checks if the object needs to be updated.
Definition: Object3d.h:491
Vector3 m_scale
The scale.
Definition: Object3d.h:65
Vector3 getTransformedPosition(void) const
Returns the transformed position directly from the internal matrix.
Definition: Object3d.h:265
Definition: OCamera.h:30
void setId(unsigned long id)
Changes the ID of the object.
Definition: Object3d.h:430
unsigned int getChildrenNumber(void)
Returns the number of children.
Definition: Object3d.h:404
Definition: Color.h:29
map< string, NeoVariable >::iterator AttributeIterator
Definition: Object3d.h:81
Vector3 m_position
The positopm.
Definition: Object3d.h:62
Definition: Quaternion.h:31
AdditionalData * getAdditionalData()
Definition: Object3d.h:118
The NeoVariable class defines a variable that can be of any type available in M_VARIABLE_TYPE.
Definition: PointerVariable.h:55
bool m_needToUpdate
Definition: Object3d.h:88
The Behavior class is an abstraction for creating behaviors.
Definition: Behavior.h:39
virtual void updateVisibility(OCamera *camera)
Recalculates visibility for the given camera.
Definition: Object3d.h:529
bool isVisible(void)
Checks if the object is visible.
Definition: Object3d.h:521