1 #ifndef __Character_H__ 2 #define __Character_H__ 3 4 #include "SdkSample.h" 5 #include "SinbadCharacterController.h" 6 7 using namespace Ogre; 8 using namespace OgreBites; 9 10 class _OgreSampleClassExport Sample_Character : public SdkSample 11 { 12 public: 13 Sample_Character()14 Sample_Character() 15 { 16 mInfo["Title"] = "Character"; 17 mInfo["Description"] = "A demo showing 3rd-person character control and use of TagPoints."; 18 mInfo["Thumbnail"] = "thumb_char.png"; 19 mInfo["Category"] = "Animation"; 20 mInfo["Help"] = "Use the WASD keys to move Sinbad, and the space bar to jump. " 21 "Use mouse to look around and mouse wheel to zoom. Press Q to take out or put back " 22 "Sinbad's swords. With the swords equipped, you can left click to slice vertically or " 23 "right click to slice horizontally. When the swords are not equipped, press E to " 24 "start/stop a silly dance routine."; 25 } 26 frameRenderingQueued(const FrameEvent & evt)27 bool frameRenderingQueued(const FrameEvent& evt) 28 { 29 // let character update animations and camera 30 mChara->addTime(evt.timeSinceLastFrame); 31 return SdkSample::frameRenderingQueued(evt); 32 } 33 keyPressed(const OIS::KeyEvent & evt)34 bool keyPressed(const OIS::KeyEvent& evt) 35 { 36 // relay input events to character controller 37 if (!mTrayMgr->isDialogVisible()) mChara->injectKeyDown(evt); 38 return SdkSample::keyPressed(evt); 39 } 40 keyReleased(const OIS::KeyEvent & evt)41 bool keyReleased(const OIS::KeyEvent& evt) 42 { 43 // relay input events to character controller 44 if (!mTrayMgr->isDialogVisible()) mChara->injectKeyUp(evt); 45 return SdkSample::keyReleased(evt); 46 } 47 48 #if (OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS) || (OGRE_PLATFORM == OGRE_PLATFORM_ANDROID) touchPressed(const OIS::MultiTouchEvent & evt)49 bool touchPressed(const OIS::MultiTouchEvent& evt) 50 { 51 // relay input events to character controller 52 if (!mTrayMgr->isDialogVisible()) mChara->injectMouseDown(evt); 53 return SdkSample::touchPressed(evt); 54 } 55 touchMoved(const OIS::MultiTouchEvent & evt)56 bool touchMoved(const OIS::MultiTouchEvent& evt) 57 { 58 // relay input events to character controller 59 if (!mTrayMgr->isDialogVisible()) mChara->injectMouseMove(evt); 60 return SdkSample::touchMoved(evt); 61 } 62 #else mouseMoved(const OIS::MouseEvent & evt)63 bool mouseMoved(const OIS::MouseEvent& evt) 64 { 65 // relay input events to character controller 66 if (!mTrayMgr->isDialogVisible()) mChara->injectMouseMove(evt); 67 return SdkSample::mouseMoved(evt); 68 } 69 mousePressed(const OIS::MouseEvent & evt,OIS::MouseButtonID id)70 bool mousePressed(const OIS::MouseEvent& evt, OIS::MouseButtonID id) 71 { 72 // relay input events to character controller 73 if (!mTrayMgr->isDialogVisible()) mChara->injectMouseDown(evt, id); 74 return SdkSample::mousePressed(evt, id); 75 } 76 #endif 77 78 protected: 79 setupContent()80 void setupContent() 81 { 82 // set background and some fog 83 mViewport->setBackgroundColour(ColourValue(1.0f, 1.0f, 0.8f)); 84 mSceneMgr->setFog(Ogre::FOG_LINEAR, ColourValue(1.0f, 1.0f, 0.8f), 0, 15, 100); 85 86 // set shadow properties 87 mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE); 88 mSceneMgr->setShadowColour(ColourValue(0.5, 0.5, 0.5)); 89 mSceneMgr->setShadowTextureSize(1024); 90 mSceneMgr->setShadowTextureCount(1); 91 92 // disable default camera control so the character can do its own 93 mCameraMan->setStyle(CS_MANUAL); 94 95 // use a small amount of ambient lighting 96 mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3)); 97 98 // add a bright light above the scene 99 Light* light = mSceneMgr->createLight(); 100 light->setType(Light::LT_POINT); 101 light->setPosition(-10, 40, 20); 102 light->setSpecularColour(ColourValue::White); 103 104 // create a floor mesh resource 105 MeshManager::getSingleton().createPlane("floor", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, 106 Plane(Vector3::UNIT_Y, 0), 100, 100, 10, 10, true, 1, 10, 10, Vector3::UNIT_Z); 107 108 // create a floor entity, give it a material, and place it at the origin 109 Entity* floor = mSceneMgr->createEntity("Floor", "floor"); 110 floor->setMaterialName("Examples/Rockwall"); 111 floor->setCastShadows(false); 112 mSceneMgr->getRootSceneNode()->attachObject(floor); 113 114 // LogManager::getSingleton().logMessage("creating sinbad"); 115 // create our character controller 116 mChara = new SinbadCharacterController(mCamera); 117 118 // LogManager::getSingleton().logMessage("toggling stats"); 119 mTrayMgr->toggleAdvancedFrameStats(); 120 121 // LogManager::getSingleton().logMessage("creating panel"); 122 StringVector items; 123 items.push_back("Help"); 124 ParamsPanel* help = mTrayMgr->createParamsPanel(TL_TOPLEFT, "HelpMessage", 100, items); 125 help->setParamValue("Help", "H / F1"); 126 127 // LogManager::getSingleton().logMessage("all done"); 128 } 129 cleanupContent()130 void cleanupContent() 131 { 132 // clean up character controller and the floor mesh 133 if (mChara) 134 { 135 delete mChara; 136 mChara = 0; 137 } 138 MeshManager::getSingleton().remove("floor"); 139 } 140 141 SinbadCharacterController* mChara; 142 }; 143 144 #endif 145