here is my entire code...
Code: Select all
#include "ExampleApplication.h"
#include <deque>
using namespace std;
class MoveDemoListener : public ExampleFrameListener
{
public:
MoveDemoListener(RenderWindow* win, Camera* cam, SceneNode *sn, Entity *ent, const deque<Vector3> &walk)
: ExampleFrameListener(win, cam, false, false)
{
// Set default values for variables
mWalkList = walk;
mWalkSpeed = 35.0f;
mEntity = ent;
mNode = sn;
mDirection = Vector3::ZERO;
// Attempt to setup the object to walk around. If no points are
// specified, set an idle animation.
if ( nextLocation() )
{
// Set walking animation
mAnimationState = mEntity->getAnimationState( "Walk" );
mAnimationState->setLoop( true );
mAnimationState->setEnabled( true );
} // if
else
{
// Set idle animation
mAnimationState = mEntity->getAnimationState( "Idle" );
mAnimationState->setLoop( true );
mAnimationState->setEnabled( true );
} // else
} // MoveDemoListener
/* This function is called to start the object moving to the next position
in mWalkList.
*/
bool nextLocation( )
{
if ( mWalkList.empty() )
return false;
mDestination = mWalkList.front( ); // this gets the front of the deque
mWalkList.pop_front( ); // this removes the front of the deque
mDirection = mDestination - mNode->getPosition( );
mDistance = mDirection.normalise( );
// change facing
Vector3 src = mNode->getOrientation( ) * Vector3::UNIT_X;
if ( (1.0f + src.dotProduct( mDirection )) < 0.0001f )
mNode->yaw( Degree(180) );
else
{
Ogre::Quaternion quat = src.getRotationTo( mDirection );
mNode->rotate( quat );
} // else
return true;
} // nextLocation( )
bool frameStarted(const FrameEvent &evt)
{
// Animate the object
mAnimationState->addTime( evt.timeSinceLastFrame );
//*******************************************************************
manuallyControlledBone->yaw(Degree(evt.timeSinceLastFrame*100));
//*******************************************************************
if ( mDirection != Vector3::ZERO )
{
Real move = mWalkSpeed * evt.timeSinceLastFrame;
mDistance -= move;
// If we are very close, just jump to the point
if (mDistance <= 0.0f)
{
mNode->setPosition( mDestination );
mDirection = Vector3::ZERO;
if (! nextLocation( ) )
{
mAnimationState = mEntity->getAnimationState( "Idle" );
mAnimationState->setLoop( true );
mAnimationState->setEnabled( true );
} // if
} // if
// Otherwise, move some some
else
{
mNode->translate( mDirection * move );
} // else
} // if
// Allow the parent class to execute
return ExampleFrameListener::frameStarted(evt);
}
protected:
Real mDistance; // The distance the object has left to travel
Vector3 mDirection; // The direction the object is moving
Vector3 mDestination; // The destination the object is moving towards
Real mWalkSpeed; // The speed at which the object is moving
AnimationState *mAnimationState; // The current animation state of the object
Entity *mEntity; // The Entity we are animating
SceneNode *mNode; // The SceneNode that the Entity is attached to
std::deque<Vector3> mWalkList; // The list of points we are walking to
};
class MoveDemoApplication : public ExampleApplication
{
protected:
public:
MoveDemoApplication()
{
}
~MoveDemoApplication()
{
}
protected:
Entity *mEntity; // The entity of the object we are animating
SceneNode *mNode; // The SceneNode of the object we are moving
std::deque<Vector3> mWalkList; // A deque containing the locations of points we wish to move to
void createScene(void)
{
// Set the default lighting.
mSceneMgr->setAmbientLight( ColourValue( 1.0f, 1.0f, 1.0f ) );
// Create the entity
mEntity = mSceneMgr->createEntity( "Robot", "robot.mesh" );
//********************************************************************
SkeletonInstance* skel = mEntity->getSkeleton();
Bone *manuallyControlledBone = skel->getBone(9);
manuallyControlledBone->setManuallyControlled(true);
Animation* anim = skel->getAnimation("Walk");
anim->destroyTrack(manuallyControlledBone->getHandle());
manuallyControlledBone->yaw(Degree(90));
//********************************************************************
// Create the scene node
mNode = mSceneMgr->getRootSceneNode( )->createChildSceneNode( "RobotNode", Vector3( 0.0f, 0.0f, 25.0f ) );
mNode->attachObject( mEntity );
// Create the walking list
mWalkList.push_back( Vector3( 550.0f, 0.0f, 50.0f ) );
// Create objects so we can see movement
Entity *ent;
SceneNode *node;
ent = mSceneMgr->createEntity( "sphere1", "sphere.mesh" );
node = mSceneMgr->getRootSceneNode( )->createChildSceneNode( "Sphere1Node1", Vector3( 0.0f, -10.0f, 25.0f ) );
node->attachObject( ent );
node->setScale( 0.1f, 0.1f, 0.1f );
ent = mSceneMgr->createEntity( "sphere2", "sphere.mesh" );
node = mSceneMgr->getRootSceneNode( )->createChildSceneNode( "Sphere1Node2", Vector3( 550.0f, -10.0f, 50.0f ) );
node->attachObject( ent );
node->setScale( 0.1f, 0.1f, 0.1f );
// Set the camera to look at our handywork
mCamera->setPosition( 90.0f, 280.0f, 535.0f );
mCamera->pitch( Degree(-30.0f) );
mCamera->yaw( Degree(-15.0f) );
}
void createFrameListener(void)
{
mFrameListener= new MoveDemoListener(mWindow, mCamera, mNode, mEntity, mWalkList);
mFrameListener->showDebugOverlay(true);
mRoot->addFrameListener(mFrameListener);
}
};
#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char **argv)
#endif
{
// Create application object
MoveDemoApplication app;
try {
app.go();
} catch( Exception& e ) {
#if OGRE_PLATFORM == PLATFORM_WIN32
MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
fprintf(stderr, "An exception has occured: %s\n",
e.getFullDescription().c_str());
#endif
}
return 0;
}
Thaks for any help!