MObject3d

From MaratisWiki
(Difference between revisions)
Jump to: navigation, search
m
 
Line 1: Line 1:
 
{{:classMObject3d}}
 
{{:classMObject3d}}
  
'''MObject3d''' is a base object from which other important objects are derived (e.g. [[MOEntity]], [[MOCamera]], [[MOText]]).
+
==Example==
  
It allows basic operations like translation/rotation, parent/child linking, etc.
+
MObject3d is a base object from which other important objects are derived (e.g. [[MOEntity]], [[MOCamera]], [[MOText]]). It allows basic operations like translation/rotation, parent/child linking, etc.
  
 
All its methods can be called from the derived object:
 
All its methods can be called from the derived object:
 +
 
<pre>
 
<pre>
 
camera->setPosition(MVector3(0,0,0));
 
camera->setPosition(MVector3(0,0,0));
 
</pre>
 
</pre>
This works because [[[[MOCamera]]]] is derived from '''MObject3d''' which has the method ''[[#setPosition|setPosition()]]''.
 
  
Notice the derived objects has the '''O''' in the name for "Object3d" to suggest their base class (e.g. M'''O'''Entity).
+
This works because [[MOCamera]] is derived from '''MObject3d''' which has the method ''[[#setPosition|setPosition()]]''. Notice the derived objects has the '''O''' in the name for "Object3d" to suggest their base class (e.g. M'''O'''Entity).
  
 +
===Position===
  
==Source code==
+
Position simply tells where the object is in space coordinate (X, Y and Z). [[MVector3]] is used to generate specific coordinate:
[http://code.google.com/p/maratis/source/browse/trunk/dev/MSDK/MEngine/Includes/MObject3d.h MObject3d.h]
+
  
[http://code.google.com/p/maratis/source/browse/trunk/dev/MSDK/MEngine/Sources/MObject3d.cpp MObject3d.cpp]
+
  MVector3 pos = MVector3(10,10,10); //pos is a point with coordinate 10,10,10
 +
  camera->setPosition(pos); //a camera object is now set to the coordinates 10,10,10
 +
  player->setPosition(MVector3(50,50,50)); //the player is set explicitly to position 50,50,50
 +
  MVector3 point = camera->getPosition(); //get the position of the camera object and stores it in "point".
  
==API==
+
===Active===
===Matrix===
+
====updateMatrix====
+
[...]
+
====computeLocalMatrix====
+
[...]
+
====getMatrix====
+
[...]
+
  
===Childs===
+
Every object is active by default. If you deactivate it, things like translation/rotation won't be updated in the next frames. More importantly, the linked physics object won't be updated. This means that deactivating an entity can save CPU time.
====unlinkChilds====
+
[...]
+
====computeChildsMatrices====
+
[...]
+
  
===Transform===
+
  entity->setActive(true); //activate the entity
====getUniformRotatedVector====
+
  entity->setActive(false); //deactivate the entity
[...]
+
====getInverseRotatedVector====
+
[...]
+
====getRotatedVector====
+
[...]
+
====getInversePosition====
+
[...]
+
====getTransformedVector====
+
[...]
+
  
===Position===
+
  if(enemy->isActive())
Position simply tells where the object is in space coordinate (X, Y and Z).
+
    //then make "enemy" attack the player
[[MVector3]] is used to generate specific coordinate:
+
<pre>
+
MVector3 pos = MVector3(10,10,10); //pos is a point with coordinate 10,10,10
+
camera->setPosition(pos); //a camera object is now set to the coordinates 10,10,10
+
player->setPosition(MVector3(50,50,50)); //the player is set explicitly to position 50,50,50
+
MVector3 point = camera->getPosition(); //get the position of the camera object and stores it in "point".
+
</pre>
+
====setPosition====
+
Set the position of the object.
+
====getTransformedPosition====
+
[...]
+
====getPosition====
+
Get the position of the object.
+
  
===Rotation===
+
  if(! entity->isActive()) //if the entity is NOT active
====setEulerRotation====
+
    return; //exit this function/method
[...]
+
  //otherwise go on with the code:
====setAxisAngleRotation====
+
  entity->...
[...]
+
====addAxisAngleRotation====
+
[...]
+
====setRotation====
+
[...]
+
====getTransformedRotation====
+
[...]
+
====getEulerRotation====
+
[...]
+
====getRotation====
+
[...]
+
  
===Scale===
+
===Visibility===
====setScale====
+
[...]
+
====getTransformedScale====
+
[...]
+
====getScale====
+
[...]
+
  
===Linking===
 
====linkTo====
 
[...]
 
====unLink====
 
[...]
 
====setParent====
 
[...]
 
====addChild====
 
[...]
 
====hasParent====
 
[...]
 
====getChildsNumber====
 
[...]
 
====getParent====
 
[...]
 
====getChild====
 
[...]
 
 
===Behaviors===
 
====updateBehaviors====
 
[...]
 
====drawBehaviors====
 
[...]
 
====deleteBehavior====
 
[...]
 
====invertBehavior====
 
[...]
 
====changeBehavior====
 
[...]
 
====addBehavior====
 
[...]
 
====getBehaviorsNumber====
 
[...]
 
====getBehavior====
 
[...]
 
 
===Need to update===
 
====needToUpdate====
 
[...]
 
 
===Active===
 
Every object is active by default. If you deactivate it, things like translation/rotation won't be updated in the next frames. More importantly, the linked physics object won't be updated. This means that deactivating an entity can save CPU time.
 
====setActive====
 
<pre>
 
entity->setActive(true); //activate the entity
 
entity->setActive(false); //deactivate the entity
 
</pre>
 
====isActive====
 
<pre>
 
if(enemy->isActive())
 
  //then make "enemy" attack the player
 
</pre>
 
<pre>
 
if(! entity->isActive()) //if the entity is NOT active
 
  return; //exit this function/method
 
//otherwise go on with the code:
 
entity->...
 
</pre>
 
 
===Visibility===
 
 
Invisible objects can still be transformed and have an influence in the scene (e.g. physics).
 
Invisible objects can still be transformed and have an influence in the scene (e.g. physics).
====setVisible====
 
Set the visibility of the object. True or false.
 
====isVisible====
 
Check if the object is visible. True or false.
 
====updateVisibility====
 
[...]
 
 
===Name===
 
====setName====
 
[...]
 
====getName====
 
[...]
 
  
 
===Type===
 
===Type===
====getType====
+
 
 
When you have a pointer to an object but you don't know what the object is (e.g. when looping through a vector of objects), you can use ''getType()''.
 
When you have a pointer to an object but you don't know what the object is (e.g. when looping through a vector of objects), you can use ''getType()''.
  
MObject3D returns the '''M_OBJECT3D''' "identifier", but this is a virtual method which is overrided by the derived objects (e.g. [[MOEntity]], [[MOCamera]]).
+
MObject3D returns the '''M_OBJECT3D''' "identifier", but this is a virtual method which is overrided by the derived objects (e.g.[[MOEntity]], [[MOCamera]]). So in the case of MOEntity, the object will return the '''M_OBJECT3D_ENTITY''' "identifier" so you can tell that you're working with a [[MOEntity]] object.
  
So in the case of MOEntity, the object will return the '''M_OBJECT3D_ENTITY''' "identifier" so you can tell that you're working with a [[MOEntity]] object.
+
  unsigned int size = vector_of_objects.size();
 
+
  for(unsigned int i=0; i<size; i++)
<pre>
+
  {
unsigned int size = vector_of_objects.size();
+
      unsigned int id = (size-1)-i;
for(unsigned int i=0; i<size; i++)
+
      if(vector_of_objects[id]->getType == M_OBJECT3D_ENTITY)
{ unsigned int id = (size-1)-i;
+
      {
if(vector_of_objects[id]->getType == M_OBJECT3D_ENTITY)
+
        printf("I've found an entity!\n");
{ printf("I've found an entity!\n");
+
      }
}
+
  }
}
+
</pre>
+
  
 
The "identifiers" ('''M_OBJECT3D_ENTITY''', '''M_OBJECT3D_CAMERA''', etc.) are macro definitions and are defined in [http://code.google.com/p/maratis/source/browse/trunk/dev/MSDK/MEngine/Includes/MEngine.h MEngine.h]
 
The "identifiers" ('''M_OBJECT3D_ENTITY''', '''M_OBJECT3D_CAMERA''', etc.) are macro definitions and are defined in [http://code.google.com/p/maratis/source/browse/trunk/dev/MSDK/MEngine/Includes/MEngine.h MEngine.h]
  
 
===Update===
 
===Update===
====update====
+
 
 
This virtual method is empty and it will be overrided by the derived objects (e.g. [[MOEntity#update_2|MOEntity::update]]).
 
This virtual method is empty and it will be overrided by the derived objects (e.g. [[MOEntity#update_2|MOEntity::update]]).
 
It's called by [[MScene#update|MScene::update]] for every object.
 
It's called by [[MScene#update|MScene::update]] for every object.
  
 
[[Category:C++ API]]
 
[[Category:C++ API]]

Latest revision as of 11:05, 9 February 2014


Contents

API

MString MObject3d::m_nameNone

MVector3 MObject3d::m_positionNone

MVector3 MObject3d::m_scaleNone

MQuaternion MObject3d::m_rotationNone

MMatrix4x4 MObject3d::m_matrixNone

vector<MObject3d *> MObject3d::m_childsNone

bool MObject3d::m_isActiveNone

bool MObject3d::m_isVisibleNone

bool MObject3d::m_needToUpdateNone

MObject3d* MObject3d::m_parentNone

vector<MBehavior *> MObject3d::m_behaviorsNone

MObject3d::MObject3d(void)

virtual MObject3d::~MObject3d(void)

MObject3d::MObject3d(const MObject3d &object)

void MObject3d::updateMatrix(void)

void MObject3d::computeLocalMatrix(void)

MMatrix4x4* MObject3d::getMatrix(void)

void MObject3d::unlinkChilds(void)

void MObject3d::computeChildsMatrices(void)

MVector3 MObject3d::getUniformRotatedVector(const MVector3 &vector)

MVector3 MObject3d::getInverseRotatedVector(const MVector3 &vector) const

MVector3 MObject3d::getRotatedVector(const MVector3 &vector) const

MVector3 MObject3d::getInversePosition(const MVector3 &position) const

MVector3 MObject3d::getTransformedVector(const MVector3 &vector) const

void MObject3d::setPosition(const MVector3 &position)

MVector3 MObject3d::getTransformedPosition(void) const

MVector3 MObject3d::getPosition(void) const

void MObject3d::setEulerRotation(const MVector3 &euler)

void MObject3d::setAxisAngleRotation(const MVector3 &axis, float angle)

void MObject3d::addAxisAngleRotation(const MVector3 &axis, float angle)

void MObject3d::setRotation(const MQuaternion &rotation)

MVector3 MObject3d::getTransformedRotation(void) const

MVector3 MObject3d::getEulerRotation(void) const

MQuaternion MObject3d::getRotation(void) const

void MObject3d::setScale(const MVector3 &scale)

MVector3 MObject3d::getTransformedScale(void) const

MVector3 MObject3d::getScale(void) const

void MObject3d::linkTo(MObject3d *parent)

void MObject3d::unLink(void)

void MObject3d::setParent(MObject3d *object)

void MObject3d::addChild(MObject3d *child)

bool MObject3d::hasParent(void)

unsigned int MObject3d::getChildsNumber(void)

MObject3d* MObject3d::getParent(void)

MObject3d* MObject3d::getChild(unsigned int id)

void MObject3d::updateBehaviors(void)

void MObject3d::drawBehaviors(void)

void MObject3d::deleteBehavior(unsigned int id)

void MObject3d::invertBehavior(unsigned int idA, unsigned int idB)

void MObject3d::changeBehavior(unsigned int id, MBehavior *behavior)

void MObject3d::addBehavior(MBehavior *behavior)

unsigned int MObject3d::getBehaviorsNumber(void)

MBehavior* MObject3d::getBehavior(unsigned int id)

bool MObject3d::needToUpdate(void)

virtual void MObject3d::setActive(bool active)

bool MObject3d::isActive(void)

void MObject3d::setVisible(bool visible)

bool MObject3d::isVisible(void)

virtual void MObject3d::updateVisibility(MOCamera *camera)

void MObject3d::setName(const char *name)

const char* MObject3d::getName(void)

virtual int MObject3d::getType(void)

virtual void MObject3d::update(void)

void MObject3d::removeChild(MObject3d *child)

void MObject3d::clearObject3d(void)


Example

MObject3d is a base object from which other important objects are derived (e.g. MOEntity, MOCamera, MOText). It allows basic operations like translation/rotation, parent/child linking, etc.

All its methods can be called from the derived object:

camera->setPosition(MVector3(0,0,0));

This works because MOCamera is derived from MObject3d which has the method setPosition(). Notice the derived objects has the O in the name for "Object3d" to suggest their base class (e.g. MOEntity).

Position

Position simply tells where the object is in space coordinate (X, Y and Z). MVector3 is used to generate specific coordinate:

 MVector3 pos = MVector3(10,10,10); //pos is a point with coordinate 10,10,10
 camera->setPosition(pos); //a camera object is now set to the coordinates 10,10,10
 player->setPosition(MVector3(50,50,50)); //the player is set explicitly to position 50,50,50
 MVector3 point = camera->getPosition(); //get the position of the camera object and stores it in "point".

Active

Every object is active by default. If you deactivate it, things like translation/rotation won't be updated in the next frames. More importantly, the linked physics object won't be updated. This means that deactivating an entity can save CPU time.

 entity->setActive(true); //activate the entity
 entity->setActive(false); //deactivate the entity
 if(enemy->isActive())
   //then make "enemy" attack the player
 if(! entity->isActive()) //if the entity is NOT active
   return; //exit this function/method
 //otherwise go on with the code:
 entity->...

Visibility

Invisible objects can still be transformed and have an influence in the scene (e.g. physics).

Type

When you have a pointer to an object but you don't know what the object is (e.g. when looping through a vector of objects), you can use getType().

MObject3D returns the M_OBJECT3D "identifier", but this is a virtual method which is overrided by the derived objects (e.g.MOEntity, MOCamera). So in the case of MOEntity, the object will return the M_OBJECT3D_ENTITY "identifier" so you can tell that you're working with a MOEntity object.

 unsigned int size = vector_of_objects.size();
 for(unsigned int i=0; i<size; i++)
 {	
     unsigned int id = (size-1)-i;
     if(vector_of_objects[id]->getType == M_OBJECT3D_ENTITY)
     {
        printf("I've found an entity!\n");
     }
 }

The "identifiers" (M_OBJECT3D_ENTITY, M_OBJECT3D_CAMERA, etc.) are macro definitions and are defined in MEngine.h

Update

This virtual method is empty and it will be overrided by the derived objects (e.g. MOEntity::update). It's called by MScene::update for every object.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox