這個是攝像機繞食人魔頭的一個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 閱讀(1096)
評論(0) 編輯 收藏 引用 所屬分類:
Ogre