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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
#include <Ogre.h>
#include <OIS/OIS.h>
#include <windows.h>
using namespace Ogre;
class Application : public Ogre::FrameListener, public OIS::MouseListener, public OIS::KeyListener
{
public:
Root* pRoot;
RenderWindow* pRenderWindow;
SceneManager* pSceneManager;
Camera* pCamera;
Viewport* pViewport;
OIS::InputManager* pInputManager;
OIS::Mouse *pMouse;
OIS::Keyboard *pKeyboard;
Entity* pEntity;
SceneNode* pNode;
AnimationState* pAnimationState;
public:
Application()
{
pRoot = new Ogre::Root();
if(!pRoot->restoreConfig())
{
if(!pRoot->showConfigDialog())
{
}
}
pRenderWindow=pRoot->initialise(true,"test app 3d");
pSceneManager=pRoot->createSceneManager(ST_GENERIC,"MonGestionnaireDeScene");
pCamera = pSceneManager->createCamera("MaCamera");
pCamera->setPosition(Ogre::Vector3(0,0,300));
pCamera->lookAt(Ogre::Vector3(0,0,0));
pViewport = pRenderWindow->addViewport(pCamera);
OIS::ParamList pl;
size_t windowHnd = 0;
std::ostringstream windowHndStr;
pRenderWindow->getCustomAttribute("WINDOW", &windowHnd);
windowHndStr << windowHnd;
pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
pInputManager = OIS::InputManager::createInputSystem( pl );
//ici
pKeyboard = static_cast<OIS::Keyboard*>(pInputManager->createInputObject(OIS::OISKeyboard, false));
pMouse = static_cast<OIS::Mouse*>(pInputManager->createInputObject(OIS::OISMouse, false));
pMouse->setEventCallback(this);
pKeyboard->setEventCallback(this);
pRoot->addFrameListener(this);
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../media/models","FileSystem","General");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../media/materials/scripts","FileSystem","General");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../media/materials/textures","FileSystem","General");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../media/materials/programs","FileSystem","General");
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
pEntity = pSceneManager->createEntity( "Robot1", "robot.mesh" );
pNode = pSceneManager->getRootSceneNode()->createChildSceneNode("Robot1Node", Vector3(0, -70, 0));
pNode->attachObject(pEntity);
pAnimationState = pEntity->getAnimationState("Idle");
pAnimationState->setEnabled(true);
pAnimationState->setLoop(true);
}
~Application()
{
delete pRoot;
}
void run()
{
pRoot->startRendering();
}
bool frameStarted(const FrameEvent & evt)
{
Sleep(1);
pAnimationState->addTime(evt.timeSinceLastFrame);
if(pMouse)
pMouse->capture();
if (pKeyboard)
pKeyboard->capture();
return true;
}
bool mouseMoved(const OIS::MouseEvent &e)
{
return true;
}
bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
{
return true;
}
bool mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
{
return true;
}
bool keyPressed(const OIS::KeyEvent &e)
{
exit(0);
return true;
}
bool keyReleased(const OIS::KeyEvent &e)
{
return true;
}
bool frameEnded(const FrameEvent& evt)
{
return true;
}
};
#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
{
try
{
Application app;
app.run();
}
catch( Ogre::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().c_str() << std::endl;
#endif
}
return 0;
}
#ifdef __cplusplus
}
#endif |
Partager