From: <me...@us...> - 2009-11-27 22:02:59
|
Revision: 2760 http://ogreaddons.svn.sourceforge.net/ogreaddons/?rev=2760&view=rev Author: melven2 Date: 2009-11-27 22:02:48 +0000 (Fri, 27 Nov 2009) Log Message: ----------- -updated some comments (version number) -added new demo for player controller (it's not finished yet!) Modified Paths: -------------- branches/ogrenewt/newton20/inc/OgreNewt.h Added Paths: ----------- branches/ogrenewt/newton20/demos/Demo09_PlayerController/ branches/ogrenewt/newton20/demos/Demo09_PlayerController/CMakeLists.txt branches/ogrenewt/newton20/demos/Demo09_PlayerController/OgreNewtonApplication.cpp branches/ogrenewt/newton20/demos/Demo09_PlayerController/OgreNewtonApplication.h branches/ogrenewt/newton20/demos/Demo09_PlayerController/OgreNewtonFrameListener.cpp branches/ogrenewt/newton20/demos/Demo09_PlayerController/OgreNewtonFrameListener.h branches/ogrenewt/newton20/demos/Demo09_PlayerController/demo09.cpp Added: branches/ogrenewt/newton20/demos/Demo09_PlayerController/CMakeLists.txt =================================================================== --- branches/ogrenewt/newton20/demos/Demo09_PlayerController/CMakeLists.txt (rev 0) +++ branches/ogrenewt/newton20/demos/Demo09_PlayerController/CMakeLists.txt 2009-11-27 22:02:48 UTC (rev 2760) @@ -0,0 +1,5 @@ +ADD_EXECUTABLE(Demo09_PlayerController demo09.cpp OgreNewtonApplication.cpp OgreNewtonFrameListener.cpp) + +TARGET_LINK_LIBRARIES(Demo09_PlayerController ${OGRE_LIBRARIES} ${CEGUI_LIBRARIES} ${OGRENEWT_LIBRARIES} ${OIS_LIBRARIES} ${CEGUIOGRE_LIBRARIES}) + +#INSTALL(TARGETS Demo09_PlayerController RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/bin) Added: branches/ogrenewt/newton20/demos/Demo09_PlayerController/OgreNewtonApplication.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo09_PlayerController/OgreNewtonApplication.cpp (rev 0) +++ branches/ogrenewt/newton20/demos/Demo09_PlayerController/OgreNewtonApplication.cpp 2009-11-27 22:02:48 UTC (rev 2760) @@ -0,0 +1,258 @@ +/* + OgreNewt library - connecting Ogre and Newton! + + Demo09_PlayerController +*/ +#include "OgreNewtonApplication.h" +#include "OgreNewtonFrameListener.h" + +#include <OgreNewt.h> +#include <OgreNewt_BasicFrameListener.h> + + +OgreNewtonApplication::OgreNewtonApplication(void) +{ + // create OgreNewt world. + m_World = new OgreNewt::World(); + mPlayer = NULL; + + mEntityCount = 0; + +} + +OgreNewtonApplication::~OgreNewtonApplication(void) +{ + // destroy world. + if( mPlayer ) + delete mPlayer; + delete m_World; +} + + + +void OgreNewtonApplication::createScene() +{ + + // setup CEGUI + mGUIRenderer = new CEGUI::OgreCEGUIRenderer( mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mSceneMgr ); + new CEGUI::System( mGUIRenderer ); + + // load up CEGUI stuff... + try + { + using namespace CEGUI; + CEGUI::Logger::getSingleton().setLoggingLevel( CEGUI::Informative ); + + CEGUI::SchemeManager::getSingleton().loadScheme((CEGUI::utf8*)"TaharezLookSkin.scheme"); + CEGUI::System::getSingleton().setDefaultMouseCursor((CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow"); + CEGUI::System::getSingleton().setDefaultFont((CEGUI::utf8*)"BlueHighway-10"); + + CEGUI::Window* sheet = CEGUI::WindowManager::getSingleton().createWindow( (CEGUI::utf8*)"DefaultWindow", (CEGUI::utf8*)"root_wnd" ); + CEGUI::System::getSingleton().setGUISheet( sheet ); + + //makeGUI(); + //setupGUI(); + + } + catch (CEGUI::Exception) + {} + + + // sky box. + mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox"); + + // shadows on! + mSceneMgr->setShadowTechnique( Ogre::SHADOWTYPE_STENCIL_ADDITIVE ); + + + // floor object! + Entity* floor; + SceneNode* floornode; + floor = mSceneMgr->createEntity("Floor", "simple_terrain.mesh" ); + floornode = mSceneMgr->getRootSceneNode()->createChildSceneNode( "FloorNode" ); + floornode->attachObject( floor ); + floor->setMaterialName( "Simple/BeachStones" ); + floor->setCastShadows( false ); + + + + + //Ogre::Vector3 siz(100.0, 10.0, 100.0); + OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floor, true, 0 )); + OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR + delete col; +#endif + + //floornode->setScale( siz ); + bod->attachNode( floornode ); + bod->setPositionOrientation( Ogre::Vector3(0.0,-10.0,0.0), Ogre::Quaternion::IDENTITY ); + + + // make a simple rope. + Ogre::Vector3 size(3,1.0,1.0); + Ogre::Vector3 pos(0,1,0); + Ogre::Quaternion orient = Ogre::Quaternion::IDENTITY; + + // loop through, making bodies and connecting them. + OgreNewt::Body* parent = NULL; + OgreNewt::Body* child = NULL; + + for (int x=0;x<8;x++) + { + // make the next box. + child = makeSimpleBox(size, pos, orient); + + // now make a new joint connecting this to the last box. + OgreNewt::Joint* joint; + + // make the joint right between the bodies... + + + if (parent) + { + joint = new OgreNewt::BasicJoints::BallAndSocket( m_World, child, parent, pos-Ogre::Vector3(size.x/2,0,0) ); + } + else + { + // no parent, this is the first joint, so just pass NULL as the parent, to stick it to the "world" + joint = new OgreNewt::BasicJoints::BallAndSocket( m_World, child, NULL, pos-Ogre::Vector3(size.x/2,0,0) ); + } + + // offset pos a little more. + pos += Ogre::Vector3(size.x,0,0); + + // save the last body for the next loop! + parent = child; + } + + for (int i=0; i<15;i++) + { + pos = Ogre::Vector3( 10-rand()%20, 4+rand()%2, 10-rand()%20 ); + size = Ogre::Vector3( 1+rand()%3, 1+rand()%3, 1+rand()%3 ); + + OgreNewt::Body* bod = makeSimpleBox( size, pos, orient ); + } + + + // player playground + + bod = NULL; + for( int i = 0; i < 20; i++ ) + { + bod = makeSimpleBox( Ogre::Vector3(4.0, 0.4, 1.0), Ogre::Vector3(15.0, -10.0+i*0.4, -2.0-i*0.4), Ogre::Quaternion::IDENTITY); + bod->setMassMatrix(0, Ogre::Vector3::ZERO); + } + + bod = makeSimpleBox( Ogre::Vector3(10.0, 0.4, 10.0), Ogre::Vector3(-17.0, -8.0, -15.0), Ogre::Quaternion(Ogre::Degree(60), Ogre::Vector3::UNIT_X)); + bod->setMassMatrix(0, Ogre::Vector3::ZERO); + + bod = makeSimpleBox( Ogre::Vector3(10.0, 0.4, 10.0), Ogre::Vector3(-27.0, -8.5, -15.0), Ogre::Quaternion(Ogre::Degree(20), Ogre::Vector3::UNIT_X)); + bod->setMassMatrix(0, Ogre::Vector3::ZERO); + + bod = makeSimpleBox( Ogre::Vector3(10.0, 0.4, 10.0), Ogre::Vector3(-37.0, -8.0, -15.0), Ogre::Quaternion(Ogre::Degree(80), Ogre::Vector3::UNIT_Y) * Ogre::Quaternion(Ogre::Degree(50), Ogre::Vector3::UNIT_X)); + bod->setMassMatrix(0, Ogre::Vector3::ZERO); + + makePlayer(); + + + // position camera + mCamera->setPosition(0.0, -3.0, 23.0); + + //make a light + Ogre::Light* light; + + light = mSceneMgr->createLight( "Light1" ); + light->setType( Ogre::Light::LT_POINT ); + light->setPosition( Ogre::Vector3(0.0, 100.0, 100.0) ); + + + +} + + +void OgreNewtonApplication::createFrameListener() +{ + mFrameListener = new OgreNewtonFrameListener( mWindow, mCamera, mSceneMgr, m_World, mPlayer); + mRoot->addFrameListener(mFrameListener); + + mNewtonListener = new OgreNewt::BasicFrameListener( mWindow, m_World, 60 ); + mRoot->addFrameListener(mNewtonListener); +} + +void OgreNewtonApplication::destroyScene() +{ + CEGUI::System* sys = CEGUI::System::getSingletonPtr(); + delete sys; + + // CEGUI Cleanup + delete mGUIRenderer; +} + + +OgreNewt::Body* OgreNewtonApplication::makeSimpleBox( const Ogre::Vector3& size, const Ogre::Vector3& pos, const Ogre::Quaternion& orient ) +{ + Entity* box1; + SceneNode* box1node; + + box1 = mSceneMgr->createEntity( "Entity"+Ogre::StringConverter::toString(mEntityCount++), "box.mesh" ); + box1node = mSceneMgr->getRootSceneNode()->createChildSceneNode(); + box1node->attachObject( box1 ); + box1node->setScale( size ); + + OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( m_World, size, 0 )); + OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); + + + // base mass on the size of the object. + Ogre::Real mass = size.x * size.y * size.z * 2.5; + // calculate the inertia based on box formula and mass + Ogre::Vector3 inertia, offset; + col->calculateInertialMatrix(inertia, offset); + +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR + delete col; +#endif + + bod->attachNode( box1node ); + bod->setMassMatrix( mass, mass*inertia ); + bod->setCenterOfMass(offset); + bod->setStandardForceCallback(); + + box1->setMaterialName( "Simple/BumpyMetal" ); + + + bod->setPositionOrientation( pos, orient ); + + return bod; +} + +void OgreNewtonApplication::makePlayer() +{ + Entity* ellipsoid; + SceneNode* node; + + ellipsoid = mSceneMgr->createEntity( "PlayerControllerEntity", "ellipsoid.mesh"); + node = mSceneMgr->getRootSceneNode()->createChildSceneNode(); + node->attachObject( ellipsoid ); + node->setScale(Ogre::Vector3(1,2.5,1)); + + OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Ellipsoid( m_World, Ogre::Vector3(1,2.5,1), 0 )); + OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); + Ogre::Vector3 inertia, offset; + col->calculateInertialMatrix(inertia, offset); +#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR + delete col; +#endif + bod->attachNode(node); + bod->setMassMatrix( 50, 50*inertia ); + bod->setCenterOfMass(offset); + bod->setStandardForceCallback(); + + ellipsoid->setMaterialName("Simple/dirt01"); + + bod->setPositionOrientation(Ogre::Vector3(0,20,20), Ogre::Quaternion::IDENTITY); + + mPlayer = new OgreNewt::PlayerController(bod, 0.4); +} + Added: branches/ogrenewt/newton20/demos/Demo09_PlayerController/OgreNewtonApplication.h =================================================================== --- branches/ogrenewt/newton20/demos/Demo09_PlayerController/OgreNewtonApplication.h (rev 0) +++ branches/ogrenewt/newton20/demos/Demo09_PlayerController/OgreNewtonApplication.h 2009-11-27 22:02:48 UTC (rev 2760) @@ -0,0 +1,47 @@ +#pragma once + + +#include <ExampleApplication.h> +#include <OgreNewt.h> + +// CEGUI has issues with the Ogre memory manager, this seems to fix it for now. +//#include <OgreNoMemoryMacros.h> +#include <CEGUI/CEGUI.h> +//#include <OgreMemoryMacros.h> + + +#include <OgreCEGUIRenderer.h> +#include <OgreCEGUIResourceProvider.h> + + + + +class OgreNewtonApplication : + public ExampleApplication +{ +public: + OgreNewtonApplication(void); + ~OgreNewtonApplication(void); + +protected: + void createFrameListener(); + void createScene(); + + void destroyScene(); + + // our custom function to simplify making simpe dynamics rigid body boxes. + OgreNewt::Body* makeSimpleBox( const Ogre::Vector3& size, const Ogre::Vector3& pos, const Ogre::Quaternion& orient ); + + void makePlayer(); + +private: + OgreNewt::World* m_World; + OgreNewt::PlayerController *mPlayer; + + Ogre::FrameListener* mNewtonListener; + + int mEntityCount; + + CEGUI::OgreCEGUIRenderer* mGUIRenderer; +}; + Added: branches/ogrenewt/newton20/demos/Demo09_PlayerController/OgreNewtonFrameListener.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo09_PlayerController/OgreNewtonFrameListener.cpp (rev 0) +++ branches/ogrenewt/newton20/demos/Demo09_PlayerController/OgreNewtonFrameListener.cpp 2009-11-27 22:02:48 UTC (rev 2760) @@ -0,0 +1,78 @@ +#include "OgreNewtonFrameListener.h" + + +//#include <OgreNoMemoryMacros.h> +#include <CEGUI/CEGUI.h> +//#include <OgreMemoryMacros.h> + + +OgreNewtonFrameListener::OgreNewtonFrameListener(RenderWindow* win, Camera* cam, SceneManager* mgr, OgreNewt::World* W, OgreNewt::PlayerController *player) : + ExampleFrameListener(win,cam) +{ + m_World = W; + mSceneMgr = mgr; + mPlayer = player; + + OgreNewt::Debugger &debug(m_World->getDebugger()); + debug.init(mgr); +} + +OgreNewtonFrameListener::~OgreNewtonFrameListener(void) +{ +} + +bool OgreNewtonFrameListener::frameStarted(const FrameEvent &evt) +{ + mKeyboard->capture(); + mMouse->capture(); + + + + // player movement uhjk zi + Ogre::Real forwardSpeed, sideSpeed; + Ogre::Radian heading; + mPlayer->getVelocity(forwardSpeed, sideSpeed, heading); + forwardSpeed = 0; + sideSpeed = 0; + if(mKeyboard->isKeyDown(OIS::KC_U)) + forwardSpeed += 6.0; + if(mKeyboard->isKeyDown(OIS::KC_J)) + forwardSpeed -= 5.0; + if(mKeyboard->isKeyDown(OIS::KC_H)) + sideSpeed -= 5.0; + if(mKeyboard->isKeyDown(OIS::KC_K)) + sideSpeed += 5.0; + if(mKeyboard->isKeyDown(OIS::KC_Z)) + heading += Degree(90)/60.0; + if(mKeyboard->isKeyDown(OIS::KC_I)) + heading -= Degree(90)/60.0; + + mPlayer->setVelocity(forwardSpeed, sideSpeed, heading); + + + OgreNewt::Debugger& debug(m_World->getDebugger()); + if (mKeyboard->isKeyDown(OIS::KC_F3)) + { + debug.startRaycastRecording(); + debug.clearRaycastsRecorded(); + debug.showDebugInformation(); + } + else + { + debug.clearRaycastsRecorded(); + debug.stopRaycastRecording(); + debug.hideDebugInformation(); + } + + + + if (mKeyboard->isKeyDown(OIS::KC_T)) + m_World->setThreadCount( m_World->getThreadCount() % 2 + 1); + + + if (mKeyboard->isKeyDown(OIS::KC_ESCAPE)) + return false; + + return true; +} + Added: branches/ogrenewt/newton20/demos/Demo09_PlayerController/OgreNewtonFrameListener.h =================================================================== --- branches/ogrenewt/newton20/demos/Demo09_PlayerController/OgreNewtonFrameListener.h (rev 0) +++ branches/ogrenewt/newton20/demos/Demo09_PlayerController/OgreNewtonFrameListener.h 2009-11-27 22:02:48 UTC (rev 2760) @@ -0,0 +1,69 @@ +#pragma once +#include "ExampleFrameListener.h" +#include <OgreNewt.h> +#include <OIS.h> +#include <CEGUI.h> + + +class OgreNewtonFrameListener : + public ExampleFrameListener, + public OIS::KeyListener, + public OIS::MouseListener +{ +protected: + OgreNewt::World* m_World; + SceneManager* mSceneMgr; + int count; + OgreNewt::PlayerController* mPlayer; +public: + OgreNewtonFrameListener(RenderWindow* win, Camera* cam, SceneManager* mgr, OgreNewt::World* W, OgreNewt::PlayerController* player); + ~OgreNewtonFrameListener(void); + + bool frameStarted(const FrameEvent &evt); + + bool mouseMoved (const OIS::MouseEvent &e) + { + CEGUI::System::getSingleton().injectMouseMove( e.state.X.rel, e.state.Y.rel ); + return true; + } + + bool keyPressed( const OIS::KeyEvent &arg ) + { + CEGUI::System::getSingleton().injectKeyDown( arg.key ); + CEGUI::System::getSingleton().injectChar( arg.text ); + return true; + } + + bool keyReleased( const OIS::KeyEvent &arg ) + { + CEGUI::System::getSingleton().injectKeyUp( arg.key ); + return true; + } + + bool mousePressed (const OIS::MouseEvent &e, OIS::MouseButtonID id) + { + CEGUI::System::getSingleton().injectMouseButtonDown(convertOISMouseButtonToCegui(id)); + return true; + } + + bool mouseReleased (const OIS::MouseEvent &e, OIS::MouseButtonID id) + { + CEGUI::System::getSingleton().injectMouseButtonUp(convertOISMouseButtonToCegui(id)); + return true; + } + +protected: + CEGUI::MouseButton convertOISMouseButtonToCegui(int id) + { + switch (id) + { + case 0: return CEGUI::LeftButton; + case 1: return CEGUI::RightButton; + case 2: return CEGUI::MiddleButton; + case 3: return CEGUI::X1Button; + default: return CEGUI::LeftButton; + } + + } +}; + Added: branches/ogrenewt/newton20/demos/Demo09_PlayerController/demo09.cpp =================================================================== --- branches/ogrenewt/newton20/demos/Demo09_PlayerController/demo09.cpp (rev 0) +++ branches/ogrenewt/newton20/demos/Demo09_PlayerController/demo09.cpp 2009-11-27 22:02:48 UTC (rev 2760) @@ -0,0 +1,33 @@ + +/* + Demo09_PlayerController + + by melven +*/ + +#ifdef WIN32 +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#endif + +#include "OgreNewtonApplication.h" + + +#ifdef WIN32 +INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT ) +#else +int main(int argc, char**argv) +#endif +{ + // Create application object + OgreNewtonApplication app; + + try { + app.go(); + } catch( Ogre::Exception& e ) { + printf( "An Error HAS OCCURED: %s", e.getFullDescription().c_str() ); + } + + return 0; +} + Modified: branches/ogrenewt/newton20/inc/OgreNewt.h =================================================================== --- branches/ogrenewt/newton20/inc/OgreNewt.h 2009-11-27 21:57:51 UTC (rev 2759) +++ branches/ogrenewt/newton20/inc/OgreNewt.h 2009-11-27 22:02:48 UTC (rev 2760) @@ -9,9 +9,9 @@ main header file. - current version: 2.07.0 + current version: 2.07.1 - Newton version: 2.07 (beta) + Newton version: at least 2.07 (beta) Ogre version: Shoggoth (1.6.x) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |