User Tools

Site Tools


public:t-gede-13-1:lab7

LAB7: Collision and Physics (Part A)

This lab, part A in particular, is heavily based on an Ogre physics example provided by Nikhilesh Sigatapu. Nikhilesh created a thin Bullet Physics Simulation wrapper for Ogre, which makes setting up physical objects very straight-forward. This wrapper is called btOgre and the example we will use is contained within that package. Other sources of information include of course the Bullet Physics Documentation and Wiki.

Discussion

Discussion thread for this lab is here: 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:

  1. 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:
    1. Download 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.
    2. Open and build <yoursdkfolder>\bullet-2.81\build\vs2010\0BulletSolution.sln
    3. Open a console in your <yoursdkfolder>\bullet-2.81 folder and execute App_HelloWorld_vs2010_debug.exe from the command line. You should see numbers printed out on the screen.
    4. Read through the source code for this example, located at <yoursdkfolder>\bullet-2.81\Demos\HelloWorld. Appreciate the fact that there are no graphics, and yet we have dynamic objects being simulated ;)
  2. 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 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:
    1. Additional Include Directories : <yoursdkfolder>\OgreSDK_vc10_v1-8-1\boost; <yoursdkfolder>\bullet-2.81\src
    2. Additional Library Directories : <yoursdkfolder>\OgreSDK_vc10_v1-8-1\boost\lib; <yoursdkfolder>\bullet-2.81\lib
    3. Additional Dependencies : BulletDynamics_vs2010_debug.lib;BulletCollision_vs2010_debug.lib;LinearMath_vs2010_debug.lib
  3. 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 ;)).
  4. 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.

  5. 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.

/var/www/ailab/WWW/wiki/data/pages/public/t-gede-13-1/lab7.txt · Last modified: 2013/03/12 13:01 by hannes