[167] | 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 | #include "GuiUpdater.h" |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | #include "LinearMath/btVector3.h" |
---|
| 31 | #include "LinearMath/btMatrix3x3.h" |
---|
| 32 | #include "LinearMath/btTransform.h" |
---|
| 33 | #include "LinearMath/btQuickprof.h" |
---|
| 34 | #include "LinearMath/btAlignedObjectArray.h" |
---|
| 35 | |
---|
| 36 | #include "GuiUpdater.h" |
---|
| 37 | |
---|
| 38 | class btCollisionShape; |
---|
| 39 | //class btDynamicsWorld; |
---|
| 40 | class btRigidBody; |
---|
| 41 | class btTypedConstraint; |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | class DemoApplication |
---|
| 46 | { |
---|
| 47 | void displayProfileString(int xOffset,int yStart,char* message); |
---|
| 48 | class CProfileIterator* m_profileIterator; |
---|
| 49 | |
---|
| 50 | protected: |
---|
| 51 | #ifdef USE_BT_CLOCK |
---|
| 52 | btClock m_clock; |
---|
| 53 | #endif //USE_BT_CLOCK |
---|
| 54 | |
---|
| 55 | ///this is the most important class |
---|
| 56 | // btDynamicsWorld* m_dynamicsWorld; |
---|
| 57 | |
---|
| 58 | ///constraint for mouse picking |
---|
| 59 | btTypedConstraint* m_pickConstraint; |
---|
| 60 | |
---|
| 61 | btCollisionShape* m_shootBoxShape; |
---|
| 62 | |
---|
| 63 | float m_cameraDistance; |
---|
| 64 | int m_debugMode; |
---|
| 65 | |
---|
| 66 | float m_ele; |
---|
| 67 | float m_azi; |
---|
| 68 | btVector3 m_cameraPosition; |
---|
| 69 | btVector3 m_cameraTargetPosition;//look at |
---|
| 70 | |
---|
| 71 | int m_mouseOldX; |
---|
| 72 | int m_mouseOldY; |
---|
| 73 | int m_mouseButtons; |
---|
| 74 | |
---|
| 75 | bool m_textureinitialized; |
---|
| 76 | bool m_textureenabled; |
---|
| 77 | unsigned int m_texturehandle; |
---|
| 78 | void draw(guiObject *obj, const btVector3&color); |
---|
| 79 | |
---|
| 80 | public: |
---|
| 81 | int m_modifierKeys; |
---|
| 82 | map<int, guiObject *> m_cache; |
---|
| 83 | |
---|
| 84 | protected: |
---|
| 85 | |
---|
| 86 | float m_scaleBottom; |
---|
| 87 | float m_scaleFactor; |
---|
| 88 | btVector3 m_cameraUp; |
---|
| 89 | int m_forwardAxis; |
---|
| 90 | |
---|
| 91 | int m_glutScreenWidth; |
---|
| 92 | int m_glutScreenHeight; |
---|
| 93 | |
---|
| 94 | int m_ortho; |
---|
| 95 | |
---|
| 96 | float m_ShootBoxInitialSpeed; |
---|
| 97 | |
---|
| 98 | bool m_stepping; |
---|
| 99 | bool m_singleStep; |
---|
| 100 | bool m_idle; |
---|
| 101 | int m_lastKey; |
---|
| 102 | |
---|
| 103 | void showProfileInfo(int& xOffset,int& yStart, int yIncr); |
---|
| 104 | // void renderscene(int pass); |
---|
| 105 | void renderscene(int pass); |
---|
| 106 | |
---|
| 107 | GL_ShapeDrawer* m_shapeDrawer; |
---|
| 108 | bool m_enableshadows; |
---|
| 109 | btVector3 m_sundirection; |
---|
| 110 | |
---|
| 111 | public: |
---|
| 112 | |
---|
| 113 | DemoApplication(); |
---|
| 114 | |
---|
| 115 | virtual ~DemoApplication(); |
---|
| 116 | |
---|
| 117 | // btDynamicsWorld* getDynamicsWorld() |
---|
| 118 | // { |
---|
| 119 | // return m_dynamicsWorld; |
---|
| 120 | // } |
---|
| 121 | |
---|
| 122 | void updateInfo(map<int, guiObject *> objects); |
---|
| 123 | |
---|
| 124 | virtual void initPhysics() {}; |
---|
| 125 | |
---|
| 126 | virtual void setDrawClusters(bool drawClusters) |
---|
| 127 | { |
---|
| 128 | |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | void overrideGLShapeDrawer (GL_ShapeDrawer* shapeDrawer); |
---|
| 132 | |
---|
| 133 | void setOrthographicProjection(); |
---|
| 134 | void resetPerspectiveProjection(); |
---|
| 135 | |
---|
| 136 | bool setTexturing(bool enable) { return(m_shapeDrawer->enableTexture(enable)); } |
---|
| 137 | bool setShadows(bool enable) { bool p=m_enableshadows;m_enableshadows=enable;return(p); } |
---|
| 138 | bool getTexturing() const |
---|
| 139 | { |
---|
| 140 | return m_shapeDrawer->hasTextureEnabled(); |
---|
| 141 | } |
---|
| 142 | bool getShadows() const |
---|
| 143 | { |
---|
| 144 | return m_enableshadows; |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | int getDebugMode() |
---|
| 149 | { |
---|
| 150 | return m_debugMode ; |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | void setDebugMode(int mode); |
---|
| 154 | |
---|
| 155 | void setAzi(float azi) |
---|
| 156 | { |
---|
| 157 | m_azi = azi; |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | void setCameraUp(const btVector3& camUp) |
---|
| 161 | { |
---|
| 162 | m_cameraUp = camUp; |
---|
| 163 | } |
---|
| 164 | void setCameraForwardAxis(int axis) |
---|
| 165 | { |
---|
| 166 | m_forwardAxis = axis; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | void myinit(); |
---|
| 170 | |
---|
| 171 | void toggleIdle(); |
---|
| 172 | |
---|
| 173 | virtual void updateCamera(); |
---|
| 174 | |
---|
| 175 | btVector3 getCameraPosition() |
---|
| 176 | { |
---|
| 177 | return m_cameraPosition; |
---|
| 178 | } |
---|
| 179 | btVector3 getCameraTargetPosition() |
---|
| 180 | { |
---|
| 181 | return m_cameraTargetPosition; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | btScalar getDeltaTimeMicroseconds() |
---|
| 185 | { |
---|
| 186 | #ifdef USE_BT_CLOCK |
---|
| 187 | btScalar dt = m_clock.getTimeMicroseconds(); |
---|
| 188 | m_clock.reset(); |
---|
| 189 | return dt; |
---|
| 190 | #else |
---|
| 191 | return btScalar(16666.); |
---|
| 192 | #endif |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | ///glut callbacks |
---|
| 196 | |
---|
| 197 | float getCameraDistance(); |
---|
| 198 | void setCameraDistance(float dist); |
---|
| 199 | void moveAndDisplay(); |
---|
| 200 | |
---|
| 201 | virtual void clientMoveAndDisplay(); |
---|
| 202 | |
---|
| 203 | virtual void clientResetScene(); |
---|
| 204 | |
---|
| 205 | ///Demo functions |
---|
| 206 | virtual void setShootBoxShape (); |
---|
| 207 | virtual void shootBox(const btVector3& destination); |
---|
| 208 | |
---|
| 209 | |
---|
| 210 | btVector3 getRayTo(int x,int y); |
---|
| 211 | |
---|
| 212 | btRigidBody* localCreateRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape); |
---|
| 213 | |
---|
| 214 | ///callback methods by glut |
---|
| 215 | |
---|
| 216 | virtual void keyboardCallback(unsigned char key, int x, int y); |
---|
| 217 | |
---|
| 218 | virtual void keyboardUpCallback(unsigned char key, int x, int y) {} |
---|
| 219 | |
---|
| 220 | virtual void specialKeyboard(int key, int x, int y); |
---|
| 221 | |
---|
| 222 | virtual void specialKeyboardUp(int key, int x, int y){} |
---|
| 223 | |
---|
| 224 | virtual void reshape(int w, int h); |
---|
| 225 | |
---|
| 226 | virtual void mouseFunc(int button, int state, int x, int y); |
---|
| 227 | |
---|
| 228 | virtual void mouseMotionFunc(int x,int y); |
---|
| 229 | |
---|
| 230 | virtual void displayCallback(); |
---|
| 231 | |
---|
| 232 | virtual void renderme(); |
---|
| 233 | |
---|
| 234 | virtual void swapBuffers(); |
---|
| 235 | |
---|
| 236 | virtual void updateModifierKeys(); |
---|
| 237 | |
---|
| 238 | void stepLeft(); |
---|
| 239 | void stepRight(); |
---|
| 240 | void stepFront(); |
---|
| 241 | void stepBack(); |
---|
| 242 | void zoomIn(); |
---|
| 243 | void zoomOut(); |
---|
| 244 | |
---|
| 245 | bool isIdle() const |
---|
| 246 | { |
---|
| 247 | return m_idle; |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | void setIdle(bool idle) |
---|
| 251 | { |
---|
| 252 | m_idle = idle; |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | |
---|
| 256 | }; |
---|
| 257 | |
---|
| 258 | #endif //DEMO_APPLICATION_H |
---|
| 259 | |
---|
| 260 | |
---|