when moving a camera, you have to consider two things, 1) the camera’s position in space 2) the camera’s orientation in space. In oF, the camera’s “orientation” is also called its “rotation”.
Positions are usually described as 3D vectors, whereas orientations/rotations are described in quaternions.
Every ofCamera is derived from ofNode, which should give you access to the position and the rotation as follows:
ofVec3f myCamGlobalPosition = myCam.getGlobalPosition();
ofQuaternion myCamRotation = myCam.getGlobalOrientation();
You can move the camera’s position by tweening its position and simultaneously tweening its orientation over time, like so, assuming that your camera is called “myCam”:
// ofCamera myCam;
float tweenvalue = (ofGetElapsedTimeMillis() % 2000) /2000.f; // this will slowly change from 0.0f to 1.0f, resetting every 2 seconds
// we define the camer's start and end orientation here:
startQuat.makeRotate(0, 0, 1, 0); // zero rotation.
targetQuat.makeRotate(90, 0, 1, 0); // rotation 90 degrees around y-axis.
// we define the camer's start and end-position here:
ofQuaternion tweenedCameraQuaternion; // this will be the camera's new rotation.
// calculate the interpolated orientation
tweenedCameraQuaternion.slerp(tweenvalue, startQuat, targetQuat);
ofVec3f lerpPos; //this will hold our tweened position.
// calculate the interpolated values.
lerpPos.x = ofLerp(tweenvalue, startPos.x, targetPos.x);
lerpPos.y = ofLerp(tweenvalue, startPos.y, targetPos.y);
lerpPos.z = ofLerp(tweenvalue, startPos.z, targetPos.z);
// alternative way to calculate interpolated values:
// lerpPos = startPos + ((targetPos-startPos) * tweenvalue);
// now update the camera with the calculated orientation and position.
Note that we use lerp to tween positions and *slerp* for rotations.
“Lerp” is short for linear interpolation, in which a value is scaled linearly, a bit like the in the classic formula y = k*x . If you’d plot the interpolation function as a graph, you’d get a straight line.
“Slerp” on the other hand, is short for ‘spherical linear interpolation’, meaning the quaternion is interpolated along a great circle so that the interpolation graph is following the shortest path between two points on a sphere…