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().
Use Case 1: Given the source position (1, 1, 1) with an orientation of (0, 90, 90), and the destination position (0, 0, 0) with an orientation of (0, 90, 90), when the TFormVector(0, 1, 0) command is applied, the expected result is (0, 1, 0).
Use Case 2: Given the source position (1, 1, 1) with an orientation of (0, 90, 90), and the destination position (0, 0, 0) with an orientation of (0, 0, 0), when the TFormVector(0, 1, 0) command is applied, the expected result is (0, 0, -1).
- Assistant
To port Blitz3D's TFormVector function to Ogre 1.7, you can use Ogre's built-in functions to perform the transformation. Here's an implementation of the TFormVector function in Ogre:
cpp - User
do not use actual nodes, use the example values instead so i can test directly.
- Assistant
Apologies for the confusion. Here's the updated code that does not rely on actual nodes:
cppOgre::Vector3 TFormVector(const Ogre::Vector3& sourceVector, const Ogre::Quaternion& sourceOrientation, const Ogre::Vector3& destPosition, const Ogre::Quaternion& destOrientation) { Ogre::Matrix3 sourceRotation = sourceOrientation.toRotationMatrix(); Ogre::Matrix3 destRotation = destOrientation.toRotationMatrix(); Ogre::Matrix3 rotationTransform = destRotation * sourceRotation.Inverse(); Ogre::Vector3 transformedVector = rotationTransform * sourceVector; transformedVector += destPosition - sourcePosition; return transformedVector; }