|
From: <xs...@us...> - 2006-05-18 18:59:40
|
Revision: 27 Author: xsdwx Date: 2006-05-18 11:59:36 -0700 (Thu, 18 May 2006) ViewCVS: http://svn.sourceforge.net/perceptioncrash/?rev=27&view=rev Log Message: ----------- Removed Paths: ------------- trunk/perceptioncrash/src/Game.cpp trunk/perceptioncrash/src/Game.hpp trunk/perceptioncrash/src/Input.cpp trunk/perceptioncrash/src/Input.hpp Deleted: trunk/perceptioncrash/src/Game.cpp =================================================================== --- trunk/perceptioncrash/src/Game.cpp 2006-05-18 06:56:47 UTC (rev 26) +++ trunk/perceptioncrash/src/Game.cpp 2006-05-18 18:59:36 UTC (rev 27) @@ -1,87 +0,0 @@ -#include <cmath> - -#include <boost/bind.hpp> - -#include "Game.hpp" - -Game::Game() - : mKeyQuit(Input::getSingleton().createKey("quit", Ogre::KC_ESCAPE)), - mKeyUp(Input::getSingleton().createKey("up", Ogre::KC_W)), - mKeyRight(Input::getSingleton().createKey("right", Ogre::KC_D)), - mKeyDown(Input::getSingleton().createKey("down", Ogre::KC_S)), - mKeyLeft(Input::getSingleton().createKey("left", Ogre::KC_A)) -{ - Input::getSingleton().registerMouseListener(boost::bind(&Game::mouseMotionListener, this, _1,_2)); -} - -void -Game::run() -{ - // This is all temporary stuff - Ogre::ResourceGroupManager rgm = Ogre::ResourceGroupManager::getSingleton(); - rgm.addResourceLocation("data/objects", "FileSystem", "General"); - rgm.addResourceLocation("data/images", "FileSystem", "General"); - rgm.addResourceLocation("data/maps/ogretestmap.zip", "Zip", - rgm.getWorldResourceGroupName()); - - rgm.linkWorldGeometryToResourceGroup(rgm.getWorldResourceGroupName(), - "ogretestmap.bsp", - Graphics::getSingleton().getSceneManagerPtr()); - - rgm.initialiseAllResourceGroups(); - rgm.loadResourceGroup(rgm.getWorldResourceGroupName(), false, true); - - Ogre::ViewPoint vp = Graphics::getSingleton().getSceneManagerPtr()->getSuggestedViewpoint(true); - Graphics::getSingleton().getCameraPtr()->setPosition(vp.position); - Graphics::getSingleton().getCameraPtr()->pitch(Ogre::Degree(90)); - Graphics::getSingleton().getCameraPtr()->rotate(vp.orientation); - Graphics::getSingleton().getCameraPtr()->setFixedYawAxis(true, Ogre::Vector3::UNIT_Z); - - Graphics::getSingleton().getSceneManagerPtr()->setAmbientLight(Ogre::ColourValue(1, 1, 1)); - - Ogre::Entity* myEntity = Graphics::getSingleton().getSceneManagerPtr()->createEntity("Robot1", "robot.mesh"); - Ogre::SceneNode* myNode = Graphics::getSingleton().getSceneManagerPtr()->getRootSceneNode()->createChildSceneNode("Robot1Node"); - myNode->attachObject(myEntity); - - // This is how the real game loop should go - while (!mKeyQuit->isDown()) - { - if (!Graphics::getSingleton().getRootPtr()->_fireFrameStarted()) - break; - - think(); - - Graphics::getSingleton().update(); - - if (!Graphics::getSingleton().getRootPtr()->_fireFrameEnded()) - break; - } -} - -void -Game::think() -{ - if (mKeyUp->isDown()) - { - Graphics::getSingleton().getCameraPtr()->moveRelative(Ogre::Vector3(0, 0, -2)); - } - if (mKeyRight->isDown()) - { - Graphics::getSingleton().getCameraPtr()->moveRelative(Ogre::Vector3(2, 0, 0)); - } - if (mKeyDown->isDown()) - { - Graphics::getSingleton().getCameraPtr()->moveRelative(Ogre::Vector3(0, 0, 2)); - } - if (mKeyLeft->isDown()) - { - Graphics::getSingleton().getCameraPtr()->moveRelative(Ogre::Vector3(-2, 0, 0)); - } -} - -void -Game::mouseMotionListener(Ogre::Real x, Ogre::Real y) -{ - Graphics::getSingleton().getCameraPtr()->yaw(Ogre::Radian(-x * 1.f)); - Graphics::getSingleton().getCameraPtr()->pitch(Ogre::Radian(-y * 1.f)); -} Deleted: trunk/perceptioncrash/src/Game.hpp =================================================================== --- trunk/perceptioncrash/src/Game.hpp 2006-05-18 06:56:47 UTC (rev 26) +++ trunk/perceptioncrash/src/Game.hpp 2006-05-18 18:59:36 UTC (rev 27) @@ -1,31 +0,0 @@ -#ifndef PC_GAME_HPP -#define PC_GAME_HPP - -#include <memory> - -#include <Ogre.h> -#include <OgreEventListeners.h> -#include <OgreKeyEvent.h> - -#include "Graphics.hpp" -#include "Input.hpp" - - -class Game -{ - public: - Game(); - - void run(); - void think(); - void mouseMotionListener(Ogre::Real, Ogre::Real); - - private: - InputKey* mKeyQuit; - InputKey* mKeyUp; - InputKey* mKeyRight; - InputKey* mKeyDown; - InputKey* mKeyLeft; -}; - -#endif /*PC_GAME_HPP*/ Deleted: trunk/perceptioncrash/src/Input.cpp =================================================================== --- trunk/perceptioncrash/src/Input.cpp 2006-05-18 06:56:47 UTC (rev 26) +++ trunk/perceptioncrash/src/Input.cpp 2006-05-18 18:59:36 UTC (rev 27) @@ -1,83 +0,0 @@ -#include "Input.hpp" -#include "Graphics.hpp" - -input::input() - : mEventProcessor(new Ogre::EventProcessor) -{ - mEventProcessor->addKeyListener(this); - mEventProcessor->addMouseMotionListener(this); - mEventProcessor->initialise(Graphics::getSingleton().getWindowPtr()); - mEventProcessor->startProcessingEvents(); -} - -InputKey* -input::createKey(std::string str, int keycode) -{ - if (mKeys.find(str) == mKeys.end()) - return mKeys[str] = new InputKey(keycode); - - return 0; -} - -InputKey* -input::findKey(std::string str) -{ - if (mKeys.find(str) != mKeys.end()) - return mKeys[str]; - - return 0; -} - -void -input::keyClicked(Ogre::KeyEvent* e) -{ - // TODO make some clicked code, probably not needed -} - -void -input::keyPressed(Ogre::KeyEvent* e) -{ - std::map<std::string, InputKey*>::iterator i; - for (i = mKeys.begin(); i != mKeys.end(); ++i) - { - if (e->getKey() == i->second->getKey()) - { - i->second->setDown(); - } - } -} - -void -input::keyReleased(Ogre::KeyEvent* e) -{ - std::map<std::string, InputKey*>::iterator i; - for (i = mKeys.begin(); i != mKeys.end(); ++i) - { - if (e->getKey() == i->second->getKey()) - { - i->second->setDown(false); - } - } -} - -void -input::mouseMoved(Ogre::MouseEvent* e) -{ - std::list<boost::function<void(Ogre::Real, Ogre::Real)> >::iterator i; - for (i = mMouseListeners.begin(); i != mMouseListeners.end(); ++i) - { - (*i) (e->getRelX(), e->getRelY()); - } -} - -void -input::mouseDragged(Ogre::MouseEvent* e) -{ - -} - -void -input::mouseDragMoved(Ogre::MouseEvent* e) -{ - -} Deleted: trunk/perceptioncrash/src/Input.hpp =================================================================== --- trunk/perceptioncrash/src/Input.hpp 2006-05-18 06:56:47 UTC (rev 26) +++ trunk/perceptioncrash/src/Input.hpp 2006-05-18 18:59:36 UTC (rev 27) @@ -1,63 +0,0 @@ -#ifndef PC_INPUT_HPP -#define PC_INPUT_HPP - -#include <map> -#include <list> - -#include <boost/function.hpp> - -#include <Ogre.h> -#include <OgreEventListeners.h> -#include <OgreKeyEvent.h> - -#include "Singleton.hpp" - -class InputKey -{ - public: - InputKey(int key): mKeycode(key), mDown(false) { } - - int getKey() const - { return mKeycode; } - bool isDown() const - { return mDown; } - - void setDown(bool yes = true) - { mDown = yes; } - - private: - int mKeycode; - bool mDown; -}; - -class input : public Ogre::KeyListener, - public Ogre::MouseMotionListener -{ - public: - input(); - - InputKey* createKey(std::string, int); - InputKey* findKey(std::string); - - void keyClicked(Ogre::KeyEvent*); - void keyPressed(Ogre::KeyEvent*); - void keyReleased(Ogre::KeyEvent*); - - void mouseMoved(Ogre::MouseEvent*); - void mouseDragged(Ogre::MouseEvent*); - void mouseDragMoved(Ogre::MouseEvent*); - - void registerMouseListener(boost::function<void(Ogre::Real, Ogre::Real)> m) - { mMouseListeners.push_back(m); } - - private: - std::map<std::string,InputKey*> mKeys; - std::list<boost::function<void(Ogre::Real, Ogre::Real)> > mMouseListeners; - - std::auto_ptr<Ogre::EventProcessor> mEventProcessor; -}; - -typedef - Singleton<input> Input; - -#endif /*PC_INPUT_HPP*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |