BasicTutorial4SourceCurrent        
Print
TutorialApplication.h
#ifndef TUTORIALAPPLICATION_H
#define TUTORIALAPPLICATION_H
 
#include "BaseApplication.h"
 
class TutorialApplication : public BaseApplication
{
public:
  TutorialApplication();
  virtual ~TutorialApplication();
protected:
  virtual void createScene();
  virtual bool frameRenderingQueued(const Ogre::FrameEvent& fe);
private:
  bool processUnbufferedInput(const Ogre::FrameEvent& fe);
};
 
 
#endif /* TUTORIALAPPLICATION_H */
TutorialApplication.cpp
#include "TutorialApplication.h"
 
TutorialApplication::TutorialApplication()
{
}
 
TutorialApplication::~TutorialApplication()
{
}
 
void TutorialApplication::createScene()
{
  mSceneMgr->setAmbientLight(Ogre::ColourValue(.25, .25, .25));
 
  Ogre::Light* pointLight = mSceneMgr->createLight("PointLight");
  pointLight->setType(Ogre::Light::LT_POINT);
  pointLight->setPosition(250, 150, 250);
  pointLight->setDiffuseColour(Ogre::ColourValue::White);
  pointLight->setSpecularColour(Ogre::ColourValue::White);
 
  Ogre::Entity* ninjaEntity = mSceneMgr->createEntity("ninja.mesh");
  Ogre::SceneNode* ninjaNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(
    "NinjaNode");
  ninjaNode->attachObject(ninjaEntity);
 
}
 
bool TutorialApplication::frameRenderingQueued(const Ogre::FrameEvent& fe)
{
  bool ret = BaseApplication::frameRenderingQueued(fe);
 
  if (!processUnbufferedInput(fe))
    return false;
 
  return ret;
}
 
bool TutorialApplication::processUnbufferedInput(const Ogre::FrameEvent& fe)
{
  static bool mouseDownLastFrame = false;
  static Ogre::Real toggleTimer = 0.0;
  static Ogre::Real rotate = .13;
  static Ogre::Real move = 250;
 
  // First toggle method
  bool leftMouseDown = mMouse->getMouseState().buttonDown(OIS::MB_Left);
 
  if (leftMouseDown && !mouseDownLastFrame)
  {
    Ogre::Light* light = mSceneMgr->getLight("PointLight");
    light->setVisible(!light->isVisible());
  }
 
  mouseDownLastFrame = leftMouseDown;
 
  // Second toggle method
  toggleTimer -= fe.timeSinceLastFrame;
 
  if ((toggleTimer < 0) && mMouse->getMouseState().buttonDown(OIS::MB_Right))
  {
    toggleTimer = .5;
 
    Ogre::Light* light = mSceneMgr->getLight("PointLight");
    light->setVisible(!light->isVisible());
  }
 
  // Moving the Ninja
  Ogre::Vector3 dirVec = Ogre::Vector3::ZERO;
 
  if (mKeyboard->isKeyDown(OIS::KC_I))
    dirVec.z -= move;
 
  if (mKeyboard->isKeyDown(OIS::KC_K))
    dirVec.z += move;
 
  if (mKeyboard->isKeyDown(OIS::KC_U))
    dirVec.y += move;
 
  if (mKeyboard->isKeyDown(OIS::KC_O))
    dirVec.y -= move;
 
  if (mKeyboard->isKeyDown(OIS::KC_J))
  {
    if (mKeyboard->isKeyDown(OIS::KC_LSHIFT))
      mSceneMgr->getSceneNode("NinjaNode")->yaw(Ogre::Degree(5 * rotate));
    else
      dirVec.x -= move;
  }
 
  if (mKeyboard->isKeyDown(OIS::KC_L))
  {
    if (mKeyboard->isKeyDown(OIS::KC_LSHIFT))
      mSceneMgr->getSceneNode("NinjaNode")->yaw(Ogre::Degree(-5 * rotate));
    else
      dirVec.x += move;
  }
 
  mSceneMgr->getSceneNode("NinjaNode")->translate(
    dirVec * fe.timeSinceLastFrame,
    Ogre::Node::TS_LOCAL);
 
  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
  {
    // Create application object
    TutorialApplication app;
 
    try {
      app.go();
    } catch(Ogre::Exception& e)  {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
      MessageBox(
        NULL, 
        e.getFullDescription().c_str(), 
        "An exception has occurred!", 
        MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
      std::cerr << "An exception has occurred: " <<
	e.getFullDescription().c_str() << std::endl;
#endif
    }
 
    return 0;
  }
 
#ifdef __cplusplus
}
#endif

Contributors to this page: kabbotta41 points  .
Page last modified on Monday 06 of April, 2015 03:19:09 UTC by kabbotta41 points .


The content on this page is licensed under the terms of the Creative Commons Attribution-ShareAlike License.
As an exception, any source code contributed within the content is released into the Public Domain.