1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
| /*
-----------------------------------------------------------------------------
Filename: CameraTrack.cpp
Description: An example of using AnimationTracks to smoothly make a node
follow a predefined path, with spline interpolation. Also
uses the auto tracking ability of the camera.
-----------------------------------------------------------------------------
*/
#include "ExampleApplication.h"
AnimationState* mAnimState;
// Event handler
class CameraTrackListener: public ExampleFrameListener
{
protected:
public:
CameraTrackListener(RenderWindow* win, Camera* cam)
: ExampleFrameListener(win, cam){}
bool frameRenderingQueued(const FrameEvent& evt)
{
if( ExampleFrameListener::frameRenderingQueued(evt) == false )
return false;
mAnimState->addTime(evt.timeSinceLastFrame);
return true;
}
};
class CameraTrackApplication : public ExampleApplication
{
public:
CameraTrackApplication() {}
~CameraTrackApplication() {}
protected:
SceneNode* mFountainNode;
// Just override the mandatory create scene method
void createScene(void)
{
mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, ;
Light* l = mSceneMgr->createLight("MainLight");
l->setPosition(20,80,50);
Entity *ent;
// Add a head, give it it's own node
SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
ent = mSceneMgr->createEntity("head", "ogrehead.mesh");
headNode->attachObject(ent);
// Make sure the camera track this node
mCamera->setAutoTracking(true, headNode); // La caméra va pointer vers la tête d'Ogre
// Create the camera node & attach camera
SceneNode* camNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
camNode->attachObject(mCamera);
Animation* anim = mSceneMgr->createAnimation("CameraTrack", 10);
// Create a track to animate the camera's node
NodeAnimationTrack* track = anim->createNodeTrack(0, camNode);
// Setup keyframes
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));
// Create a new animation state to track this
mAnimState = mSceneMgr->createAnimationState("CameraTrack");
mAnimState->setEnabled(true);
}
// Create new frame listener
void createFrameListener(void)
{
mFrameListener= new CameraTrackListener(mWindow, mCamera);
mRoot->addFrameListener(mFrameListener);
}
};
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char **argv)
#endif
{
// Create application object
CameraTrackApplication app;
try {
app.go();
} catch( Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
std::cerr << "An exception has occured: " << e.getFullDescription();
#endif
}
return 0;
}
#ifdef __cplusplus
}
#endif |
Partager