Advertisement
Guest User

DemoApplication.h

a guest
Dec 27th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.68 KB | None | 0 0
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
  4.  
  5. This software is provided 'as-is', without any express or implied warranty.
  6. In no event will the authors be held liable for any damages arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it freely,
  9. subject to the following restrictions:
  10.  
  11. 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.
  12. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  13. 3. This notice may not be removed or altered from any source distribution.
  14. */
  15.  
  16. #ifndef DEMO_APPLICATION_H
  17. #define DEMO_APPLICATION_H
  18.  
  19.  
  20. #include "GlutStuff.h"
  21. #include "GL_ShapeDrawer.h"
  22.  
  23. #include <stdlib.h>
  24. #include <stdio.h>
  25. #include <math.h>
  26.  
  27.  
  28. #include "LinearMath/btVector3.h"
  29. #include "LinearMath/btMatrix3x3.h"
  30. #include "LinearMath/btTransform.h"
  31. #include "LinearMath/btQuickprof.h"
  32. #include "LinearMath/btAlignedObjectArray.h"
  33.  
  34. class   btCollisionShape;
  35. class   btDynamicsWorld;
  36. class   btRigidBody;
  37. class   btTypedConstraint;
  38.  
  39.  
  40.  
  41. class DemoApplication
  42. {
  43. protected:
  44.     void    displayProfileString(int xOffset,int yStart,char* message);
  45.     class CProfileIterator* m_profileIterator;
  46.  
  47.     protected:
  48. #ifdef USE_BT_CLOCK
  49.     btClock m_clock;
  50. #endif //USE_BT_CLOCK
  51.  
  52.     ///this is the most important class
  53.     btDynamicsWorld*        m_dynamicsWorld;
  54.  
  55.     ///constraint for mouse picking
  56.     btTypedConstraint*      m_pickConstraint;
  57.  
  58.     virtual void removePickingConstraint();
  59.  
  60.     virtual void pickObject(const btVector3& pickPos, const class btCollisionObject* hitObj);
  61.  
  62.  
  63.     btCollisionShape*   m_shootBoxShape;
  64.  
  65.     float   m_cameraDistance;
  66.     int m_debugMode;
  67.  
  68.     float m_ele;
  69.     float m_azi;
  70.     btVector3 m_cameraPosition;
  71.     btVector3 m_cameraTargetPosition;//look at
  72.  
  73.     int m_mouseOldX;
  74.     int m_mouseOldY;
  75.     int m_mouseButtons;
  76. public:
  77.     int m_modifierKeys;
  78. protected:
  79.  
  80.     float m_scaleBottom;
  81.     float m_scaleFactor;
  82.     btVector3 m_cameraUp;
  83.     int m_forwardAxis;
  84.     float m_zoomStepSize;
  85.  
  86.     int m_glutScreenWidth;
  87.     int m_glutScreenHeight;
  88.  
  89.     float   m_frustumZNear;
  90.     float   m_frustumZFar;
  91.  
  92.     int m_ortho;
  93.  
  94.     float   m_ShootBoxInitialSpeed;
  95.  
  96.     bool    m_stepping;
  97.     bool m_singleStep;
  98.     bool m_idle;
  99.     int m_lastKey;
  100.  
  101.     void showProfileInfo(int& xOffset,int& yStart, int yIncr);
  102.     void renderscene(int pass);
  103.  
  104.     GL_ShapeDrawer* m_shapeDrawer;
  105.     bool            m_enableshadows;
  106.     btVector3       m_sundirection;
  107.     btScalar        m_defaultContactProcessingThreshold;
  108.  
  109. public:
  110.  
  111.     DemoApplication();
  112.  
  113.     virtual ~DemoApplication();
  114.  
  115.     void        setDynamicsWorld(btDynamicsWorld* world)
  116.     {
  117.         m_dynamicsWorld=world;
  118.     }
  119.  
  120.  
  121.     btDynamicsWorld*        getDynamicsWorld()
  122.     {
  123.         return m_dynamicsWorld;
  124.     }
  125.  
  126.     virtual void initPhysics() = 0;
  127.  
  128.     virtual void setDrawClusters(bool drawClusters)
  129.     {
  130.  
  131.     }
  132.  
  133.     void overrideGLShapeDrawer (GL_ShapeDrawer* shapeDrawer);
  134.  
  135.     void setOrthographicProjection();
  136.     void resetPerspectiveProjection();
  137.  
  138.     bool    setTexturing(bool enable) { return(m_shapeDrawer->enableTexture(enable)); }
  139.     bool    setShadows(bool enable) { bool p=m_enableshadows;m_enableshadows=enable;return(p); }
  140.     bool    getTexturing() const
  141.     {
  142.         return m_shapeDrawer->hasTextureEnabled();
  143.     }
  144.     bool    getShadows() const
  145.     {
  146.         return m_enableshadows;
  147.     }
  148.  
  149.  
  150.     int     getDebugMode()
  151.     {
  152.         return m_debugMode ;
  153.     }
  154.  
  155.     void    setDebugMode(int mode);
  156.  
  157.     void    setAzi(float azi)
  158.     {
  159.         m_azi = azi;
  160.     }
  161.  
  162.     void    setEle(float ele)
  163.     {
  164.         m_ele = ele;
  165.     }
  166.  
  167.     void    setCameraUp(const btVector3& camUp)
  168.     {
  169.         m_cameraUp = camUp;
  170.     }
  171.     void    setCameraForwardAxis(int axis)
  172.     {
  173.         m_forwardAxis = axis;
  174.     }
  175.  
  176.     virtual void myinit();
  177.  
  178.     void toggleIdle();
  179.  
  180.     virtual void updateCamera();
  181.  
  182.     btVector3   getCameraPosition()
  183.     {
  184.         return m_cameraPosition;
  185.     }
  186.     btVector3   getCameraTargetPosition()
  187.     {
  188.         return m_cameraTargetPosition;
  189.     }
  190.  
  191.     btScalar    getDeltaTimeMicroseconds()
  192.     {
  193. #ifdef USE_BT_CLOCK
  194.         btScalar dt = (btScalar)m_clock.getTimeMicroseconds();
  195.         m_clock.reset();
  196.         return dt;
  197. #else
  198.         return btScalar(16666.);
  199. #endif
  200.     }
  201.     void setFrustumZPlanes(float zNear, float zFar)
  202.     {
  203.         m_frustumZNear = zNear;
  204.         m_frustumZFar = zFar;
  205.     }
  206.  
  207.     ///glut callbacks
  208.  
  209.     float   getCameraDistance();
  210.     void    setCameraDistance(float dist);
  211.     void    moveAndDisplay();
  212.  
  213.     virtual void clientMoveAndDisplay() = 0;
  214.  
  215.     virtual void    clientResetScene();
  216.  
  217.     ///Demo functions
  218.     virtual void setShootBoxShape ();
  219.     virtual void    shootBox(const btVector3& destination);
  220.  
  221.  
  222.     btVector3   getRayTo(int x,int y);
  223.  
  224.     btRigidBody*    localCreateRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape);
  225.  
  226.     ///callback methods by glut
  227.  
  228.     virtual void keyboardCallback(unsigned char key, int x, int y);
  229.  
  230.     virtual void keyboardUpCallback(unsigned char key, int x, int y) {}
  231.  
  232.     virtual void specialKeyboard(int key, int x, int y){}
  233.  
  234.     virtual void specialKeyboardUp(int key, int x, int y){}
  235.  
  236.     virtual void reshape(int w, int h);
  237.  
  238.     virtual void mouseFunc(int button, int state, int x, int y);
  239.  
  240.     virtual void    mouseMotionFunc(int x,int y);
  241.  
  242.     virtual void displayCallback();
  243.  
  244.     virtual     void renderme();
  245.  
  246.     virtual     void swapBuffers() = 0;
  247.  
  248.     virtual     void    updateModifierKeys() = 0;
  249.  
  250.     void stepLeft();
  251.     void stepRight();
  252.     void stepFront();
  253.     void stepBack();
  254.     void zoomIn();
  255.     void zoomOut();
  256.  
  257.     bool    isIdle() const
  258.     {
  259.         return  m_idle;
  260.     }
  261.  
  262.     void    setIdle(bool idle)
  263.     {
  264.         m_idle = idle;
  265.     }
  266.  
  267.  
  268. };
  269.  
  270. #endif //DEMO_APPLICATION_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement