Back to index

supertuxkart  0.5+dfsg1
DemoApplication.h
Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 */
00015 
00016 #ifndef DEMO_APPLICATION_H
00017 #define DEMO_APPLICATION_H
00018 
00019 
00020 #include "GlutStuff.h"
00021 #include "GL_ShapeDrawer.h"
00022 
00023 #include <stdlib.h>
00024 #include <stdio.h>
00025 #include <math.h>
00026 
00027 
00028 #include "LinearMath/btVector3.h"
00029 #include "LinearMath/btMatrix3x3.h"
00030 #include "LinearMath/btTransform.h"
00031 #include "LinearMath/btQuickprof.h"
00032 #include "LinearMath/btAlignedObjectArray.h"
00033 
00034 class  btCollisionShape;
00035 class  btDynamicsWorld;
00036 class  btRigidBody;
00037 class  btTypedConstraint;
00038 
00039 
00040 
00041 class DemoApplication
00042 {
00043        void   displayProfileString(int xOffset,int yStart,char* message);
00044        class CProfileIterator* m_profileIterator;
00045 
00046        protected:
00047 #ifdef USE_BT_CLOCK
00048        btClock m_clock;
00049 #endif //USE_BT_CLOCK
00050 
00052        btDynamicsWorld*            m_dynamicsWorld;
00053 
00055        btTypedConstraint*          m_pickConstraint;
00056 
00057        btCollisionShape*    m_shootBoxShape;
00058 
00059        float  m_cameraDistance;
00060        int    m_debugMode;
00061        
00062        float m_ele;
00063        float m_azi;
00064        btVector3 m_cameraPosition;
00065        btVector3 m_cameraTargetPosition;//look at
00066 
00067        float m_scaleBottom;
00068        float m_scaleFactor;
00069        btVector3 m_cameraUp;
00070        int    m_forwardAxis;
00071 
00072        int m_glutScreenWidth;
00073        int m_glutScreenHeight;
00074 
00075        float  m_ShootBoxInitialSpeed;
00076        
00077        bool   m_stepping;
00078        bool m_singleStep;
00079        bool m_idle;
00080        int m_lastKey;
00081 
00082        void showProfileInfo(float& xOffset,float& yStart, float yIncr);
00083 
00084        GL_ShapeDrawer       m_shapeDrawer;
00085 
00086 public:
00087               
00088        DemoApplication();
00089        
00090        virtual ~DemoApplication();
00091 
00092        btDynamicsWorld*            getDynamicsWorld()
00093        {
00094               return m_dynamicsWorld;
00095        }
00096        
00097        void setOrthographicProjection();
00098        void resetPerspectiveProjection();
00099 
00100        int           getDebugMode()
00101        {
00102               return m_debugMode ;
00103        }
00104        
00105        void   setDebugMode(int mode);
00106        
00107        
00108        void   setCameraUp(const btVector3& camUp)
00109        {
00110               m_cameraUp = camUp;
00111        }
00112        void   setCameraForwardAxis(int axis)
00113        {
00114               m_forwardAxis = axis;
00115        }
00116 
00117        void myinit();
00118 
00119        void toggleIdle();
00120        
00121        virtual void updateCamera();
00122 
00123        btVector3     getCameraPosition()
00124        {
00125               return m_cameraPosition;
00126        }
00127        btVector3     getCameraTargetPosition()
00128        {
00129               return m_cameraTargetPosition;
00130        }
00131 
00132        btScalar      getDeltaTimeMicroseconds()
00133        {
00134 #ifdef USE_BT_CLOCK
00135               btScalar dt = m_clock.getTimeMicroseconds();
00136               m_clock.reset();
00137               return dt;
00138 #else
00139               return btScalar(16666.);
00140 #endif
00141        }
00142 
00144                             
00145        float  getCameraDistance();
00146        void   setCameraDistance(float dist);     
00147        void   moveAndDisplay();
00148 
00149        virtual void clientMoveAndDisplay() = 0;
00150 
00151        virtual void  clientResetScene();
00152 
00154        void   shootBox(const btVector3& destination);
00155 
00156 
00157        btVector3     getRayTo(int x,int y);
00158 
00159        btRigidBody*  localCreateRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape);
00160 
00162 
00163        virtual void keyboardCallback(unsigned char key, int x, int y);
00164 
00165        virtual void specialKeyboard(int key, int x, int y);
00166 
00167        virtual void specialKeyboardUp(int key, int x, int y);
00168 
00169        virtual void reshape(int w, int h);
00170 
00171        virtual void mouseFunc(int button, int state, int x, int y);
00172 
00173        virtual void  mouseMotionFunc(int x,int y);
00174        
00175        virtual void displayCallback();
00176 
00177        virtual       void renderme();
00178 
00179 
00180        void stepLeft();
00181        void stepRight();
00182        void stepFront();
00183        void stepBack();
00184        void zoomIn();
00185        void zoomOut();
00186 
00187        bool   isIdle() const
00188        {
00189               return m_idle;
00190        }
00191 
00192        void   setIdle(bool idle)
00193        {
00194               m_idle = idle;
00195        }
00196 
00197 
00198 };
00199 
00200 #endif //DEMO_APPLICATION_H
00201