Ogre Camera 相机移动 一种一般移动方式

本文介绍了一种Ogre3D中相机平滑移动的方法,包括围绕世界轴旋转、相机局部旋转和相机朝向点的平滑转移。通过使用平滑插值(smooth step)函数,实现相机从起始位置到目标位置的平滑过渡,同时调整相机的朝向和上方向。代码示例展示了如何初始化和更新相机状态。
摘要由CSDN通过智能技术生成

三个分量的插值,用 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




//当相机从起始位置移动到终止位置后,经过在自身坐标系的旋转(绕朝向方向的轴ÿ

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值