====== LAB7: Collision and Physics (Part A) ====== This lab, part A in particular, is heavily based on an Ogre physics example provided by [[http://nikhilesh.info/|Nikhilesh Sigatapu]]. Nikhilesh created a thin [[http://bulletphysics.org/wordpress/|Bullet Physics Simulation]] wrapper for Ogre, which makes setting up physical objects very straight-forward. This wrapper is called [[https://github.com/nikki93/btogre|btOgre]] and the example we will use is contained within that package. Other sources of information include of course the [[http://bulletphysics.org/mediawiki-1.5.8/index.php/Main_Page|Bullet Physics Documentation and Wiki]]. ===== Discussion ===== Discussion thread for this lab is here: [[http://ruclasses.proboards.com/index.cgi?board=gedespring2013&action=display&thread=124|Lab 7 Discussion Thread]] ===== Goal ====== The goal of this lab is to understand how you can integrate a physics simulation with Ogre and understand what such a simulation can provide. ===== Preparation ===== Preparation steps are provided below. ===== Lab Project ===== Follow these steps to complete the lab project: - **Download, Compile and Test Bullet Physics** The Bullet physics simulation library comes with a number of OpenGL examples that demonstrate the capabilities of the library. Even if we intend to use this library with Ogre, you should first make sure you can compile and view these stand-alone examples. Do the following: - Download [[https://code.google.com/p/bullet/|Bullet 2.81]] and for example place it next to your Ogre SDK. I suggest renaming the folder as ''bullet-2.81'' as you are not likely to worry about specific revisions. - Open and build ''\bullet-2.81\build\vs2010\0BulletSolution.sln'' - Open a console in your ''\bullet-2.81'' folder and execute ''App_HelloWorld_vs2010_debug.exe'' from the command line. You should see numbers printed out on the screen. - Read through the source code for this example, located at ''\bullet-2.81\Demos\HelloWorld''. Appreciate the fact that there are no graphics, and yet we have dynamic objects being simulated ;) - **Create a New Ogre Project** Create a new empty project called "Lab7" in the same way you have created new projects for other lab projects. Add the files in {{public:t-gede-13-1:lab7:lab7files.zip|Lab7Files.zip}} to your project. You should also add the contents of the **Models** and **Materials** folders to those folders in your compiled executable location. Finally, in addition to the regular configuration settings for the labs, you will have to add the following to use the Bullet libraries: - **Additional Include Directories** : ''\OgreSDK_vc10_v1-8-1\boost; \bullet-2.81\src'' - **Additional Library Directories** : ''\OgreSDK_vc10_v1-8-1\boost\lib; \bullet-2.81\lib'' - **Additional Dependencies** : ''BulletDynamics_vs2010_debug.lib;BulletCollision_vs2010_debug.lib;LinearMath_vs2010_debug.lib'' - **Compile and Run the Lab7Main Example** You should now be able to compile and run the provided Lab7Main example application, and you should see a simple object fall down and land on the ground plane. The interaction between the object and the ground is not particularly interesting, so in order to see something a bit more exciting, you should try using the ''TestLevel_b0.mesh'' as the groundEntity instead of the simple plane. Try that (you can accomplish that by commenting out three lines and un-comment one line ;)). - **Create a Prop Class for Multiple Stars** Take a look at the code that creates a single star object. It's between the comment "Star!" and the comment "Ground!". Replace this code with the instancing of a generic prop class. The constructor of the prop class should take the following arguments and completely create the new object in the scene: Prop(SceneManager* sceneMgr, const Ogre::String& mesh, Vector3 pos, Vector3 scale, btScalar mass) And then to create one star in ''createScene'' you would simply do: Prop* mystar = new Prop(mSceneMgr, "Star.mesh", Vector3(0,10,0), Vector3(1,1,1), 5); When you implement this class, be aware that Ogre allows you to omit providing an entity name and a scene node name when you create those. Ogre will then simply provide unique names of its own (useful when you want to create multiple instances of this object). Make sure that your class also implements a destructor that deletes the object properly (in the example, you see how the object is deleted in the BtOgreTestApplication destructor). When you have implemented the **Prop** class, test it by creating two instances of the star. - **Create New Stars with the Mouse** Finally, add a check for a left mouse button **down** state in the ''frameStarted'' method of the ''BtOgreTestFrameListener'' and respond to that state by creating a new instance of the star. You should now be able to easily fill the world with bouncing stars! ===== When You Are Finished ===== Upload your **commented source files** into Lab6 in MySchool (zip them up if more than one). The lab projects will not be graded, but their completion counts towards your participation grade.