这个是摄像机绕食人魔头的一个demo,
其中的关键就在于摄像机的自动绕行 和 摄像机一直朝向食人魔头,
ogre这引擎似乎什么都帮你想到了,很多的函数都已封装好,就怕你找不到
以下的是这个demo关键代码,都是在createscene里的,我给了下具体的解释:
// Make sure the camera track this node
mCamera->setAutoTracking(true, headNode); //
这里让摄像机总是朝着魔头
// Create the camera node & attach camera
SceneNode* camNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
camNode->attachObject(mCamera);
// set up spline animation of node
Animation* anim = mSceneMgr->createAnimation("CameraTrack", 10); //这里的10指代这个摄像机绕一圈要花10秒钟,至于这10秒钟怎么分,在下面关键帧设置中会分配
// Spline it for nice curves
anim->setInterpolationMode(Animation::IM_LINEAR); //设置两点间移动时的插值类型,有线型和弧线型两种,什么效果大家自个试吧
// Create a track to animate the camera's node
//以下就要设置相机绕行的轨迹了
NodeAnimationTrack* track = anim->createNodeTrack(0, camNode);
// Setup keyframes
//关键帧就10帧,这与动画的总时间10刚好对应
TransformKeyFrame* key = track->createNodeKeyFrame(0); // startposition
key = track->createNodeKeyFrame(2.5);
key->setTranslate(Vector3(500,500,-1000));
key = track->createNodeKeyFrame(5);
key->setTranslate(Vector3(-1500,1000,-600));
key = track->createNodeKeyFrame(7.5);
key->setTranslate(Vector3(0,-100,0));
key = track->createNodeKeyFrame(10);
key->setTranslate(Vector3(0,0,0));
// Create a new animation state to track this
mAnimState = mSceneMgr->createAnimationState("CameraTrack");
mAnimState->setEnabled(true);
关键帧设置的那8行代码其实就是说从0~2.5秒 摄像机从起始点移动到(500, 500, -1000),后面几行同理
该demo中的createplane函数还是有点不明白
MeshPtr createPlane(
const String& name, const String& groupName, const Plane& plane,
Real width, Real height,
int xsegments = 1, int ysegments = 1,
bool normals = true, int numTexCoordSets = 1,
Real uTile = 1.0f, Real vTile = 1.0f, //这个tile啥意思啦??????????????????
const Vector3& upVector = Vector3::UNIT_Y,
HardwareBuffer::Usage vertexBufferUsage = HardwareBuffer::HBU_STATIC_WRITE_ONLY,
HardwareBuffer::Usage indexBufferUsage = HardwareBuffer::HBU_STATIC_WRITE_ONLY,
bool vertexShadowBuffer = true, bool indexShadowBuffer = true);
posted on 2008-09-07 20:45
AstaTus 阅读(1087)
评论(0) 编辑 收藏 引用 所属分类:
Ogre