Back to index

supertuxkart  0.5+dfsg1
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
DemoApplication Class Reference

#include <DemoApplication.h>

Collaboration diagram for DemoApplication:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 DemoApplication ()
virtual ~DemoApplication ()
btDynamicsWorldgetDynamicsWorld ()
void setOrthographicProjection ()
void resetPerspectiveProjection ()
int getDebugMode ()
void setDebugMode (int mode)
void setCameraUp (const btVector3 &camUp)
void setCameraForwardAxis (int axis)
void myinit ()
void toggleIdle ()
virtual void updateCamera ()
btVector3 getCameraPosition ()
btVector3 getCameraTargetPosition ()
btScalar getDeltaTimeMicroseconds ()
float getCameraDistance ()
 glut callbacks
void setCameraDistance (float dist)
void moveAndDisplay ()
virtual void clientMoveAndDisplay ()=0
virtual void clientResetScene ()
void shootBox (const btVector3 &destination)
 Demo functions.
btVector3 getRayTo (int x, int y)
btRigidBodylocalCreateRigidBody (float mass, const btTransform &startTransform, btCollisionShape *shape)
virtual void keyboardCallback (unsigned char key, int x, int y)
 callback methods by glut
virtual void specialKeyboard (int key, int x, int y)
virtual void specialKeyboardUp (int key, int x, int y)
virtual void reshape (int w, int h)
virtual void mouseFunc (int button, int state, int x, int y)
virtual void mouseMotionFunc (int x, int y)
virtual void displayCallback ()
virtual void renderme ()
void stepLeft ()
void stepRight ()
void stepFront ()
void stepBack ()
void zoomIn ()
void zoomOut ()
bool isIdle () const
void setIdle (bool idle)

Protected Member Functions

void showProfileInfo (float &xOffset, float &yStart, float yIncr)

Protected Attributes

btDynamicsWorldm_dynamicsWorld
 this is the most important class
btTypedConstraintm_pickConstraint
 constraint for mouse picking
btCollisionShapem_shootBoxShape
float m_cameraDistance
int m_debugMode
float m_ele
float m_azi
btVector3 m_cameraPosition
btVector3 m_cameraTargetPosition
float m_scaleBottom
float m_scaleFactor
btVector3 m_cameraUp
int m_forwardAxis
int m_glutScreenWidth
int m_glutScreenHeight
float m_ShootBoxInitialSpeed
bool m_stepping
bool m_singleStep
bool m_idle
int m_lastKey
GL_ShapeDrawer m_shapeDrawer

Private Member Functions

void displayProfileString (int xOffset, int yStart, char *message)

Private Attributes

class CProfileIteratorm_profileIterator

Detailed Description

Definition at line 41 of file DemoApplication.h.


Constructor & Destructor Documentation

Definition at line 52 of file DemoApplication.cpp.

:
m_dynamicsWorld(0),
m_pickConstraint(0),
m_shootBoxShape(0),
       m_cameraDistance(15.0),
       m_debugMode(0),
       m_ele(20.f),
       m_azi(0.f),
       m_cameraPosition(0.f,0.f,0.f),
       m_cameraTargetPosition(0.f,0.f,0.f),
       m_scaleBottom(0.5f),
       m_scaleFactor(2.f),
       m_cameraUp(0,1,0),
       m_forwardAxis(2),    
       m_glutScreenWidth(0),
       m_glutScreenHeight(0),
       m_ShootBoxInitialSpeed(40.f),
       m_stepping(true),
       m_singleStep(false),
       m_idle(false)
{
#ifndef BT_NO_PROFILE
       m_profileIterator = CProfileManager::Get_Iterator();
#endif //BT_NO_PROFILE
}

Here is the call graph for this function:

Definition at line 82 of file DemoApplication.cpp.

{
#ifndef BT_NO_PROFILE
       CProfileManager::Release_Iterator(m_profileIterator);
#endif //BT_NO_PROFILE

       if (m_shootBoxShape)
              delete m_shootBoxShape;

}

Here is the call graph for this function:


Member Function Documentation

virtual void DemoApplication::clientMoveAndDisplay ( ) [pure virtual]

Here is the caller graph for this function:

Definition at line 1128 of file DemoApplication.cpp.

{
#ifdef SHOW_NUM_DEEP_PENETRATIONS
       gNumDeepPenetrationChecks = 0;
       gNumGjkChecks = 0;
#endif //SHOW_NUM_DEEP_PENETRATIONS

       int numObjects = 0;
       if (m_dynamicsWorld)
       {
              m_dynamicsWorld->stepSimulation(1.f/60.f,0);
              numObjects = m_dynamicsWorld->getNumCollisionObjects();
       }
       
       for (int i=0;i<numObjects;i++)
       {
              btCollisionObject* colObj = m_dynamicsWorld->getCollisionObjectArray()[i];
              btRigidBody* body = btRigidBody::upcast(colObj);
              if (body)
              {
                     if (body->getMotionState())
                     {
                            btDefaultMotionState* myMotionState = (btDefaultMotionState*)body->getMotionState();
                            myMotionState->m_graphicsWorldTrans = myMotionState->m_startWorldTrans;
                            colObj->setWorldTransform( myMotionState->m_graphicsWorldTrans );
                            colObj->setInterpolationWorldTransform( myMotionState->m_startWorldTrans );
                            colObj->activate();
                     }
                     //removed cached contact points
                     m_dynamicsWorld->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(colObj->getBroadphaseHandle(),getDynamicsWorld()->getDispatcher());

                     btRigidBody* body = btRigidBody::upcast(colObj);
                     if (body && !body->isStaticObject())
                     {
                            btRigidBody::upcast(colObj)->setLinearVelocity(btVector3(0,0,0));
                            btRigidBody::upcast(colObj)->setAngularVelocity(btVector3(0,0,0));
                     }
              }

       /*
       //quickly search some issue at a certain simulation frame, pressing space to reset
              int fixed=18;
              for (int i=0;i<fixed;i++)
              {
                     getDynamicsWorld()->stepSimulation(1./60.f,1);
              }
       */
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 496 of file DemoApplication.cpp.

{
}

Here is the caller graph for this function:

void DemoApplication::displayProfileString ( int  xOffset,
int  yStart,
char *  message 
) [private]

Definition at line 823 of file DemoApplication.cpp.

{
       glRasterPos3f(xOffset,yStart,0);
       BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),message);
}

Here is the call graph for this function:

Here is the caller graph for this function:

glut callbacks

Definition at line 135 of file DemoApplication.cpp.

{
       return m_cameraDistance;
}

Definition at line 123 of file DemoApplication.h.

       {
              return m_cameraPosition;
       }

Here is the caller graph for this function:

Definition at line 127 of file DemoApplication.h.

Here is the caller graph for this function:

Definition at line 100 of file DemoApplication.h.

       {
              return m_debugMode ;
       }

Here is the caller graph for this function:

Definition at line 132 of file DemoApplication.h.

       {
#ifdef USE_BT_CLOCK
              btScalar dt = m_clock.getTimeMicroseconds();
              m_clock.reset();
              return dt;
#else
              return btScalar(16666.);
#endif
       }

Definition at line 92 of file DemoApplication.h.

       {
              return m_dynamicsWorld;
       }

Here is the caller graph for this function:

btVector3 DemoApplication::getRayTo ( int  x,
int  y 
)

Definition at line 546 of file DemoApplication.cpp.

{

              float top = 1.f;
       float bottom = -1.f;
       float nearPlane = 1.f;
       float tanFov = (top-bottom)*0.5f / nearPlane;
       float fov = 2.0 * atanf (tanFov);

       btVector3     rayFrom = getCameraPosition();
       btVector3 rayForward = (getCameraTargetPosition()-getCameraPosition());
       rayForward.normalize();
       float farPlane = 10000.f;
       rayForward*= farPlane;

       btVector3 rightOffset;
       btVector3 vertical = m_cameraUp;

       btVector3 hor;
       hor = rayForward.cross(vertical);
       hor.normalize();
       vertical = hor.cross(rayForward);
       vertical.normalize();

       float tanfov = tanf(0.5f*fov);
       
       btScalar aspect = m_glutScreenHeight / (btScalar)m_glutScreenWidth;

       hor *= 2.f * farPlane * tanfov;
       vertical *= 2.f * farPlane * tanfov;

       if (aspect<1)
       {
              hor/=aspect;
       } else
       {
              vertical*=aspect;
       }

       btVector3 rayToCenter = rayFrom + rayForward;
       btVector3 dHor = hor * 1.f/float(m_glutScreenWidth);
       btVector3 dVert = vertical * 1.f/float(m_glutScreenHeight);
       

       btVector3 rayTo = rayToCenter - 0.5f * hor + 0.5f * vertical;
       rayTo += x * dHor;
       rayTo -= y * dVert;
       return rayTo;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool DemoApplication::isIdle ( ) const [inline]

Definition at line 187 of file DemoApplication.h.

       {
              return m_idle;
       }
void DemoApplication::keyboardCallback ( unsigned char  key,
int  x,
int  y 
) [virtual]

callback methods by glut

Definition at line 253 of file DemoApplication.cpp.

{
       (void)x;
       (void)y;

              m_lastKey = 0;

#ifndef BT_NO_PROFILE
        if (key >= 0x31 && key < 0x37)
        {
                int child = key-0x31;
                m_profileIterator->Enter_Child(child);
        }
        if (key==0x30)
        {
                m_profileIterator->Enter_Parent();
        }
#endif //BT_NO_PROFILE

    switch (key) 
    {
    case 'q' : 
#ifdef BT_USE_FREEGLUT
              //return from glutMainLoop(), detect memory leaks etc.
              glutLeaveMainLoop();
#else
              exit(0);
#endif
              break;

    case 'l' : stepLeft(); break;
    case 'r' : stepRight(); break;
    case 'f' : stepFront(); break;
    case 'b' : stepBack(); break;
    case 'z' : zoomIn(); break;
    case 'x' : zoomOut(); break;
    case 'i' : toggleIdle(); break;
       case 'h':
                     if (m_debugMode & btIDebugDraw::DBG_NoHelpText)
                            m_debugMode = m_debugMode & (~btIDebugDraw::DBG_NoHelpText);
                     else
                            m_debugMode |= btIDebugDraw::DBG_NoHelpText;
                     break;

       case 'w':
                     if (m_debugMode & btIDebugDraw::DBG_DrawWireframe)
                            m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawWireframe);
                     else
                            m_debugMode |= btIDebugDraw::DBG_DrawWireframe;
                 break;

   case 'p':
          if (m_debugMode & btIDebugDraw::DBG_ProfileTimings)
              m_debugMode = m_debugMode & (~btIDebugDraw::DBG_ProfileTimings);
       else
              m_debugMode |= btIDebugDraw::DBG_ProfileTimings;
   break;

   case 'm':
          if (m_debugMode & btIDebugDraw::DBG_EnableSatComparison)
              m_debugMode = m_debugMode & (~btIDebugDraw::DBG_EnableSatComparison);
       else
              m_debugMode |= btIDebugDraw::DBG_EnableSatComparison;
   break;

   case 'n':
          if (m_debugMode & btIDebugDraw::DBG_DisableBulletLCP)
              m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DisableBulletLCP);
       else
              m_debugMode |= btIDebugDraw::DBG_DisableBulletLCP;
   break;

       case 't' : 
                     if (m_debugMode & btIDebugDraw::DBG_DrawText)
                            m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawText);
                     else
                            m_debugMode |= btIDebugDraw::DBG_DrawText;
                 break;
       case 'y':            
                     if (m_debugMode & btIDebugDraw::DBG_DrawFeaturesText)
                            m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawFeaturesText);
                     else
                            m_debugMode |= btIDebugDraw::DBG_DrawFeaturesText;
              break;
       case 'a':     
              if (m_debugMode & btIDebugDraw::DBG_DrawAabb)
                            m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawAabb);
                     else
                            m_debugMode |= btIDebugDraw::DBG_DrawAabb;
                     break;
              case 'c' : 
                     if (m_debugMode & btIDebugDraw::DBG_DrawContactPoints)
                            m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawContactPoints);
                     else
                            m_debugMode |= btIDebugDraw::DBG_DrawContactPoints;
                     break;

              case 'd' : 
                     if (m_debugMode & btIDebugDraw::DBG_NoDeactivation)
                            m_debugMode = m_debugMode & (~btIDebugDraw::DBG_NoDeactivation);
                     else
                            m_debugMode |= btIDebugDraw::DBG_NoDeactivation;
                     if (m_debugMode & btIDebugDraw::DBG_NoDeactivation)
                     {
                            gDisableDeactivation = true;
                     } else
                     {
                            gDisableDeactivation = false;
                     }
                     break;
                     

              

       case 'o' :
              {
                     m_stepping = !m_stepping;
                     break;
              }
       case 's' : clientMoveAndDisplay(); break;
//    case ' ' : newRandom(); break;
       case ' ':
              clientResetScene();
                     break;
       case '1':
              {
                     if (m_debugMode & btIDebugDraw::DBG_EnableCCD)
                            m_debugMode = m_debugMode & (~btIDebugDraw::DBG_EnableCCD);
                     else
                            m_debugMode |= btIDebugDraw::DBG_EnableCCD;
                     break;
              }

              case '.':
              {
                     shootBox(getCameraTargetPosition());
                     break;
              }

              case '+':
              {
                     m_ShootBoxInitialSpeed += 10.f;
                     break;
              }
              case '-':
              {
                     m_ShootBoxInitialSpeed -= 10.f;
                     break;
              }

    default:
//        std::cout << "unused key : " << key << std::endl;
        break;
    }

       if (getDynamicsWorld() && getDynamicsWorld()->getDebugDrawer())
              getDynamicsWorld()->getDebugDrawer()->setDebugMode(m_debugMode);

       glutPostRedisplay();

}

Here is the call graph for this function:

Here is the caller graph for this function:

btRigidBody * DemoApplication::localCreateRigidBody ( float  mass,
const btTransform startTransform,
btCollisionShape shape 
)

Definition at line 755 of file DemoApplication.cpp.

{
       //rigidbody is dynamic if and only if mass is non zero, otherwise static
       bool isDynamic = (mass != 0.f);

       btVector3 localInertia(0,0,0);
       if (isDynamic)
              shape->calculateLocalInertia(mass,localInertia);

       //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects

#define USE_MOTIONSTATE 1
#ifdef USE_MOTIONSTATE
       btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);

       btRigidBody::btRigidBodyConstructionInfo cInfo(mass,myMotionState,shape,localInertia);

       btRigidBody* body = new btRigidBody(cInfo);

#else
       btRigidBody* body = new btRigidBody(mass,0,shape,localInertia);       
       body->setWorldTransform(startTransform);
#endif//

       m_dynamicsWorld->addRigidBody(body);
       
       return body;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DemoApplication::mouseFunc ( int  button,
int  state,
int  x,
int  y 
) [virtual]

Definition at line 597 of file DemoApplication.cpp.

{
       //printf("button %i, state %i, x=%i,y=%i\n",button,state,x,y);
       //button 0, state 0 means left mouse down

       btVector3 rayTo = getRayTo(x,y);

       switch (button)
       {
       case 2:
              {
                     if (state==0)
                     {

                            shootBox(rayTo);
                     }
                     break;
              };
       case 1:
              {


                     if (state==0)
                     {
                            

                            //apply an impulse
                            if (m_dynamicsWorld)
                            {
                                   btCollisionWorld::ClosestRayResultCallback rayCallback(m_cameraPosition,rayTo);
                                   m_dynamicsWorld->rayTest(m_cameraPosition,rayTo,rayCallback);
                                   if (rayCallback.HasHit())
                                   {
                                          
                                          btRigidBody* body = btRigidBody::upcast(rayCallback.m_collisionObject);
                                          if (body)
                                          {
                                                        body->setActivationState(ACTIVE_TAG);
                                                        btVector3 impulse = rayTo;
                                                        impulse.normalize();
                                                        float impulseStrength = 10.f;
                                                        impulse *= impulseStrength;
                                                        btVector3 relPos = rayCallback.m_hitPointWorld - body->getCenterOfMassPosition();
                                                        body->applyImpulse(impulse,relPos);
                                                 }
                                   }
                            }

                            

                     } else
                     {

                     }
                     break; 
              }
       case 0:
              {
                     if (state==0)
                     {
              

                            //add a point to point constraint for picking
                            if (m_dynamicsWorld)
                            {
                                   btCollisionWorld::ClosestRayResultCallback rayCallback(m_cameraPosition,rayTo);
                                   m_dynamicsWorld->rayTest(m_cameraPosition,rayTo,rayCallback);
                                   if (rayCallback.HasHit())
                                   {
                                          
                                          
                                          btRigidBody* body = btRigidBody::upcast(rayCallback.m_collisionObject);
                                          if (body)
                                          {
                                                 //other exclusions?
                                                 if (!(body->isStaticObject() || body->isKinematicObject()))
                                                 {
                                                        pickedBody = body;
                                                        pickedBody->setActivationState(DISABLE_DEACTIVATION);

                                                        
                                                        btVector3 pickPos = rayCallback.m_hitPointWorld;

                                                        btVector3 localPivot = body->getCenterOfMassTransform().inverse() * pickPos;

                                                        btPoint2PointConstraint* p2p = new btPoint2PointConstraint(*body,localPivot);
                                                        m_dynamicsWorld->addConstraint(p2p);
                                                        m_pickConstraint = p2p;
                                                        
                                                        //save mouse position for dragging
                                                        gOldPickingPos = rayTo;

                                                        btVector3 eyePos(m_cameraPosition[0],m_cameraPosition[1],m_cameraPosition[2]);

                                                        gOldPickingDist  = (pickPos-eyePos).length();

                                                        //very weak constraint for picking
                                                        p2p->m_setting.m_tau = 0.1f;
                                                 }
                                          }
                                   }
                            }

                     } else
                     {

                            if (m_pickConstraint && m_dynamicsWorld)
                            {
                                   m_dynamicsWorld->removeConstraint(m_pickConstraint);
                                   delete m_pickConstraint;
                                   //printf("removed constraint %i",gPickingConstraintId);
                                   m_pickConstraint = 0;
                                   pickedBody->forceActivationState(ACTIVE_TAG);
                                   pickedBody->setDeactivationTime( 0.f );
                                   pickedBody = 0;
                            }

                            
                     }

                     break;

              }
       default:
              {
              }
       }

}

Here is the call graph for this function:

Here is the caller graph for this function:

void DemoApplication::mouseMotionFunc ( int  x,
int  y 
) [virtual]

Definition at line 727 of file DemoApplication.cpp.

{

       if (m_pickConstraint)
       {
              //move the constraint pivot
              btPoint2PointConstraint* p2p = static_cast<btPoint2PointConstraint*>(m_pickConstraint);
              if (p2p)
              {
                     //keep it at the same picking distance

                     btVector3 newRayTo = getRayTo(x,y);
                     btVector3 eyePos(m_cameraPosition[0],m_cameraPosition[1],m_cameraPosition[2]);
                     btVector3 dir = newRayTo-eyePos;
                     dir.normalize();
                     dir *= gOldPickingDist;

                     btVector3 newPos = eyePos + dir;
                     p2p->setPivotB(newPos);
              }

       }

       
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 487 of file DemoApplication.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void DemoApplication::myinit ( void  )

Definition at line 94 of file DemoApplication.cpp.

{

    GLfloat light_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
    GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
    /* light_position is NOT default value       */
    GLfloat light_position0[] = { 1.0, 10.0, 1.0, 0.0 };
    GLfloat light_position1[] = { -1.0, -10.0, -1.0, 0.0 };
  
    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
  
    glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
    glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
    glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
    glLightfv(GL_LIGHT1, GL_POSITION, light_position1);

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHT1);
 

    glShadeModel(GL_SMOOTH);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

              glClearColor(0.7,0.7,0.7,0);

    //  glEnable(GL_CULL_FACE);
    //  glCullFace(GL_BACK);
}

Here is the caller graph for this function:

void DemoApplication::renderme ( ) [virtual]

color differently for active, sleeping, wantsdeactivation states

Definition at line 903 of file DemoApplication.cpp.

{
       updateCamera();

       btScalar m[16];

       if (m_dynamicsWorld)
       {
              int numObjects = m_dynamicsWorld->getNumCollisionObjects();
              btVector3 wireColor(1,0,0);
              for (int i=0;i<numObjects;i++)
              {
                     btCollisionObject* colObj = m_dynamicsWorld->getCollisionObjectArray()[i];
                     btRigidBody* body = btRigidBody::upcast(colObj);

                     if (body && body->getMotionState())
                     {
                            btDefaultMotionState* myMotionState = (btDefaultMotionState*)body->getMotionState();
                            myMotionState->m_graphicsWorldTrans.getOpenGLMatrix(m);
                     } else
                     {
                            colObj->getWorldTransform().getOpenGLMatrix(m);
                     }

                     btVector3 wireColor(1.f,1.0f,0.5f); //wants deactivation
                     if (i & 1)
                     {
                            wireColor = btVector3(0.f,0.0f,1.f);
                     }
                     if (colObj->getActivationState() == 1) //active
                     {
                            if (i & 1)
                            {
                                   wireColor += btVector3 (1.f,0.f,0.f);
                            } else
                            {                    
                                   wireColor += btVector3 (.5f,0.f,0.f);
                            }
                     }
                     if (colObj->getActivationState() == 2) //ISLAND_SLEEPING
                     {
                            if (i & 1)
                            {
                                   wireColor += btVector3 (0.f,1.f, 0.f);
                            } else
                            {
                                   wireColor += btVector3 (0.f,0.5f,0.f);
                            }
                     }

                     m_shapeDrawer.drawOpenGL(m,colObj->getCollisionShape(),wireColor,getDebugMode());
              }


                     float xOffset = 10.f;
                     float yStart = 20.f;
                     float yIncr = 20.f;
                     char buf[124];

                     glDisable(GL_LIGHTING);
                     glColor3f(0, 0, 0);

                     if ((m_debugMode & btIDebugDraw::DBG_NoHelpText)==0)
                            {
                            setOrthographicProjection();

                            showProfileInfo(xOffset,yStart,yIncr);

       #ifdef USE_QUICKPROF


                     if ( getDebugMode() & btIDebugDraw::DBG_ProfileTimings)
                     {
                            static int counter = 0;
                            counter++;
                            std::map<std::string, hidden::ProfileBlock*>::iterator iter;
                            for (iter = btProfiler::mProfileBlocks.begin(); iter != btProfiler::mProfileBlocks.end(); ++iter)
                            {
                                   char blockTime[128];
                                   sprintf(blockTime, "%s: %lf",&((*iter).first[0]),btProfiler::getBlockTime((*iter).first, btProfiler::BLOCK_CYCLE_SECONDS));//BLOCK_TOTAL_PERCENT));
                                   glRasterPos3f(xOffset,yStart,0);
                                   BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),blockTime);
                                   yStart += yIncr;

                            }

                     }
       #endif //USE_QUICKPROF

                     
                            glRasterPos3f(xOffset,yStart,0);
                            sprintf(buf,"mouse to interact");
                            BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
                            yStart += yIncr;

                            glRasterPos3f(xOffset,yStart,0);
                            sprintf(buf,"space to reset");
                            BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
                            yStart += yIncr;
                     
                            glRasterPos3f(xOffset,yStart,0);
                            sprintf(buf,"cursor keys and z,x to navigate");
                            BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
                            yStart += yIncr;

                            glRasterPos3f(xOffset,yStart,0);
                            sprintf(buf,"i to toggle simulation, s single step");
                            BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
                            yStart += yIncr;

                            glRasterPos3f(xOffset,yStart,0);
                            sprintf(buf,"q to quit");
                            BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
                            yStart += yIncr;

                            glRasterPos3f(xOffset,yStart,0);
                            sprintf(buf,". to shoot box");
                            BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
                            yStart += yIncr;

                            // not yet hooked up again after refactoring...

                            glRasterPos3f(xOffset,yStart,0);
                            sprintf(buf,"d to toggle deactivation");
                            BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
                            yStart += yIncr;

                            
                            glRasterPos3f(xOffset,yStart,0);
                            sprintf(buf,"g to toggle mesh animation (ConcaveDemo)");
                            BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
                            yStart += yIncr;
                     

                            glRasterPos3f(xOffset,yStart,0);
                            sprintf(buf,"h to toggle help text");
                            BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
                            yStart += yIncr;

                            
                            glRasterPos3f(xOffset,yStart,0);
                            sprintf(buf,"p to toggle profiling (+results to file)");
                            BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
                            yStart += yIncr;


                            //bool useBulletLCP = !(getDebugMode() & btIDebugDraw::DBG_DisableBulletLCP);
                            //bool useCCD = (getDebugMode() & btIDebugDraw::DBG_EnableCCD);
                            //glRasterPos3f(xOffset,yStart,0);
                            //sprintf(buf,"1 CCD mode (adhoc) = %i",useCCD);
                            //BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
                            //yStart += yIncr;


                            glRasterPos3f(xOffset,yStart,0);
                            sprintf(buf,"+- shooting speed = %10.2f",m_ShootBoxInitialSpeed);
                            BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
                            yStart += yIncr;

#ifdef SHOW_NUM_DEEP_PENETRATIONS
                            

                            glRasterPos3f(xOffset,yStart,0);
                            sprintf(buf,"gNumDeepPenetrationChecks = %d",gNumDeepPenetrationChecks);
                            BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
                            yStart += yIncr;

                            glRasterPos3f(xOffset,yStart,0);
                            sprintf(buf,"gNumGjkChecks= %d",gNumGjkChecks);
                            BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
                            yStart += yIncr;

                            
                            glRasterPos3f(xOffset,yStart,0);
                            sprintf(buf,"gNumAlignedAllocs = %d",gNumAlignedAllocs);
                            BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
                            yStart += yIncr;

                            glRasterPos3f(xOffset,yStart,0);
                            sprintf(buf,"gNumAlignedFree= %d",gNumAlignedFree);
                            BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
                            yStart += yIncr;

                            glRasterPos3f(xOffset,yStart,0);
                            sprintf(buf,"# alloc-free = %d",gNumAlignedAllocs-gNumAlignedFree);
                            BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
                            yStart += yIncr;

//enable BT_DEBUG_MEMORY_ALLOCATIONS define in Bullet/src/LinearMath/btAlignedAllocator.h for memory leak detection
#ifdef BT_DEBUG_MEMORY_ALLOCATIONS
                            glRasterPos3f(xOffset,yStart,0);
                            sprintf(buf,"gTotalBytesAlignedAllocs = %d",gTotalBytesAlignedAllocs);
                            BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
                            yStart += yIncr;
#endif //BT_DEBUG_MEMORY_ALLOCATIONS

                            if (getDynamicsWorld())
                            {
                                   glRasterPos3f(xOffset,yStart,0);
                                   sprintf(buf,"# objects = %d",getDynamicsWorld()->getNumCollisionObjects());
                                   BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
                                   yStart += yIncr;
                                   glRasterPos3f(xOffset,yStart,0);
                                   sprintf(buf,"# pairs = %d",getDynamicsWorld()->getBroadphase()->getOverlappingPairCache()->getNumOverlappingPairs());
                                   BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
                                   yStart += yIncr;

                            }


#endif //SHOW_NUM_DEEP_PENETRATIONS

                            resetPerspectiveProjection();
                     }

                     glEnable(GL_LIGHTING);

              
       }

       updateCamera();

}

Here is the call graph for this function:

Definition at line 809 of file DemoApplication.cpp.

{

       glMatrixMode(GL_PROJECTION);
       glPopMatrix();
       glMatrixMode(GL_MODELVIEW);
       updateCamera();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DemoApplication::reshape ( int  w,
int  h 
) [virtual]

Definition at line 243 of file DemoApplication.cpp.

{
       m_glutScreenWidth = w;
       m_glutScreenHeight = h;
       
       glViewport(0, 0, w, h);
       updateCamera();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DemoApplication::setCameraDistance ( float  dist)

Definition at line 130 of file DemoApplication.cpp.

{
       m_cameraDistance  = dist;
}
void DemoApplication::setCameraForwardAxis ( int  axis) [inline]

Definition at line 112 of file DemoApplication.h.

       {
              m_forwardAxis = axis;
       }
void DemoApplication::setCameraUp ( const btVector3 camUp) [inline]

Definition at line 108 of file DemoApplication.h.

       {
              m_cameraUp = camUp;
       }
void DemoApplication::setDebugMode ( int  mode)

Definition at line 415 of file DemoApplication.cpp.

{
       m_debugMode = mode;
       if (getDynamicsWorld() && getDynamicsWorld()->getDebugDrawer())
              getDynamicsWorld()->getDebugDrawer()->setDebugMode(mode);
}

Here is the call graph for this function:

void DemoApplication::setIdle ( bool  idle) [inline]

Definition at line 192 of file DemoApplication.h.

       {
              m_idle = idle;
       }

Definition at line 785 of file DemoApplication.cpp.

{

       // switch to projection mode
       glMatrixMode(GL_PROJECTION);

       // save previous matrix which contains the 
       //settings for the perspective projection
       glPushMatrix();
       // reset matrix
       glLoadIdentity();
       // set a 2D orthographic projection
       gluOrtho2D(0, m_glutScreenWidth, 0, m_glutScreenHeight);
       glMatrixMode(GL_MODELVIEW);
       glLoadIdentity();

       // invert the y axis, down is positive
       glScalef(1, -1, 1);
       // mover the origin from the bottom left corner
       // to the upper left corner
       glTranslatef(0, -m_glutScreenHeight, 0);

}

Here is the caller graph for this function:

void DemoApplication::shootBox ( const btVector3 destination)

Demo functions.

Definition at line 503 of file DemoApplication.cpp.

{

       if (m_dynamicsWorld)
       {
              float mass = 10.f;
              btTransform startTransform;
              startTransform.setIdentity();
              btVector3 camPos = getCameraPosition();
              startTransform.setOrigin(camPos);

              if (!m_shootBoxShape)
              {
              //#define TEST_UNIFORM_SCALING_SHAPE 1
#ifdef TEST_UNIFORM_SCALING_SHAPE
              btConvexShape* childShape = new btBoxShape(btVector3(1.f,1.f,1.f));
              m_shootBoxShape = new btUniformScalingShape(childShape,0.5f);
#else
              m_shootBoxShape = new btBoxShape(btVector3(1.f,1.f,1.f));
#endif//
              }

              btRigidBody* body = this->localCreateRigidBody(mass, startTransform,m_shootBoxShape);

              btVector3 linVel(destination[0]-camPos[0],destination[1]-camPos[1],destination[2]-camPos[2]);
              linVel.normalize();
              linVel*=m_ShootBoxInitialSpeed;

              body->getWorldTransform().setOrigin(camPos);
              body->getWorldTransform().setRotation(btQuaternion(0,0,0,1));
              body->setLinearVelocity(linVel);
              body->setAngularVelocity(btVector3(0,0,0));
       }

}

Here is the call graph for this function:

Here is the caller graph for this function:

void DemoApplication::showProfileInfo ( float &  xOffset,
float &  yStart,
float  yIncr 
) [protected]

Definition at line 830 of file DemoApplication.cpp.

{
#ifndef BT_NO_PROFILE

       static double time_since_reset = 0.f;
       if (!m_idle)
       {
                     time_since_reset = CProfileManager::Get_Time_Since_Reset();
       }


       {
              //recompute profiling data, and store profile strings

              char blockTime[128];

              double totalTime = 0;
              
              int frames_since_reset = CProfileManager::Get_Frame_Count_Since_Reset();

              m_profileIterator->First();

              double parent_time = m_profileIterator->Is_Root() ? time_since_reset : m_profileIterator->Get_Current_Parent_Total_Time();

              {
                     sprintf(blockTime,"--- Profiling: %s (total running time: %.3f ms) ---",     m_profileIterator->Get_Current_Parent_Name(), parent_time );
                     displayProfileString(xOffset,yStart,blockTime);
                     yStart += yIncr;
                     sprintf(blockTime,"press number (1,2...) to display child timings, or 0 to go up to parent" );
                     displayProfileString(xOffset,yStart,blockTime);
                     yStart += yIncr;

              }


              double accumulated_time = 0.f;

              for (int i = 0; !m_profileIterator->Is_Done(); m_profileIterator->Next())
              {
                     double current_total_time = m_profileIterator->Get_Current_Total_Time();
                     accumulated_time += current_total_time;
                     double fraction = parent_time > SIMD_EPSILON ? (current_total_time / parent_time) * 100 : 0.f;

                     sprintf(blockTime,"%d -- %s (%.2f %%) :: %.3f ms / frame (%d calls)",
                            ++i, m_profileIterator->Get_Current_Name(), fraction,
                            (current_total_time / (double)frames_since_reset),m_profileIterator->Get_Current_Total_Calls());
                     displayProfileString(xOffset,yStart,blockTime);
                     yStart += yIncr;
                     totalTime += current_total_time;
              }

              sprintf(blockTime,"%s (%.3f %%) :: %.3f ms", "Unaccounted",
                     // (min(0, time_since_reset - totalTime) / time_since_reset) * 100);
                     parent_time > SIMD_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f, parent_time - accumulated_time);

              displayProfileString(xOffset,yStart,blockTime);
              yStart += yIncr;



              sprintf(blockTime,"-------------------------------------------------");
              displayProfileString(xOffset,yStart,blockTime);
              yStart += yIncr;

       }
#endif//BT_NO_PROFILE




}

Here is the call graph for this function:

Here is the caller graph for this function:

void DemoApplication::specialKeyboard ( int  key,
int  x,
int  y 
) [virtual]

Definition at line 430 of file DemoApplication.cpp.

{
       (void)x;
       (void)y;

    switch (key) 
    {
       case GLUT_KEY_F1:
              {

                     break;
              }

       case GLUT_KEY_F2:
       {

              break;
       }


       case GLUT_KEY_END:
              {
                     int numObj = getDynamicsWorld()->getNumCollisionObjects();
                     if (numObj)
                     {
                            btCollisionObject* obj = getDynamicsWorld()->getCollisionObjectArray()[numObj-1];
                            
                            getDynamicsWorld()->removeCollisionObject(obj);
                            btRigidBody* body = btRigidBody::upcast(obj);
                            if (body && body->getMotionState())
                            {
                                   delete body->getMotionState();                                 
                            }
                            delete obj;
                            

                     }
                     break;
              }
    case GLUT_KEY_LEFT : stepLeft(); break;
    case GLUT_KEY_RIGHT : stepRight(); break;
    case GLUT_KEY_UP : stepFront(); break;
    case GLUT_KEY_DOWN : stepBack(); break;
    case GLUT_KEY_PAGE_UP : zoomIn(); break;
    case GLUT_KEY_PAGE_DOWN : zoomOut(); break;
    case GLUT_KEY_HOME : toggleIdle(); break;
    default:
//        std::cout << "unused (special) key : " << key << std::endl;
        break;
    }

       glutPostRedisplay();

}

Here is the call graph for this function:

Here is the caller graph for this function:

void DemoApplication::specialKeyboardUp ( int  key,
int  x,
int  y 
) [virtual]

Definition at line 423 of file DemoApplication.cpp.

{

              glutPostRedisplay();

}

Here is the caller graph for this function:

Definition at line 217 of file DemoApplication.cpp.

{ 
       m_ele -= STEPSIZE; if (m_ele < 0) m_ele += 360; updateCamera(); 
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 213 of file DemoApplication.cpp.

{ 
       m_ele += STEPSIZE; if (m_ele >= 360) m_ele -= 360; updateCamera(); 
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 205 of file DemoApplication.cpp.

{ 
       m_azi -= STEPSIZE; if (m_azi < 0) m_azi += 360; updateCamera(); 
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 209 of file DemoApplication.cpp.

{ 
       m_azi += STEPSIZE; if (m_azi >= 360) m_azi -= 360; updateCamera(); 
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 142 of file DemoApplication.cpp.

                                 {
    if (m_idle) {
        m_idle = false;
    }
    else {
        m_idle = true;
    }
}

Here is the caller graph for this function:

void DemoApplication::updateCamera ( ) [virtual]

Definition at line 154 of file DemoApplication.cpp.

                                   {

       
       glMatrixMode(GL_PROJECTION);
       glLoadIdentity();
       float rele = m_ele * 0.01745329251994329547;// rads per deg
       float razi = m_azi * 0.01745329251994329547;// rads per deg
       

       btQuaternion rot(m_cameraUp,razi);


       btVector3 eyePos(0,0,0);
       eyePos[m_forwardAxis] = -m_cameraDistance;

       btVector3 forward(eyePos[0],eyePos[1],eyePos[2]);
       if (forward.length2() < SIMD_EPSILON)
       {
              forward.setValue(1.f,0.f,0.f);
       }
       btVector3 right = m_cameraUp.cross(forward);
       btQuaternion roll(right,-rele);

       eyePos = btMatrix3x3(rot) * btMatrix3x3(roll) * eyePos;

       m_cameraPosition[0] = eyePos.getX();
       m_cameraPosition[1] = eyePos.getY();
       m_cameraPosition[2] = eyePos.getZ();

       if (m_glutScreenWidth > m_glutScreenHeight) 
       {
              btScalar aspect = m_glutScreenWidth / (btScalar)m_glutScreenHeight;
              glFrustum (-aspect, aspect, -1.0, 1.0, 1.0, 10000.0);
       } else 
       {
              btScalar aspect = m_glutScreenHeight / (btScalar)m_glutScreenWidth;
              glFrustum (-1.0, 1.0, -aspect, aspect, 1.0, 10000.0);
       }


    glMatrixMode(GL_MODELVIEW);
       glLoadIdentity();
       gluLookAt(m_cameraPosition[0], m_cameraPosition[1], m_cameraPosition[2], 
              m_cameraTargetPosition[0], m_cameraTargetPosition[1], m_cameraTargetPosition[2], 
                       m_cameraUp.getX(),m_cameraUp.getY(),m_cameraUp.getZ());
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 221 of file DemoApplication.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 228 of file DemoApplication.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

float DemoApplication::m_azi [protected]

Definition at line 63 of file DemoApplication.h.

Definition at line 59 of file DemoApplication.h.

Definition at line 64 of file DemoApplication.h.

Definition at line 65 of file DemoApplication.h.

Definition at line 69 of file DemoApplication.h.

Definition at line 60 of file DemoApplication.h.

this is the most important class

Definition at line 52 of file DemoApplication.h.

float DemoApplication::m_ele [protected]

Definition at line 62 of file DemoApplication.h.

Definition at line 70 of file DemoApplication.h.

Definition at line 73 of file DemoApplication.h.

Definition at line 72 of file DemoApplication.h.

bool DemoApplication::m_idle [protected]

Definition at line 79 of file DemoApplication.h.

int DemoApplication::m_lastKey [protected]

Definition at line 80 of file DemoApplication.h.

constraint for mouse picking

Definition at line 55 of file DemoApplication.h.

Definition at line 44 of file DemoApplication.h.

float DemoApplication::m_scaleBottom [protected]

Definition at line 67 of file DemoApplication.h.

float DemoApplication::m_scaleFactor [protected]

Definition at line 68 of file DemoApplication.h.

Definition at line 84 of file DemoApplication.h.

Definition at line 75 of file DemoApplication.h.

Definition at line 57 of file DemoApplication.h.

Definition at line 78 of file DemoApplication.h.

bool DemoApplication::m_stepping [protected]

Definition at line 77 of file DemoApplication.h.


The documentation for this class was generated from the following files: