I'd like to port Blitz3D's TFormVector function in Ogre 1.7. The function is described…
- User
I'd like to port Blitz3D's TFormVector function in Ogre 1.7.
The function is described as:
TFORMVECTOR(FLOAT X,FLOAT Y,FLOAT Z, SOURCE_ENTITY,DEST_ENTITY) x, y, z = components of a vector in 3d space source_entity = handle of source entity, or 0 for 3d world dest_entity = handle of destination entity, or 0 for 3d world Description Transforms between coordinate systems. After using TFormVector the new components can be read with TFormedX(), TFormedY() and TFormedZ().
For example if:
source is at 1,1,1 and orientation is 0,90,90 dest is at 0,0,0 and orientation is 0,90,90
If the TFormVector xyz is at 0,1,0
the result is 0,1,0
BUT if dest rotation is at 0,0,0
the result is 0,0,-1
Do you get how the computation works?
- Assistant
To port Blitz3D's TFormVector function in Ogre 1.7, you can create a similar function using Ogre's API. Here's an example implementation:
#include <OgreVector3.h> #include <OgreQuaternion.h> Ogre::Vector3 TFormVector(float x, float y, float z, Ogre::SceneNode* sourceEntity, Ogre::SceneNode* destEntity) { Ogre::Vector3 vector(x, y, z); if(sourceEntity) { // Convert vector from source entity's local space to world space vector = sourceEntity->convertLocalToWorldPosition(vector); } if(destEntity) { // Convert vector from world space to dest entity's local space vector = destEntity->convertWorldToLocalPosition(vector); } return vector; }