這個(gè)是攝像機(jī)繞食人魔頭的一個(gè)demo,
其中的關(guān)鍵就在于攝像機(jī)的自動(dòng)繞行 和 攝像機(jī)一直朝向食人魔頭,
ogre這引擎似乎什么都幫你想到了,很多的函數(shù)都已封裝好,就怕你找不到
以下的是這個(gè)demo關(guān)鍵代碼,都是在createscene里的,我給了下具體的解釋:
// Make sure the camera track this node
mCamera->setAutoTracking(true, headNode); //
這里讓攝像機(jī)總是朝著魔頭

// 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指代這個(gè)攝像機(jī)繞一圈要花10秒鐘,至于這10秒鐘怎么分,在下面關(guān)鍵幀設(shè)置中會(huì)分配

// Spline it for nice curves
anim->setInterpolationMode(Animation::IM_LINEAR); //設(shè)置兩點(diǎn)間移動(dòng)時(shí)的插值類型,有線型和弧線型兩種,什么效果大家自個(gè)試吧
// Create a track to animate the camera's node
//以下就要設(shè)置相機(jī)繞行的軌跡了
NodeAnimationTrack* track = anim->createNodeTrack(0, camNode);
// Setup keyframes
//關(guān)鍵幀就10幀,這與動(dòng)畫的總時(shí)間10剛好對(duì)應(yīng)
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);
關(guān)鍵幀設(shè)置的那8行代碼其實(shí)就是說從0~2.5秒 攝像機(jī)從起始點(diǎn)移動(dòng)到(500, 500, -1000),后面幾行同理
該demo中的createplane函數(shù)還是有點(diǎn)不明白
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, //這個(gè)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 閱讀(1096)
評(píng)論(0) 編輯 收藏 引用 所屬分類:
Ogre