MObject3d

(Difference between revisions)
Jump to: navigation, search
(update)
(Active)
Line 126: Line 126:
 
===Active===
 
===Active===
 
====setActive====
 
====setActive====
[...]
+
<pre>
 +
entity->setActive(true); //activate the entity
 +
entity->setActive(false); //deactivate the entity
 +
</pre>
 
====isActive====
 
====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===
 
===Visibility===

Revision as of 23:56, 21 October 2013

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).


Contents

Source code

MObject3d.h

MObject3d.cpp

API

Matrix

updateMatrix

[...]

computeLocalMatrix

[...]

getMatrix

[...]

Childs

unlinkChilds

[...]

computeChildsMatrices

[...]

Transform

getUniformRotatedVector

[...]

getInverseRotatedVector

[...]

getRotatedVector

[...]

getInversePosition

[...]

getTransformedVector

[...]

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".

setPosition

Set the position of the object.

getTransformedPosition

[...]

getPosition

Get the position of the object.

Rotation

setEulerRotation

[...]

setAxisAngleRotation

[...]

addAxisAngleRotation

[...]

setRotation

[...]

getTransformedRotation

[...]

getEulerRotation

[...]

getRotation

[...]

Scale

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

setActive

entity->setActive(true); //activate the entity
entity->setActive(false); //deactivate the entity

isActive

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).

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

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).

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

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