I'm trying to get an objects position to extrude from another objects rotation.
The meshes position should be where it faces plus a radius. The only Cartesian coordinate based spherical code on the internet I can find presumes that there are two values (phi and lowercase phi) used to get the point on the sphere.
How do you define "where it faces"? Except for cameras this does not make sense, because the usual scene node does not have a lookat vector. For cameras you just have to take the normalized lookat vector, multiply it by your radius, and add it to the cam's position. Otherwise you can get the lookat vector by defining your "initial facing direction", e.g. (0,0,1), and rotate it by the absolute rotation of the node. Then proceed as before.
getRotation() does not directly tell you where something faces. It tells you the amount that object is rotated on each of its axes. You can use this to get a direction, but that vector is most definitely not a location in 3d space or a direction.
Such a weird name, all I'm trying to do is project a rotation to a 3d position. Wiki has an article about slerp here. One way to solve my problem is to convert my rotation to a quaternion and then slerp it. Spherical linear interpolation sounds much more nerdy.
I'll try it over the weekend, probably Sunday because I'm drinking right now.
// build a rotation matrix from the rotation values
core::matrix4 m;
m.setRotation (rot);
// get a vector that points forward, and rotate it using the matrix
core::vector3df dir (0, 0, 1);
m.rotateVect (dir);
// get a position that is radius units from pos in the direction dir
core::vector3df r (pos);
r += (dir * radius);
I can't thank you enough, I've been working on this problem for the past 4 days. I have been using converting a circle into 3d space above where I want to look at and it looked really tacky, but now the camera movement is smooth and looks great
// to show position of where you are looking
core::vector3df sphereToPosition(core::vector3df rot, const core::vector3df &pos, u32 radius){
// build a rotation matrix from the rotation values
core::matrix4 m;
m.setRotationDegrees (rot);
// rotate the vector using a matrix that points forward
core::vector3df dir (0, 0, 1);
m.rotateVect (dir);
// add the position of the object to the projected radius
core::vector3df r (pos);
r += (dir * radius);
return r;
}