三个分量的插值,用 smooth step: x * x * ( 3 - 2 * x ) [0 <= x <= 1]
1:绕世界轴旋转
2:相机自身局部旋转(绕z轴)
3:相机起始和终止时的朝向点间的转移
.cpp文件,代码粗糙,主要看方法
#include "CarCamLookFixedPnt.h"
/*CarCamLookFixedPnt::CarCamLookFixedPnt(Camera* pCCamera, Vector3 &fixedPnt, Vector3 &startPos, Vector3 &startUpDir, Vector3 &endPos, Vector3 &endUpDir, uint16 animationFrames = 20)
:m_pCamera(pCCamera),m_fixedPnt(fixedPnt),m_startPos(startPos),m_startUpDir(startUpDir),m_endPos(endPos),m_endUpDir(endUpDir),m_animFrames(animationFrames)
{
}
*/
CarCamLookFixedPnt::CarCamLookFixedPnt():m_pCamSceneNode(NULL)
{
Math useRandomSeedInMathConstructor; //Math的构造函数里设置了随机种子,可以保证随机函数正确生成随机数
}
CarCamLookFixedPnt::~CarCamLookFixedPnt(void)
{
}
void CarCamLookFixedPnt::init(Camera* pCCamera, const Vector3 &startPos, const Vector3 &startUpDir, const Vector3 &startLookPnt, const Vector3 &endPos, const Vector3 &endUpDir, const Vector3 &endLookPnt, uint16 animationFrames )
{
m_pCamera = pCCamera;
m_pCamSceneNode = m_pCamera->getParentSceneNode();
m_startPos = startPos;
m_startUpDir = adjust_to_perp_up_direction(startLookPnt - startPos, startUpDir);
m_fixedPnt = startLookPnt;
m_endPos = endPos;
m_endUpDir = adjust_to_perp_up_direction(endLookPnt - endPos, endUpDir);
m_endLookPnt = adjust_endLookPnt_to_same_length(endLookPnt);
m_animFrames = animationFrames;
m_worldRotAxis = (startPos - startLookPnt).crossProduct(endPos - endLookPnt); //即起始和终止两个朝向的反向向量的叉积为世界坐标系的旋转轴
m_curFrame = 0; //unsigned
//当相机从起始位置移动到终止位置后,经过在自身坐标系的旋转(绕朝向方向的轴ÿ