Code: Select all
void moveTo(IAnimatedMeshSceneNode* node, vector3df finalPosition){
vector3df actualPosition = node->getPosition();
core::vector3df posDiff = finalPosition - actualPosition;
f32 degree = actualPosition.Y;
posDiff.normalize();
if (posDiff.X != 0.0f || posDiff.Z != 0.0f)
degree = atan2(posDiff.X,posDiff.Z) * core::RADTODEG;
node->setRotation(core::vector3df(0,degree,0));
...
}
The other way is this one:
Code: Select all
void moveTo(IAnimatedMeshSceneNode* node, vector3df finalPosition){
core::quaternion qt;
core::quaternion rot = qt.rotationFromTo(actualPosition, finalPosition);
vector3df degrees = rot.getMatrix().getRotationDegrees();
node->setRotation(degrees);
...
}
the positions are like this:
1.350000 0.000000 1.720000
1.340000 0.000000 1.760000
1.340000 0.000000 1.800000
1.370000 0.000000 1.820000
1.390000 0.000000 1.850000
1.390000 0.000000 1.900000
1.390000 0.000000 1.940000
1.420000 0.000000 1.960000
1.430000 0.000000 1.980000
1.440000 0.000000 2.020000
1.430000 0.000000 2.060000
1.450000 0.000000 2.100000
1.460000 0.000000 2.140000
1.490000 0.000000 2.170000
1.530000 0.000000 2.180000
Is there something to solve this problem with quaternions? And someone has a suggestion of how to rotate my node in a smooth way?
thanks in advance.