rotate a Ogre Manual Object between two Ogre vectors

240 Views Asked by At

ImageI am working on a rviz plugin project in which I need to move a ogre cube mesh structure between two coordinates.

Here is the code what I have done for this

Ogre::Vector3 src (1,2,3);
Ogre::Vector3 destination(4,5,6);
//manual object
static int count=0;
const std::string& filename="cube.mesh";
Ogre::MeshPtr cube= rviz::loadMeshFromResource(filename);    
std::stringstream str;
str << "cube" << count++;
Ogre::Entity *entity = scene_manager_->createEntity(str.str(),cube);
Ogre::SceneNode* parent_node = scene_manager_->getRootSceneNode();
parent_node ->attachObject(entity);
parent_node ->setPosition((src+destination)/2);   //by doing this the cube passes through mid point
Ogre::Radian angle = src.angleBetween(destination);

//here is some error, 
Ogre::Quaternion angle_x((angle), Ogre::Vector3::UNIT_X);
Ogre::Quaternion angle_y((angle), Ogre::Vector3::UNIT_Y);
Ogre::Quaternion angle_z((angle), Ogre::Vector3::UNIT_Z);
parent_node ->rotate(angle_x*angle_y*angle_z);

However it's not getting aligned between two vectors . Please help.

1

There are 1 best solutions below

2
MBo On

To get direction from src point to destination one, you have to subtract these positions, getting vector.

As far as I understand (know nothing about Ogre), src.angleBetween(destination); gives angular difference between direction from origin to destrination and direction from origin to src. Note it is not angle between "origin to src" and "src to destination" directions.

Moreover, Ogre::Radian angle is scalar value, an angle in radians, you cannot get rotation matrix from this value (matrix needed to align vectors)