人物模型走路的问题,是OGRE,SDK里的例子,一段代码不太懂,求教

myj870517 2011-07-17 11:01:52

if (mKeyDirection != Vector3::ZERO && mBaseAnimID != ANIM_DANCE)
{
// calculate actually goal direction in world based on player's key directions
mGoalDirection += mKeyDirection.z * mCameraNode->getOrientation().zAxis();
mGoalDirection += mKeyDirection.x * mCameraNode->getOrientation().xAxis();
mGoalDirection.y = 0;
mGoalDirection.normalise();

Quaternion toGoal = mBodyNode->getOrientation().zAxis().getRotationTo(mGoalDirection);

// calculate how much the character has to turn to face goal direction
Real yawToGoal = toGoal.getYaw().valueDegrees();
// this is how much the character CAN turn this frame
Real yawAtSpeed = yawToGoal / Math::Abs(yawToGoal) * deltaTime * TURN_SPEED;
// reduce "turnability" if we're in midair
if (mBaseAnimID == ANIM_JUMP_LOOP) yawAtSpeed *= 0.2f;

// turn as much as we can, but not more than we need to
if (yawToGoal < 0) yawToGoal = std::min<Real>(0, std::max<Real>(yawToGoal, yawAtSpeed)); //yawToGoal = Math::Clamp<Real>(yawToGoal, yawAtSpeed, 0);
else if (yawToGoal > 0) yawToGoal = std::max<Real>(0, std::min<Real>(yawToGoal, yawAtSpeed)); //yawToGoal = Math::Clamp<Real>(yawToGoal, 0, yawAtSpeed);

mBodyNode->yaw(Degree(yawToGoal));

// move in current body direction (not the goal direction)
mBodyNode->translate(0, 0, deltaTime * RUN_SPEED * mAnims[mBaseAnimID]->getWeight(),
Node::TS_LOCAL);
}

第一第二句是什么意思呢,为什么要和摄像机NODE有关系,zAxis()是什么意思呢
mGoalDirection += mKeyDirection.z * mCameraNode->getOrientation().zAxis();
mGoalDirection += mKeyDirection.x * mCameraNode->getOrientation().xAxis();


如果向下面这样写可以吗
直走
SinbadTranslate += sinbadNode->getLocalAxes() * Ogre::Vector3(0,0,-1);
sinbadNode->translate(SinbadTranslate * evt.timeSinceLastFrame * 50.0f);
转弯
float rotX = CInputManager::GetInstance()->returnMouse()->getMouseState().X.rel * evt.timeSinceLastFrame * -1;
character->turnAround(rotX/5);


...全文
162 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
gamemagic 2011-07-22
  • 打赏
  • 举报
回复
摄像机方向,就是你前进的方向。当然跟摄像机有关
karlson0211 2011-07-21
  • 打赏
  • 举报
回复
帮顶。。

8,324

社区成员

发帖
与我相关
我的任务
社区描述
游戏开发相关内容讨论专区
社区管理员
  • 游戏开发
  • 呆呆敲代码的小Y
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧