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