Inclined Plane

From Physics Simulation Wiki

Jump to: navigation, search

Contents

Introduction

Add a one line description about your tutorial.

Overview

Describe your tutorial in detail. What will be the Bullet physics objects that you will use and how the whole thing will work

Setup

The following sources are defined HeaderFile.h and SourceFile.cpp.

HeaderFile.h

Lets look at the header file HeaderFile.h. As before, we are simply declaring our create function.

class CommonExampleInterface*    YourDemoCreateFunc(struct CommonExampleOptions& options);

SourceFile.cpp

In the SourceFile.cpp file, we define the create function as follows:

CommonExampleInterface*    YourDemoCreateFunc(CommonExampleOptions& options)
{
   return new YourDemoExample(options.m_guiHelper);
}

Our example class YourDemoExample is declared and partially defined as follows.

struct YourDemoExample : public CommonRigidBodyBase {
   YourDemoExample(struct GUIHelperInterface* helper):CommonRigidBodyBase(helper) {}
   virtual ~YourDemoExample(){}
   virtual void initPhysics();
   virtual void renderScene();
   void resetCamera() {
      float dist = 41;
      float pitch = 52;
      float yaw = 35;
      float targetPos[3]={0,0.46,0};
      m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]);
   }
};

The resetCamera and renderScene remain unchanged. The only difference is in the initPhysics function which is defined as follows.

void YourDemoExample::initPhysics() {
   m_guiHelper->setUpAxis(1);
   createEmptyDynamicsWorld();
   m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);
   
   if (m_dynamicsWorld->getDebugDrawer())    
      m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe+btIDebugDraw::DBG_DrawContactPoints);

   btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.)));
   m_collisionShapes.push_back(groundShape);

   btTransform groundTransform;
   groundTransform.setIdentity();
   groundTransform.setOrigin(btVector3(0,-50,0)); 
   
   {
      btScalar mass(0.);
      createRigidBody(mass,groundTransform,groundShape, btVector4(0,0,1,1));
   }

The above lines should be familiar as we are first setting our up axis and then we create an empty dynamic world. We then enable debug rendering and then create our static ground rigid body.

   {
     //This code will be changed subject to your tutorial demo requirement

In the above lines of code, we [add description about the physics objects you use in detail].

Finally, we issue a call to m_guiHelper to autogenerate graphical objects from the given dynamics world.

      
   }
   m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld);
}

Build Scipts

For the example browser application, the build scripts are present in the {BULLET_ROOT}/examples/ExampleBrowser sub-folder.

Editing Premake4.lua for premake

Open the premake4.lua script file. Ensure that the first line (i.e. the project name) is App_BulletExampleBrowser. Next, scroll down until you see another project named BulletExampleBrowserLib. Scroll further down until you see a files section. You must enter the relative path of your sources. Supposing we store our sources (YourDemo.h/cpp) in the examples/ExtendedTutorials sub-folder, we would then add the following entry in the files section.

files {
   --list of existing source files 
   "../ExtendedTutorials/YourDemo.cpp",
   "../ExtendedTutorials/YourDemo.h",
   --additional source files 

Note that you may omit adding headers as they will be included with the source files. Advanced user could also use wild card to include all source files in a given folder as follows.

files {
   --list of existing source files 
   "../ExtendedTutorials/*", 
   --additional source files  

An important note. After you have edited premake4.lua file, ensure that the root folder premake batch script is rerun to ensure that the new changes take effect and our sources are included.

Editing CMakeLists.txt for CMake

Open the CMakeLists.txt script file. Next, scroll down until you see the following variable definition

SET(BulletExampleBrowser_SRCS

You must enter the relative path of your sources. Supposing we store our sources (YourDemo.h/cpp) in the examples/ExtendedTutorials sub-folder, we would then add the following enteries.

SET(BulletExampleBrowser_SRCS
   #list of existing source files 
   "../ExtendedTutorials/YourDemo.cpp",
   "../ExtendedTutorials/YourDemo.h",
   #additional source files 

Note that you may omit adding headers as they will be included with the source files. Note that the wild card enteries do not work in case of CMake and the best approach is to add all sources individually.

An important note. After you have edited CMakeLists.txt file, rerun CMake to ensure that the new changes take effect and our sources are included in the BulletExampleBrowser project.

Snapshot

Thats it. We can then add our entry in the ExampleEnteries.cpp file as was shown earlier in Simple Box example. Running this example shows [write what your demo shows on screen]. Clicking and dragging the mouse on the dynamic rigid body forces it to move subject to the constraint enforce by the point to point constraint as shown in the snapshot below.

File:YourDemoSnapshot.png

Personal tools