| Both sides previous revisionPrevious revisionNext revision | Previous revision |
| public:t-gede-14-1:lab9 [2015/03/19 07:49] – [LAB9: Physics (Optional)] marino | public:t-gede-14-1:lab9 [2024/04/29 13:33] (current) – external edit 127.0.0.1 |
|---|
| You can use your own project or start fresh with the base application {{:public:t-gede-14-1:lab6_handout.7z|code}} | You can use your own project or start fresh with the base application {{:public:t-gede-14-1:lab6_handout.7z|code}} |
| |
| ===== Lab ===== | ===== Bullet ===== |
| - Setup Project. | - Setup Bullet Project. |
| - Downlaod [[https://code.google.com/p/bullet/downloads/detail?name=bullet-2.82-r2704.zip&can=2&q=|Bullet]] | - Downlaod [[https://github.com/bulletphysics/bullet3/releases|Bullet]] I recommend downloading the 2.83 version. If you want to test something else, that is fine, I just haven't tested that with the following code. |
| - Build Bullet | - Build Bullet |
| - Run <bullet root>\build\vs2010.bat to generate the VS 2010 project files. | - Run <bullet root>\build\vs2010.bat to generate the VS 2010 project files. |
| - Change the C/C++->Code Generation->Runtime Library to Multi Threaded DLL (/MDd (Debug) and /MD (Release)) | - Change the C/C++->Code Generation->Runtime Library to Multi Threaded DLL (/MDd (Debug) and /MD (Release)) |
| - Build the solution for debug and release. | - Build the solution for debug and release. |
| | |
| | ===== Lab ===== |
| | And now for the Ogre project. |
| - **Add** ''<Bullet Root>\lib;'' to ''Linker->General->Additional Library Directories'' (Debug and Release) | - **Add** ''<Bullet Root>\lib;'' to ''Linker->General->Additional Library Directories'' (Debug and Release) |
| - **Add** ''<Bullet Root>\src;'' to ''C++->General->Additional Include Directories'' (Debug and Release) | - **Add** ''<Bullet Root>\src;'' to ''C++->General->Additional Include Directories'' (Debug and Release) |
| |
| </code> | </code> |
| - **Create a pointer** to physics in your Application, and initialize it in the startup function. | - **Create a pointer** to physics in your Application, and initialize it in the startup function.<code|cpp> _physicsEngine = new Physics(); |
| | _physicsEngine->initObjects();</code> |
| - **Before we start** there are some basic changes that have to made to the environment, in order to make the physics look more realist, we must make sure that our environmet is in a logical scale. If you have the handout code, Sinbad will be around 9.5 units high, Bullet library uses 1 unit as equal to 1 meter. | - **Before we start** there are some basic changes that have to made to the environment, in order to make the physics look more realist, we must make sure that our environmet is in a logical scale. If you have the handout code, Sinbad will be around 9.5 units high, Bullet library uses 1 unit as equal to 1 meter. |
| - **You can check out Sinbad's actualt height** by doing ''_SinbadNode->getBoundingBox().getSize()'', this function will return the bounding box the the sceneNode, which is an axis aligned box that encompasses the entities of the SceneNode and is defined by the vertex extremas + an additional 2% scale. | - **You can check out Sinbad's actualt height** by doing ''_SinbadNode->getBoundingBox().getSize()'', this function will return the bounding box the the sceneNode, which is an axis aligned box that encompasses the entities of the SceneNode and is defined by the vertex extremas + an additional 2% scale. |
| _Mouse = 0; | _Mouse = 0; |
| }</code> Also make sure to add the int member variable mouseMask, and set it to 0 in the FrameListener constructor. Now you can query whether a mouse button was pressed like so '' (mouseMask & (1 << (int)OIS::MouseButtonID::MB_Left)) '' **make sure** to add ''mouseMask = 0'' before your call to ''_Mouse->capture()'' in you FrameStarted function so we don't retain old mouse states :). | }</code> Also make sure to add the int member variable mouseMask, and set it to 0 in the FrameListener constructor. Now you can query whether a mouse button was pressed like so '' (mouseMask & (1 << (int)OIS::MouseButtonID::MB_Left)) '' **make sure** to add ''mouseMask = 0'' before your call to ''_Mouse->capture()'' in you FrameStarted function so we don't retain old mouse states :). |
| - **Now we spawn a cube from the origin of the camera** and give it some linear velocity in the direction of the camera. <code>if ( (mouseMask & (1 << (int)OIS::MouseButtonID::MB_Left)) ) { | - **Now we spawn a cube from the origin of the camera** and give it some linear velocity in the direction of the camera. You will have to pass a pointer to the SceneManager into the frameListener. <code>if ( (mouseMask & (1 << (int)OIS::MouseButtonID::MB_Left)) ) { |
| // Create a cube entity. | // Create a cube entity. |
| Ogre::Entity* cubeEnt = _sceneManager->createEntity("Cube.mesh"); | Ogre::Entity* cubeEnt = _sceneManager->createEntity("Cube.mesh"); |
| |
| <box red 100% | **Attention!**> | <box red 100% | **Attention!**> |
| ** Compile and run using a Release built target!!! Very important, unless you plan to fry some eggs and bacon on your laptop :)** Just make sure to use the Release version of the plugins file when you run the application.It can be found under ''<YourOgreSDK>\bin\Release\plugins.cfg''</box> | ** Compile and run using a Release built target!!! Very important, unless you plan to fry some eggs and bacon on your laptop :)** Just make sure to use the Release version of the plugins file when you run the application.It can be found under ''<YourOgreSDK>\bin\Release\plugins.cfg'' **Check out these pre-processor variables to help you out**<code|cpp>#if _DEBUG |
| | cf.load("../LabFiles/OgreConfig/resources_d.cfg"); |
| | #elif NDEBUG |
| | cf.load("../LabFiles/OgreConfig/resources.cfg"); |
| | #endif |
| |
| | #if _DEBUG |
| | _root = new Ogre::Root("../LabFiles/OgreConfig/plugins_d.cfg","../LabFiles/OgreConfig/ogre.cfg", "../LabFiles/ogre.log"); |
| | #elif NDEBUG |
| | _root = new Ogre::Root("../LabFiles/OgreConfig/plugins.cfg","../LabFiles/OgreConfig/ogre.cfg", "../LabFiles/ogre.log"); |
| | #endif</code></box> |
| ===== When You Are Finished ===== | ===== When You Are Finished ===== |
| |
| Upload your **commented source files** into Lab9 in MySchool (zip them up if more than one). | Upload your **commented source files** into Lab9 in MySchool (zip them up if more than one). |