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