source: OGRE/trunk/ogrenew/Samples/SkeletalAnimation/include/SkeletalAnimation.h @ 692

Revision 692, 3.9 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10You may use this sample code for anything you like, it is not covered by the
11LGPL like the rest of the engine.
12-----------------------------------------------------------------------------
13*/
14/*
15-----------------------------------------------------------------------------
16Filename:    SkeletalAnimation.h
17Description: Specialisation of OGRE's framework application to show the
18             skeletal animation feature, including spline animation.
19-----------------------------------------------------------------------------
20*/
21
22
23#include "ExampleApplication.h"
24
25#define NUM_ROBOTS 10
26#define ROW_COUNT 10
27AnimationState* mAnimState[NUM_ROBOTS];
28Real mAnimationSpeed[NUM_ROBOTS];
29
30// Event handler to animate
31class SkeletalAnimationFrameListener : public ExampleFrameListener
32{
33protected:
34public:
35    SkeletalAnimationFrameListener(RenderWindow* win, Camera* cam)
36        : ExampleFrameListener(win, cam)
37    {
38    }
39
40    bool frameStarted(const FrameEvent& evt)
41    {
42        for (int i = 0; i < NUM_ROBOTS; ++i)
43        {
44            mAnimState[i]->addTime(evt.timeSinceLastFrame * mAnimationSpeed[i]);
45        }
46
47        // Call default
48        return ExampleFrameListener::frameStarted(evt);
49
50    }
51};
52
53
54
55class SkeletalApplication : public ExampleApplication
56{
57public:
58    SkeletalApplication() {}
59
60protected:
61
62    // Just override the mandatory create scene method
63    void createScene(void)
64    {
65        // Setup animation default
66        Animation::setDefaultInterpolationMode(Animation::IM_LINEAR);
67        Animation::setDefaultRotationInterpolationMode(Animation::RIM_LINEAR);
68
69        // Set ambient light
70        mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
71
72
73       
74        Entity *ent;
75        int row = 0;
76        int column = 0;
77        for (int i = 0; i < NUM_ROBOTS; ++i, ++column)
78        {
79            if (column > ROW_COUNT)
80            {
81                ++row;
82                column = 0;
83            }
84
85            ent = mSceneMgr->createEntity("robot" + StringConverter::toString(i), "robot.mesh");
86            // Add entity to the scene node
87            mSceneMgr->getRootSceneNode()->createChildSceneNode(
88                Vector3(-(row*100), 0,(column*50)))->attachObject(ent);
89            mAnimState[i] = ent->getAnimationState("Walk");
90            mAnimState[i]->setEnabled(true);
91            mAnimationSpeed[i] = Math::RangeRandom(0.5, 1.5);
92        }
93
94
95
96        // Give it a little ambience with lights
97        Light* l;
98        l = mSceneMgr->createLight("BlueLight");
99        l->setPosition(-200,-80,-100);
100        l->setDiffuseColour(0.5, 0.5, 1.0);
101
102        l = mSceneMgr->createLight("GreenLight");
103        l->setPosition(0,0,-100);
104        l->setDiffuseColour(0.5, 1.0, 0.5);
105
106        // Position the camera
107        mCamera->setPosition(100,50,100);
108        mCamera->lookAt(-50,50,0);
109
110        // Report whether hardware skinning is enabled or not
111        Technique* t = ent->getSubEntity(0)->getMaterial()->getBestTechnique();
112        Pass* p = t->getPass(0);
113        if (p->hasVertexProgram() &&
114            p->getVertexProgram()->isSkeletalAnimationIncluded())
115        {
116            mWindow->setDebugText("Hardware skinning is enabled");
117        }
118        else
119        {
120            mWindow->setDebugText("Software skinning is enabled");
121        }
122
123
124
125
126    }
127
128    // Create new frame listener
129    void createFrameListener(void)
130    {
131        mFrameListener= new SkeletalAnimationFrameListener(mWindow, mCamera);
132        mRoot->addFrameListener(mFrameListener);
133    }
134
135
136};
137
Note: See TracBrowser for help on using the repository browser.