[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 | |
---|
| 17 | #include "LocalGui.h" |
---|
| 18 | #include "LinearMath/btIDebugDraw.h" |
---|
| 19 | #include "BulletDynamics/Dynamics/btDynamicsWorld.h" |
---|
| 20 | |
---|
| 21 | #include "BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h"//picking |
---|
| 22 | #include "BulletCollision/CollisionShapes/btCollisionShape.h" |
---|
| 23 | #include "BulletCollision/CollisionShapes/btBoxShape.h" |
---|
| 24 | #include "BulletCollision/CollisionShapes/btSphereShape.h" |
---|
| 25 | #include "BulletCollision/CollisionShapes/btCompoundShape.h" |
---|
| 26 | #include "BulletCollision/CollisionShapes/btUniformScalingShape.h" |
---|
| 27 | #include "BulletDynamics/ConstraintSolver/btConstraintSolver.h" |
---|
| 28 | #include "GL_ShapeDrawer.h" |
---|
| 29 | #include "LinearMath/btQuickprof.h" |
---|
| 30 | #include "LinearMath/btDefaultMotionState.h" |
---|
| 31 | |
---|
| 32 | #include "GLDebugFont.h" |
---|
| 33 | #include "btBulletDynamicsCommon.h" |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | extern bool gDisableDeactivation; |
---|
| 37 | int numObjects = 0; |
---|
| 38 | const int maxNumObjects = 16384; |
---|
| 39 | btTransform startTransforms[maxNumObjects]; |
---|
| 40 | btCollisionShape* gShapePtr[maxNumObjects];//1 rigidbody has 1 shape (no re-use of shapes) |
---|
| 41 | #define SHOW_NUM_DEEP_PENETRATIONS 1 |
---|
| 42 | |
---|
| 43 | extern int gNumClampedCcdMotions; |
---|
| 44 | |
---|
| 45 | #ifdef SHOW_NUM_DEEP_PENETRATIONS |
---|
| 46 | extern int gNumDeepPenetrationChecks; |
---|
| 47 | |
---|
| 48 | extern int gNumSplitImpulseRecoveries; |
---|
| 49 | extern int gNumGjkChecks; |
---|
| 50 | extern int gNumAlignedAllocs; |
---|
| 51 | extern int gNumAlignedFree; |
---|
| 52 | extern int gTotalBytesAlignedAllocs; |
---|
| 53 | |
---|
| 54 | #endif // |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | LocalGui::LocalGui(Environment *env) |
---|
| 58 | //see btIDebugDraw.h for modes |
---|
| 59 | : |
---|
| 60 | Gui(env), |
---|
| 61 | //m_dynamicsWorld(0), |
---|
| 62 | m_pickConstraint(0), |
---|
| 63 | m_shootBoxShape(0), |
---|
| 64 | m_cameraDistance(15.0), |
---|
| 65 | m_debugMode(0), |
---|
| 66 | m_ele(20.f), |
---|
| 67 | m_azi(0.f), |
---|
| 68 | m_cameraPosition(0.f,0.f,0.f), |
---|
| 69 | m_cameraTargetPosition(0.f,0.f,0.f), |
---|
| 70 | m_scaleBottom(0.5f), |
---|
| 71 | m_scaleFactor(2.f), |
---|
| 72 | m_cameraUp(0,1,0), |
---|
| 73 | m_forwardAxis(2), |
---|
| 74 | m_glutScreenWidth(0), |
---|
| 75 | m_glutScreenHeight(0), |
---|
| 76 | m_ShootBoxInitialSpeed(40.f), |
---|
| 77 | m_stepping(true), |
---|
| 78 | m_singleStep(false), |
---|
| 79 | m_idle(false), |
---|
| 80 | m_enableshadows(false), |
---|
| 81 | m_sundirection(btVector3(1,-2,1)*1000), |
---|
| 82 | m_ortho(0), |
---|
| 83 | m_mouseOldX(0), |
---|
| 84 | m_mouseOldY(0), |
---|
| 85 | m_mouseButtons(0), |
---|
| 86 | m_modifierKeys(0) |
---|
| 87 | { |
---|
| 88 | #ifndef BT_NO_PROFILE |
---|
| 89 | m_profileIterator = CProfileManager::Get_Iterator(); |
---|
| 90 | #endif //BT_NO_PROFILE |
---|
| 91 | |
---|
| 92 | m_shapeDrawer = new GL_ShapeDrawer (); |
---|
| 93 | m_shapeDrawer->enableTexture(true); |
---|
| 94 | m_enableshadows = false; |
---|
| 95 | |
---|
| 96 | m_env = env; |
---|
| 97 | m_dynamicsWorld = m_env->getDynamicsWorld(); |
---|
| 98 | |
---|
| 99 | m_ele = 75; |
---|
| 100 | updateCamera(); |
---|
| 101 | |
---|
| 102 | setTexturing(true); |
---|
| 103 | setShadows(true); |
---|
| 104 | setCameraDistance(btScalar(20)); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | LocalGui::~LocalGui() |
---|
| 110 | { |
---|
| 111 | #ifndef BT_NO_PROFILE |
---|
| 112 | CProfileManager::Release_Iterator(m_profileIterator); |
---|
| 113 | #endif //BT_NO_PROFILE |
---|
| 114 | |
---|
| 115 | if (m_shootBoxShape) |
---|
| 116 | delete m_shootBoxShape; |
---|
| 117 | |
---|
| 118 | if (m_shapeDrawer) |
---|
| 119 | delete m_shapeDrawer; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | void LocalGui::overrideGLShapeDrawer (GL_ShapeDrawer* shapeDrawer) |
---|
| 124 | { |
---|
| 125 | shapeDrawer->enableTexture (m_shapeDrawer->hasTextureEnabled()); |
---|
| 126 | delete m_shapeDrawer; |
---|
| 127 | m_shapeDrawer = shapeDrawer; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | void LocalGui::init(void) |
---|
| 131 | { |
---|
| 132 | GLfloat light_ambient[] = { 0.2, 0.2, 0.2, 1.0 }; |
---|
| 133 | GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; |
---|
| 134 | GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; |
---|
| 135 | /* light_position is NOT default value */ |
---|
| 136 | GLfloat light_position0[] = { 1.0, 10.0, 1.0, 0.0 }; |
---|
| 137 | GLfloat light_position1[] = { -1.0, -10.0, -1.0, 0.0 }; |
---|
| 138 | |
---|
| 139 | glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); |
---|
| 140 | glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); |
---|
| 141 | glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); |
---|
| 142 | glLightfv(GL_LIGHT0, GL_POSITION, light_position0); |
---|
| 143 | |
---|
| 144 | glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient); |
---|
| 145 | glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse); |
---|
| 146 | glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular); |
---|
| 147 | glLightfv(GL_LIGHT1, GL_POSITION, light_position1); |
---|
| 148 | |
---|
| 149 | glEnable(GL_LIGHTING); |
---|
| 150 | glEnable(GL_LIGHT0); |
---|
| 151 | glEnable(GL_LIGHT1); |
---|
| 152 | |
---|
| 153 | |
---|
| 154 | glShadeModel(GL_SMOOTH); |
---|
| 155 | glEnable(GL_DEPTH_TEST); |
---|
| 156 | glDepthFunc(GL_LESS); |
---|
| 157 | |
---|
| 158 | glClearColor(0.7,0.7,0.7,0); |
---|
| 159 | |
---|
| 160 | // glEnable(GL_CULL_FACE); |
---|
| 161 | // glCullFace(GL_BACK); |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | void LocalGui::setCameraDistance(float dist) |
---|
| 166 | { |
---|
| 167 | m_cameraDistance = dist; |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | float LocalGui::getCameraDistance() |
---|
| 171 | { |
---|
| 172 | return m_cameraDistance; |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | |
---|
| 176 | |
---|
| 177 | void LocalGui::toggleIdle() { |
---|
| 178 | if (m_idle) { |
---|
| 179 | m_idle = false; |
---|
| 180 | } |
---|
| 181 | else { |
---|
| 182 | m_idle = true; |
---|
| 183 | } |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | |
---|
| 189 | void LocalGui::updateCamera() { |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | glMatrixMode(GL_PROJECTION); |
---|
| 193 | glLoadIdentity(); |
---|
| 194 | float rele = m_ele * 0.01745329251994329547;// rads per deg |
---|
| 195 | float razi = m_azi * 0.01745329251994329547;// rads per deg |
---|
| 196 | |
---|
| 197 | |
---|
| 198 | btQuaternion rot(m_cameraUp,razi); |
---|
| 199 | |
---|
| 200 | |
---|
| 201 | btVector3 eyePos(0,0,0); |
---|
| 202 | eyePos[m_forwardAxis] = -m_cameraDistance; |
---|
| 203 | |
---|
| 204 | btVector3 forward(eyePos[0],eyePos[1],eyePos[2]); |
---|
| 205 | if (forward.length2() < SIMD_EPSILON) |
---|
| 206 | { |
---|
| 207 | forward.setValue(1.f,0.f,0.f); |
---|
| 208 | } |
---|
| 209 | btVector3 right = m_cameraUp.cross(forward); |
---|
| 210 | btQuaternion roll(right,-rele); |
---|
| 211 | |
---|
| 212 | eyePos = btMatrix3x3(rot) * btMatrix3x3(roll) * eyePos; |
---|
| 213 | |
---|
| 214 | m_cameraPosition[0] = eyePos.getX(); |
---|
| 215 | m_cameraPosition[1] = eyePos.getY(); |
---|
| 216 | m_cameraPosition[2] = eyePos.getZ(); |
---|
| 217 | m_cameraPosition += m_cameraTargetPosition; |
---|
| 218 | |
---|
| 219 | if (m_glutScreenWidth == 0 && m_glutScreenHeight == 0) |
---|
| 220 | return; |
---|
| 221 | |
---|
| 222 | btScalar aspect; |
---|
| 223 | btVector3 extents; |
---|
| 224 | |
---|
| 225 | if (m_glutScreenWidth > m_glutScreenHeight) |
---|
| 226 | { |
---|
| 227 | aspect = m_glutScreenWidth / (btScalar)m_glutScreenHeight; |
---|
| 228 | extents.setValue(aspect * 1.0f, 1.0f,0); |
---|
| 229 | } else |
---|
| 230 | { |
---|
| 231 | aspect = m_glutScreenHeight / (btScalar)m_glutScreenWidth; |
---|
| 232 | extents.setValue(1.0f, aspect*1.f,0); |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | |
---|
| 236 | if (m_ortho) |
---|
| 237 | { |
---|
| 238 | // reset matrix |
---|
| 239 | glLoadIdentity(); |
---|
| 240 | |
---|
| 241 | |
---|
| 242 | extents *= m_cameraDistance; |
---|
| 243 | btVector3 lower = m_cameraTargetPosition - extents; |
---|
| 244 | btVector3 upper = m_cameraTargetPosition + extents; |
---|
| 245 | //gluOrtho2D(lower.x, upper.x, lower.y, upper.y); |
---|
| 246 | glOrtho(lower.getX(), upper.getX(), lower.getY(), upper.getY(),-1000,1000); |
---|
| 247 | |
---|
| 248 | glMatrixMode(GL_MODELVIEW); |
---|
| 249 | glLoadIdentity(); |
---|
| 250 | //glTranslatef(100,210,0); |
---|
| 251 | } else |
---|
| 252 | { |
---|
| 253 | if (m_glutScreenWidth > m_glutScreenHeight) |
---|
| 254 | { |
---|
| 255 | glFrustum (-aspect, aspect, -1.0, 1.0, 1.0, 10000.0); |
---|
| 256 | } else |
---|
| 257 | { |
---|
| 258 | glFrustum (-1.0, 1.0, -aspect, aspect, 1.0, 10000.0); |
---|
| 259 | } |
---|
| 260 | glMatrixMode(GL_MODELVIEW); |
---|
| 261 | glLoadIdentity(); |
---|
| 262 | gluLookAt(m_cameraPosition[0], m_cameraPosition[1], m_cameraPosition[2], |
---|
| 263 | m_cameraTargetPosition[0], m_cameraTargetPosition[1], m_cameraTargetPosition[2], |
---|
| 264 | m_cameraUp.getX(),m_cameraUp.getY(),m_cameraUp.getZ()); |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | |
---|
| 270 | |
---|
| 271 | const float STEPSIZE = 5; |
---|
| 272 | |
---|
| 273 | void LocalGui::stepLeft() |
---|
| 274 | { |
---|
| 275 | m_azi -= STEPSIZE; if (m_azi < 0) m_azi += 360; updateCamera(); |
---|
| 276 | } |
---|
| 277 | void LocalGui::stepRight() |
---|
| 278 | { |
---|
| 279 | m_azi += STEPSIZE; if (m_azi >= 360) m_azi -= 360; updateCamera(); |
---|
| 280 | } |
---|
| 281 | void LocalGui::stepFront() |
---|
| 282 | { |
---|
| 283 | m_ele += STEPSIZE; if (m_ele >= 360) m_ele -= 360; updateCamera(); |
---|
| 284 | } |
---|
| 285 | void LocalGui::stepBack() |
---|
| 286 | { |
---|
| 287 | m_ele -= STEPSIZE; if (m_ele < 0) m_ele += 360; updateCamera(); |
---|
| 288 | } |
---|
| 289 | void LocalGui::zoomIn() |
---|
| 290 | { |
---|
| 291 | m_cameraDistance -= 0.4; updateCamera(); |
---|
| 292 | if (m_cameraDistance < 0.1) |
---|
| 293 | m_cameraDistance = 0.1; |
---|
| 294 | |
---|
| 295 | } |
---|
| 296 | void LocalGui::zoomOut() |
---|
| 297 | { |
---|
| 298 | m_cameraDistance += 0.4; updateCamera(); |
---|
| 299 | |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | |
---|
| 303 | |
---|
| 304 | void LocalGui::reshape(int w, int h) |
---|
| 305 | { |
---|
| 306 | GLDebugResetFont(w,h); |
---|
| 307 | |
---|
| 308 | m_glutScreenWidth = w; |
---|
| 309 | m_glutScreenHeight = h; |
---|
| 310 | |
---|
| 311 | glViewport(0, 0, w, h); |
---|
| 312 | updateCamera(); |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | |
---|
| 316 | void LocalGui::keyboardCallback(unsigned char key, int x, int y) |
---|
| 317 | { |
---|
| 318 | (void)x; |
---|
| 319 | (void)y; |
---|
| 320 | |
---|
| 321 | m_lastKey = 0; |
---|
| 322 | |
---|
| 323 | #ifndef BT_NO_PROFILE |
---|
| 324 | if (key >= 0x31 && key <= 0x39) |
---|
| 325 | { |
---|
| 326 | int child = key-0x31; |
---|
| 327 | m_profileIterator->Enter_Child(child); |
---|
| 328 | } |
---|
| 329 | if (key==0x30) |
---|
| 330 | { |
---|
| 331 | m_profileIterator->Enter_Parent(); |
---|
| 332 | } |
---|
| 333 | #endif //BT_NO_PROFILE |
---|
| 334 | |
---|
| 335 | switch (key) |
---|
| 336 | { |
---|
| 337 | case 'q' : |
---|
| 338 | #ifdef BT_USE_FREEGLUT |
---|
| 339 | //return from glutMainLoop(), detect memory leaks etc. |
---|
| 340 | glutLeaveMainLoop(); |
---|
| 341 | #else |
---|
| 342 | exit(0); |
---|
| 343 | #endif |
---|
| 344 | break; |
---|
| 345 | |
---|
| 346 | case 'l' : stepLeft(); break; |
---|
| 347 | case 'r' : stepRight(); break; |
---|
| 348 | case 'f' : stepFront(); break; |
---|
| 349 | case 'b' : stepBack(); break; |
---|
| 350 | case 'z' : zoomIn(); break; |
---|
| 351 | case 'x' : zoomOut(); break; |
---|
| 352 | case 'i' : toggleIdle(); break; |
---|
| 353 | case 'g' : m_enableshadows=!m_enableshadows;break; |
---|
| 354 | case 'u' : m_shapeDrawer->enableTexture(!m_shapeDrawer->enableTexture(false));break; |
---|
| 355 | case 'h': |
---|
| 356 | if (m_debugMode & btIDebugDraw::DBG_NoHelpText) |
---|
| 357 | m_debugMode = m_debugMode & (~btIDebugDraw::DBG_NoHelpText); |
---|
| 358 | else |
---|
| 359 | m_debugMode |= btIDebugDraw::DBG_NoHelpText; |
---|
| 360 | break; |
---|
| 361 | |
---|
| 362 | case 'w': |
---|
| 363 | if (m_debugMode & btIDebugDraw::DBG_DrawWireframe) |
---|
| 364 | m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawWireframe); |
---|
| 365 | else |
---|
| 366 | m_debugMode |= btIDebugDraw::DBG_DrawWireframe; |
---|
| 367 | break; |
---|
| 368 | |
---|
| 369 | case 'p': |
---|
| 370 | if (m_debugMode & btIDebugDraw::DBG_ProfileTimings) |
---|
| 371 | m_debugMode = m_debugMode & (~btIDebugDraw::DBG_ProfileTimings); |
---|
| 372 | else |
---|
| 373 | m_debugMode |= btIDebugDraw::DBG_ProfileTimings; |
---|
| 374 | break; |
---|
| 375 | |
---|
| 376 | case 'm': |
---|
| 377 | if (m_debugMode & btIDebugDraw::DBG_EnableSatComparison) |
---|
| 378 | m_debugMode = m_debugMode & (~btIDebugDraw::DBG_EnableSatComparison); |
---|
| 379 | else |
---|
| 380 | m_debugMode |= btIDebugDraw::DBG_EnableSatComparison; |
---|
| 381 | break; |
---|
| 382 | |
---|
| 383 | case 'n': |
---|
| 384 | if (m_debugMode & btIDebugDraw::DBG_DisableBulletLCP) |
---|
| 385 | m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DisableBulletLCP); |
---|
| 386 | else |
---|
| 387 | m_debugMode |= btIDebugDraw::DBG_DisableBulletLCP; |
---|
| 388 | break; |
---|
| 389 | |
---|
| 390 | case 't' : |
---|
| 391 | if (m_debugMode & btIDebugDraw::DBG_DrawText) |
---|
| 392 | m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawText); |
---|
| 393 | else |
---|
| 394 | m_debugMode |= btIDebugDraw::DBG_DrawText; |
---|
| 395 | break; |
---|
| 396 | case 'y': |
---|
| 397 | if (m_debugMode & btIDebugDraw::DBG_DrawFeaturesText) |
---|
| 398 | m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawFeaturesText); |
---|
| 399 | else |
---|
| 400 | m_debugMode |= btIDebugDraw::DBG_DrawFeaturesText; |
---|
| 401 | break; |
---|
| 402 | case 'a': |
---|
| 403 | if (m_debugMode & btIDebugDraw::DBG_DrawAabb) |
---|
| 404 | m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawAabb); |
---|
| 405 | else |
---|
| 406 | m_debugMode |= btIDebugDraw::DBG_DrawAabb; |
---|
| 407 | break; |
---|
| 408 | case 'c' : |
---|
| 409 | if (m_debugMode & btIDebugDraw::DBG_DrawContactPoints) |
---|
| 410 | m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawContactPoints); |
---|
| 411 | else |
---|
| 412 | m_debugMode |= btIDebugDraw::DBG_DrawContactPoints; |
---|
| 413 | break; |
---|
| 414 | case 'C' : |
---|
| 415 | if (m_debugMode & btIDebugDraw::DBG_DrawConstraints) |
---|
| 416 | m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawConstraints); |
---|
| 417 | else |
---|
| 418 | m_debugMode |= btIDebugDraw::DBG_DrawConstraints; |
---|
| 419 | break; |
---|
| 420 | case 'L' : |
---|
| 421 | if (m_debugMode & btIDebugDraw::DBG_DrawConstraintLimits) |
---|
| 422 | m_debugMode = m_debugMode & (~btIDebugDraw::DBG_DrawConstraintLimits); |
---|
| 423 | else |
---|
| 424 | m_debugMode |= btIDebugDraw::DBG_DrawConstraintLimits; |
---|
| 425 | break; |
---|
| 426 | |
---|
| 427 | case 'd' : |
---|
| 428 | if (m_debugMode & btIDebugDraw::DBG_NoDeactivation) |
---|
| 429 | m_debugMode = m_debugMode & (~btIDebugDraw::DBG_NoDeactivation); |
---|
| 430 | else |
---|
| 431 | m_debugMode |= btIDebugDraw::DBG_NoDeactivation; |
---|
| 432 | if (m_debugMode & btIDebugDraw::DBG_NoDeactivation) |
---|
| 433 | { |
---|
| 434 | gDisableDeactivation = true; |
---|
| 435 | } else |
---|
| 436 | { |
---|
| 437 | gDisableDeactivation = false; |
---|
| 438 | } |
---|
| 439 | break; |
---|
| 440 | |
---|
| 441 | |
---|
| 442 | |
---|
| 443 | |
---|
| 444 | case 'o' : |
---|
| 445 | { |
---|
| 446 | m_ortho = !m_ortho;//m_stepping = !m_stepping; |
---|
| 447 | break; |
---|
| 448 | } |
---|
| 449 | case 's' : clientMoveAndDisplay(); break; |
---|
| 450 | // case ' ' : newRandom(); break; |
---|
| 451 | case ' ': |
---|
| 452 | clientResetScene(); |
---|
| 453 | break; |
---|
| 454 | case '1': |
---|
| 455 | { |
---|
| 456 | if (m_debugMode & btIDebugDraw::DBG_EnableCCD) |
---|
| 457 | m_debugMode = m_debugMode & (~btIDebugDraw::DBG_EnableCCD); |
---|
| 458 | else |
---|
| 459 | m_debugMode |= btIDebugDraw::DBG_EnableCCD; |
---|
| 460 | break; |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | case '.': |
---|
| 464 | { |
---|
| 465 | shootBox(getRayTo(x,y));//getCameraTargetPosition()); |
---|
| 466 | break; |
---|
| 467 | } |
---|
| 468 | |
---|
| 469 | case '+': |
---|
| 470 | { |
---|
| 471 | m_ShootBoxInitialSpeed += 10.f; |
---|
| 472 | break; |
---|
| 473 | } |
---|
| 474 | case '-': |
---|
| 475 | { |
---|
| 476 | m_ShootBoxInitialSpeed -= 10.f; |
---|
| 477 | break; |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | default: |
---|
| 481 | // std::cout << "unused key : " << key << std::endl; |
---|
| 482 | break; |
---|
| 483 | } |
---|
| 484 | |
---|
| 485 | if (getDynamicsWorld() && getDynamicsWorld()->getDebugDrawer()) |
---|
| 486 | getDynamicsWorld()->getDebugDrawer()->setDebugMode(m_debugMode); |
---|
| 487 | |
---|
| 488 | |
---|
| 489 | |
---|
| 490 | } |
---|
| 491 | |
---|
| 492 | void LocalGui::setDebugMode(int mode) |
---|
| 493 | { |
---|
| 494 | m_debugMode = mode; |
---|
| 495 | if (getDynamicsWorld() && getDynamicsWorld()->getDebugDrawer()) |
---|
| 496 | getDynamicsWorld()->getDebugDrawer()->setDebugMode(mode); |
---|
| 497 | } |
---|
| 498 | |
---|
| 499 | void LocalGui::moveAndDisplay() |
---|
| 500 | { |
---|
| 501 | if (!m_idle) |
---|
| 502 | clientMoveAndDisplay(); |
---|
| 503 | else |
---|
| 504 | displayCallback(); |
---|
| 505 | } |
---|
| 506 | |
---|
| 507 | |
---|
| 508 | /* |
---|
| 509 | void LocalGui::displayCallback() |
---|
| 510 | { |
---|
| 511 | } |
---|
| 512 | */ |
---|
| 513 | |
---|
| 514 | |
---|
| 515 | #define NUM_SPHERES_ON_DIAGONAL 9 |
---|
| 516 | |
---|
| 517 | void LocalGui::setShootBoxShape () |
---|
| 518 | { |
---|
| 519 | if (!m_shootBoxShape) |
---|
| 520 | { |
---|
| 521 | m_shootBoxShape = new btBoxShape(btVector3(.5f,.5f,.5f)); |
---|
| 522 | } |
---|
| 523 | } |
---|
| 524 | |
---|
| 525 | void LocalGui::shootBox(const btVector3& destination) |
---|
| 526 | { |
---|
| 527 | |
---|
| 528 | /*if (m_dynamicsWorld) |
---|
| 529 | { |
---|
| 530 | float mass = 1.f; |
---|
| 531 | btTransform startTransform; |
---|
| 532 | startTransform.setIdentity(); |
---|
| 533 | btVector3 camPos = getCameraPosition(); |
---|
| 534 | startTransform.setOrigin(camPos); |
---|
| 535 | |
---|
| 536 | setShootBoxShape (); |
---|
| 537 | |
---|
| 538 | btRigidBody* body = this->localCreateRigidBody(mass, startTransform,m_shootBoxShape); |
---|
| 539 | body->setLinearFactor(btVector3(1,1,1)); |
---|
| 540 | |
---|
| 541 | btVector3 linVel(destination[0]-camPos[0],destination[1]-camPos[1],destination[2]-camPos[2]); |
---|
| 542 | linVel.normalize(); |
---|
| 543 | linVel*=m_ShootBoxInitialSpeed; |
---|
| 544 | |
---|
| 545 | body->getWorldTransform().setOrigin(camPos); |
---|
| 546 | body->getWorldTransform().setRotation(btQuaternion(0,0,0,1)); |
---|
| 547 | body->setLinearVelocity(linVel); |
---|
| 548 | body->setAngularVelocity(btVector3(0,0,0)); |
---|
| 549 | body->setCcdMotionThreshold(1.); |
---|
| 550 | body->setCcdSweptSphereRadius(0.2f); |
---|
| 551 | |
---|
| 552 | } |
---|
| 553 | */ |
---|
| 554 | } |
---|
| 555 | |
---|
| 556 | |
---|
| 557 | int gPickingConstraintId = 0; |
---|
| 558 | btVector3 gOldPickingPos; |
---|
| 559 | btVector3 gHitPos(-1,-1,-1); |
---|
| 560 | float gOldPickingDist = 0.f; |
---|
| 561 | btRigidBody* pickedBody = 0;//for deactivation state |
---|
| 562 | |
---|
| 563 | |
---|
| 564 | btVector3 LocalGui::getRayTo(int x,int y) |
---|
| 565 | { |
---|
| 566 | if (m_ortho) |
---|
| 567 | { |
---|
| 568 | |
---|
| 569 | btScalar aspect; |
---|
| 570 | btVector3 extents; |
---|
| 571 | if (m_glutScreenWidth > m_glutScreenHeight) |
---|
| 572 | { |
---|
| 573 | aspect = m_glutScreenWidth / (btScalar)m_glutScreenHeight; |
---|
| 574 | extents.setValue(aspect * 1.0f, 1.0f,0); |
---|
| 575 | } else |
---|
| 576 | { |
---|
| 577 | aspect = m_glutScreenHeight / (btScalar)m_glutScreenWidth; |
---|
| 578 | extents.setValue(1.0f, aspect*1.f,0); |
---|
| 579 | } |
---|
| 580 | |
---|
| 581 | extents *= m_cameraDistance; |
---|
| 582 | btVector3 lower = m_cameraTargetPosition - extents; |
---|
| 583 | btVector3 upper = m_cameraTargetPosition + extents; |
---|
| 584 | |
---|
| 585 | btScalar u = x / btScalar(m_glutScreenWidth); |
---|
| 586 | btScalar v = (m_glutScreenHeight - y) / btScalar(m_glutScreenHeight); |
---|
| 587 | |
---|
| 588 | btVector3 p(0,0,0); |
---|
| 589 | p.setValue((1.0f - u) * lower.getX() + u * upper.getX(),(1.0f - v) * lower.getY() + v * upper.getY(),m_cameraTargetPosition.getZ()); |
---|
| 590 | return p; |
---|
| 591 | } |
---|
| 592 | |
---|
| 593 | float top = 1.f; |
---|
| 594 | float bottom = -1.f; |
---|
| 595 | float nearPlane = 1.f; |
---|
| 596 | float tanFov = (top-bottom)*0.5f / nearPlane; |
---|
| 597 | float fov = 2.0 * atanf (tanFov); |
---|
| 598 | |
---|
| 599 | btVector3 rayFrom = getCameraPosition(); |
---|
| 600 | btVector3 rayForward = (getCameraTargetPosition()-getCameraPosition()); |
---|
| 601 | rayForward.normalize(); |
---|
| 602 | float farPlane = 10000.f; |
---|
| 603 | rayForward*= farPlane; |
---|
| 604 | |
---|
| 605 | btVector3 rightOffset; |
---|
| 606 | btVector3 vertical = m_cameraUp; |
---|
| 607 | |
---|
| 608 | btVector3 hor; |
---|
| 609 | hor = rayForward.cross(vertical); |
---|
| 610 | hor.normalize(); |
---|
| 611 | vertical = hor.cross(rayForward); |
---|
| 612 | vertical.normalize(); |
---|
| 613 | |
---|
| 614 | float tanfov = tanf(0.5f*fov); |
---|
| 615 | |
---|
| 616 | |
---|
| 617 | hor *= 2.f * farPlane * tanfov; |
---|
| 618 | vertical *= 2.f * farPlane * tanfov; |
---|
| 619 | |
---|
| 620 | btScalar aspect; |
---|
| 621 | |
---|
| 622 | if (m_glutScreenWidth > m_glutScreenHeight) |
---|
| 623 | { |
---|
| 624 | aspect = m_glutScreenWidth / (btScalar)m_glutScreenHeight; |
---|
| 625 | |
---|
| 626 | hor*=aspect; |
---|
| 627 | } else |
---|
| 628 | { |
---|
| 629 | aspect = m_glutScreenHeight / (btScalar)m_glutScreenWidth; |
---|
| 630 | vertical*=aspect; |
---|
| 631 | } |
---|
| 632 | |
---|
| 633 | |
---|
| 634 | btVector3 rayToCenter = rayFrom + rayForward; |
---|
| 635 | btVector3 dHor = hor * 1.f/float(m_glutScreenWidth); |
---|
| 636 | btVector3 dVert = vertical * 1.f/float(m_glutScreenHeight); |
---|
| 637 | |
---|
| 638 | |
---|
| 639 | btVector3 rayTo = rayToCenter - 0.5f * hor + 0.5f * vertical; |
---|
| 640 | rayTo += x * dHor; |
---|
| 641 | rayTo -= y * dVert; |
---|
| 642 | return rayTo; |
---|
| 643 | } |
---|
| 644 | |
---|
| 645 | btScalar mousePickClamping = 30.f; |
---|
| 646 | |
---|
| 647 | |
---|
| 648 | void LocalGui::mouseFunc(int button, int state, int x, int y) |
---|
| 649 | { |
---|
| 650 | m_dynamicsWorld = m_env->getDynamicsWorld(); |
---|
| 651 | |
---|
| 652 | if (state == 0) |
---|
| 653 | { |
---|
| 654 | m_mouseButtons |= 1<<button; |
---|
| 655 | } else |
---|
| 656 | { |
---|
| 657 | m_mouseButtons = 0; |
---|
| 658 | } |
---|
| 659 | |
---|
| 660 | m_mouseOldX = x; |
---|
| 661 | m_mouseOldY = y; |
---|
| 662 | |
---|
| 663 | updateModifierKeys(); |
---|
| 664 | if ((m_modifierKeys& BT_ACTIVE_ALT) && (state==0)) |
---|
| 665 | { |
---|
| 666 | return; |
---|
| 667 | } |
---|
| 668 | |
---|
| 669 | //printf("button %i, state %i, x=%i,y=%i\n",button,state,x,y); |
---|
| 670 | //button 0, state 0 means left mouse down |
---|
| 671 | |
---|
| 672 | btVector3 rayTo = getRayTo(x,y); |
---|
| 673 | |
---|
| 674 | switch (button) |
---|
| 675 | { |
---|
| 676 | case 2: |
---|
| 677 | { |
---|
| 678 | if (state==0) |
---|
| 679 | { |
---|
| 680 | |
---|
| 681 | shootBox(rayTo); |
---|
| 682 | } |
---|
| 683 | break; |
---|
| 684 | }; |
---|
| 685 | case 1: |
---|
| 686 | { |
---|
| 687 | if (state==0) |
---|
| 688 | { |
---|
| 689 | |
---|
| 690 | } else |
---|
| 691 | { |
---|
| 692 | } |
---|
| 693 | break; |
---|
| 694 | } |
---|
| 695 | case 0: |
---|
| 696 | { |
---|
| 697 | if (state==0) |
---|
| 698 | { |
---|
| 699 | |
---|
| 700 | //add a point to point constraint for picking |
---|
| 701 | if (m_dynamicsWorld) |
---|
| 702 | { |
---|
| 703 | |
---|
| 704 | btVector3 rayFrom; |
---|
| 705 | if (m_ortho) |
---|
| 706 | { |
---|
| 707 | rayFrom = rayTo; |
---|
| 708 | rayFrom.setZ(-100.f); |
---|
| 709 | } else |
---|
| 710 | { |
---|
| 711 | rayFrom = m_cameraPosition; |
---|
| 712 | } |
---|
| 713 | |
---|
| 714 | btCollisionWorld::ClosestRayResultCallback rayCallback(rayFrom,rayTo); |
---|
| 715 | m_dynamicsWorld->rayTest(rayFrom,rayTo,rayCallback); |
---|
| 716 | if (rayCallback.hasHit()) |
---|
| 717 | { |
---|
| 718 | |
---|
| 719 | |
---|
| 720 | btRigidBody* body = btRigidBody::upcast(rayCallback.m_collisionObject); |
---|
| 721 | if (body) |
---|
| 722 | { |
---|
| 723 | //other exclusions? |
---|
| 724 | if (!(body->isStaticObject() || body->isKinematicObject())) |
---|
| 725 | { |
---|
| 726 | pickedBody = body; |
---|
| 727 | pickedBody->setActivationState(DISABLE_DEACTIVATION); |
---|
| 728 | |
---|
| 729 | |
---|
| 730 | btVector3 pickPos = rayCallback.m_hitPointWorld; |
---|
| 731 | printf("pickPos=%f,%f,%f\n",pickPos.getX(),pickPos.getY(),pickPos.getZ()); |
---|
| 732 | |
---|
| 733 | |
---|
| 734 | btVector3 localPivot = body->getCenterOfMassTransform().inverse() * pickPos; |
---|
| 735 | |
---|
| 736 | btPoint2PointConstraint* p2p = new btPoint2PointConstraint(*body,localPivot); |
---|
| 737 | p2p->m_setting.m_impulseClamp = mousePickClamping; |
---|
| 738 | |
---|
| 739 | m_dynamicsWorld->addConstraint(p2p); |
---|
| 740 | m_pickConstraint = p2p; |
---|
| 741 | |
---|
| 742 | //save mouse position for dragging |
---|
| 743 | gOldPickingPos = rayTo; |
---|
| 744 | gHitPos = pickPos; |
---|
| 745 | |
---|
| 746 | gOldPickingDist = (pickPos-rayFrom).length(); |
---|
| 747 | |
---|
| 748 | //very weak constraint for picking |
---|
| 749 | p2p->m_setting.m_tau = 0.1f; |
---|
| 750 | } |
---|
| 751 | } |
---|
| 752 | } |
---|
| 753 | } |
---|
| 754 | |
---|
| 755 | } else |
---|
| 756 | { |
---|
| 757 | |
---|
| 758 | if (m_pickConstraint && m_dynamicsWorld) |
---|
| 759 | { |
---|
| 760 | m_dynamicsWorld->removeConstraint(m_pickConstraint); |
---|
| 761 | delete m_pickConstraint; |
---|
| 762 | //printf("removed constraint %i",gPickingConstraintId); |
---|
| 763 | m_pickConstraint = 0; |
---|
| 764 | pickedBody->forceActivationState(ACTIVE_TAG); |
---|
| 765 | pickedBody->setDeactivationTime( 0.f ); |
---|
| 766 | pickedBody = 0; |
---|
| 767 | } |
---|
| 768 | |
---|
| 769 | |
---|
| 770 | } |
---|
| 771 | |
---|
| 772 | break; |
---|
| 773 | |
---|
| 774 | } |
---|
| 775 | default: |
---|
| 776 | { |
---|
| 777 | } |
---|
| 778 | } |
---|
| 779 | |
---|
| 780 | } |
---|
| 781 | |
---|
| 782 | void LocalGui::mouseMotionFunc(int x,int y) |
---|
| 783 | { |
---|
| 784 | |
---|
| 785 | if (m_pickConstraint) |
---|
| 786 | { |
---|
| 787 | //move the constraint pivot |
---|
| 788 | btPoint2PointConstraint* p2p = static_cast<btPoint2PointConstraint*>(m_pickConstraint); |
---|
| 789 | if (p2p) |
---|
| 790 | { |
---|
| 791 | //keep it at the same picking distance |
---|
| 792 | |
---|
| 793 | btVector3 newRayTo = getRayTo(x,y); |
---|
| 794 | btVector3 rayFrom; |
---|
| 795 | btVector3 oldPivotInB = p2p->getPivotInB(); |
---|
| 796 | btVector3 newPivotB; |
---|
| 797 | if (m_ortho) |
---|
| 798 | { |
---|
| 799 | newPivotB = oldPivotInB; |
---|
| 800 | newPivotB.setX(newRayTo.getX()); |
---|
| 801 | newPivotB.setY(newRayTo.getY()); |
---|
| 802 | } else |
---|
| 803 | { |
---|
| 804 | rayFrom = m_cameraPosition; |
---|
| 805 | btVector3 dir = newRayTo-rayFrom; |
---|
| 806 | dir.normalize(); |
---|
| 807 | dir *= gOldPickingDist; |
---|
| 808 | |
---|
| 809 | newPivotB = rayFrom + dir; |
---|
| 810 | } |
---|
| 811 | |
---|
| 812 | |
---|
| 813 | |
---|
| 814 | p2p->setPivotB(newPivotB); |
---|
| 815 | } |
---|
| 816 | |
---|
| 817 | } |
---|
| 818 | |
---|
| 819 | float dx, dy; |
---|
| 820 | dx = x - m_mouseOldX; |
---|
| 821 | dy = y - m_mouseOldY; |
---|
| 822 | |
---|
| 823 | |
---|
| 824 | ///only if ALT key is pressed (Maya style) |
---|
| 825 | if (m_modifierKeys& BT_ACTIVE_ALT) |
---|
| 826 | { |
---|
| 827 | if(m_mouseButtons & 2) |
---|
| 828 | { |
---|
| 829 | btVector3 hor = getRayTo(0,0)-getRayTo(1,0); |
---|
| 830 | btVector3 vert = getRayTo(0,0)-getRayTo(0,1); |
---|
| 831 | btScalar multiplierX = 0.01; |
---|
| 832 | btScalar multiplierY = 0.01; |
---|
| 833 | if (m_ortho) |
---|
| 834 | { |
---|
| 835 | multiplierX = 1; |
---|
| 836 | multiplierY = 1; |
---|
| 837 | } |
---|
| 838 | |
---|
| 839 | |
---|
| 840 | m_cameraTargetPosition += hor* dx * multiplierX; |
---|
| 841 | m_cameraTargetPosition += vert* dy * multiplierY; |
---|
| 842 | } |
---|
| 843 | |
---|
| 844 | if(m_mouseButtons & (2 << 2) && m_mouseButtons & 1) |
---|
| 845 | { |
---|
| 846 | } |
---|
| 847 | else if(m_mouseButtons & 1) |
---|
| 848 | { |
---|
| 849 | m_azi += dx * 0.2; |
---|
| 850 | m_azi = fmodf(m_azi, 180.f); |
---|
| 851 | m_ele += dy * 0.2; |
---|
| 852 | m_ele = fmodf(m_ele, 180.f); |
---|
| 853 | } |
---|
| 854 | else if(m_mouseButtons & 4) |
---|
| 855 | { |
---|
| 856 | m_cameraDistance -= dy * 0.2f; |
---|
| 857 | if (m_cameraDistance<0.1) |
---|
| 858 | m_cameraDistance = 0.1; |
---|
| 859 | |
---|
| 860 | |
---|
| 861 | } |
---|
| 862 | } |
---|
| 863 | |
---|
| 864 | |
---|
| 865 | m_mouseOldX = x; |
---|
| 866 | m_mouseOldY = y; |
---|
| 867 | updateCamera(); |
---|
| 868 | } |
---|
| 869 | |
---|
| 870 | //See http://www.lighthouse3d.com/opengl/glut/index.php?bmpfontortho |
---|
| 871 | void LocalGui::setOrthographicProjection() |
---|
| 872 | { |
---|
| 873 | |
---|
| 874 | // switch to projection mode |
---|
| 875 | glMatrixMode(GL_PROJECTION); |
---|
| 876 | |
---|
| 877 | // save previous matrix which contains the |
---|
| 878 | //settings for the perspective projection |
---|
| 879 | glPushMatrix(); |
---|
| 880 | // reset matrix |
---|
| 881 | glLoadIdentity(); |
---|
| 882 | // set a 2D orthographic projection |
---|
| 883 | gluOrtho2D(0, m_glutScreenWidth, 0, m_glutScreenHeight); |
---|
| 884 | glMatrixMode(GL_MODELVIEW); |
---|
| 885 | glLoadIdentity(); |
---|
| 886 | |
---|
| 887 | // invert the y axis, down is positive |
---|
| 888 | glScalef(1, -1, 1); |
---|
| 889 | // mover the origin from the bottom left corner |
---|
| 890 | // to the upper left corner |
---|
| 891 | glTranslatef(0, -m_glutScreenHeight, 0); |
---|
| 892 | |
---|
| 893 | } |
---|
| 894 | |
---|
| 895 | void LocalGui::resetPerspectiveProjection() |
---|
| 896 | { |
---|
| 897 | |
---|
| 898 | glMatrixMode(GL_PROJECTION); |
---|
| 899 | glPopMatrix(); |
---|
| 900 | glMatrixMode(GL_MODELVIEW); |
---|
| 901 | updateCamera(); |
---|
| 902 | } |
---|
| 903 | |
---|
| 904 | |
---|
| 905 | |
---|
| 906 | |
---|
| 907 | extern CProfileIterator * m_profileIterator; |
---|
| 908 | |
---|
| 909 | void LocalGui::displayProfileString(int xOffset,int yStart,char* message) |
---|
| 910 | { |
---|
| 911 | glRasterPos3f(xOffset,yStart,0); |
---|
| 912 | GLDebugDrawString(xOffset,yStart,message); |
---|
| 913 | } |
---|
| 914 | |
---|
| 915 | |
---|
| 916 | void LocalGui::showProfileInfo(int& xOffset,int& yStart, int yIncr) |
---|
| 917 | { |
---|
| 918 | #ifndef BT_NO_PROFILE |
---|
| 919 | |
---|
| 920 | static double time_since_reset = 0.f; |
---|
| 921 | if (!m_idle) |
---|
| 922 | { |
---|
| 923 | time_since_reset = CProfileManager::Get_Time_Since_Reset(); |
---|
| 924 | } |
---|
| 925 | |
---|
| 926 | |
---|
| 927 | { |
---|
| 928 | //recompute profiling data, and store profile strings |
---|
| 929 | |
---|
| 930 | char blockTime[128]; |
---|
| 931 | |
---|
| 932 | double totalTime = 0; |
---|
| 933 | |
---|
| 934 | int frames_since_reset = CProfileManager::Get_Frame_Count_Since_Reset(); |
---|
| 935 | |
---|
| 936 | m_profileIterator->First(); |
---|
| 937 | |
---|
| 938 | double parent_time = m_profileIterator->Is_Root() ? time_since_reset : m_profileIterator->Get_Current_Parent_Total_Time(); |
---|
| 939 | |
---|
| 940 | { |
---|
| 941 | sprintf(blockTime,"--- Profiling: %s (total running time: %.3f ms) ---", m_profileIterator->Get_Current_Parent_Name(), parent_time ); |
---|
| 942 | displayProfileString(xOffset,yStart,blockTime); |
---|
| 943 | yStart += yIncr; |
---|
| 944 | sprintf(blockTime,"press number (1,2...) to display child timings, or 0 to go up to parent" ); |
---|
| 945 | displayProfileString(xOffset,yStart,blockTime); |
---|
| 946 | yStart += yIncr; |
---|
| 947 | |
---|
| 948 | } |
---|
| 949 | |
---|
| 950 | |
---|
| 951 | double accumulated_time = 0.f; |
---|
| 952 | |
---|
| 953 | for (int i = 0; !m_profileIterator->Is_Done(); m_profileIterator->Next()) |
---|
| 954 | { |
---|
| 955 | double current_total_time = m_profileIterator->Get_Current_Total_Time(); |
---|
| 956 | accumulated_time += current_total_time; |
---|
| 957 | double fraction = parent_time > SIMD_EPSILON ? (current_total_time / parent_time) * 100 : 0.f; |
---|
| 958 | |
---|
| 959 | sprintf(blockTime,"%d -- %s (%.2f %%) :: %.3f ms / frame (%d calls)", |
---|
| 960 | ++i, m_profileIterator->Get_Current_Name(), fraction, |
---|
| 961 | (current_total_time / (double)frames_since_reset),m_profileIterator->Get_Current_Total_Calls()); |
---|
| 962 | displayProfileString(xOffset,yStart,blockTime); |
---|
| 963 | yStart += yIncr; |
---|
| 964 | totalTime += current_total_time; |
---|
| 965 | } |
---|
| 966 | |
---|
| 967 | sprintf(blockTime,"%s (%.3f %%) :: %.3f ms", "Unaccounted", |
---|
| 968 | // (min(0, time_since_reset - totalTime) / time_since_reset) * 100); |
---|
| 969 | parent_time > SIMD_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f, parent_time - accumulated_time); |
---|
| 970 | |
---|
| 971 | displayProfileString(xOffset,yStart,blockTime); |
---|
| 972 | yStart += yIncr; |
---|
| 973 | |
---|
| 974 | |
---|
| 975 | |
---|
| 976 | sprintf(blockTime,"-------------------------------------------------"); |
---|
| 977 | displayProfileString(xOffset,yStart,blockTime); |
---|
| 978 | yStart += yIncr; |
---|
| 979 | |
---|
| 980 | } |
---|
| 981 | #endif//BT_NO_PROFILE |
---|
| 982 | } |
---|
| 983 | |
---|
| 984 | |
---|
| 985 | void LocalGui::renderscene(int pass) |
---|
| 986 | { |
---|
| 987 | btScalar m[16]; |
---|
| 988 | btMatrix3x3 rot;rot.setIdentity(); |
---|
| 989 | const int numObjects=m_dynamicsWorld->getNumCollisionObjects(); |
---|
| 990 | btVector3 wireColor(1,0,0); |
---|
| 991 | for(int i=0;i<numObjects;i++) |
---|
| 992 | { |
---|
| 993 | btCollisionObject* colObj=m_dynamicsWorld->getCollisionObjectArray()[i]; |
---|
| 994 | btRigidBody* body=btRigidBody::upcast(colObj); |
---|
| 995 | if(body&&body->getMotionState()) |
---|
| 996 | { |
---|
| 997 | btDefaultMotionState* myMotionState = (btDefaultMotionState*)body->getMotionState(); |
---|
| 998 | myMotionState->m_graphicsWorldTrans.getOpenGLMatrix(m); |
---|
| 999 | rot=myMotionState->m_graphicsWorldTrans.getBasis(); |
---|
| 1000 | } |
---|
| 1001 | else |
---|
| 1002 | { |
---|
| 1003 | colObj->getWorldTransform().getOpenGLMatrix(m); |
---|
| 1004 | rot=colObj->getWorldTransform().getBasis(); |
---|
| 1005 | } |
---|
| 1006 | btVector3 wireColor(1.f,1.0f,0.5f); //wants deactivation |
---|
| 1007 | if(i&1) wireColor=btVector3(0.f,0.0f,1.f); |
---|
| 1008 | ///color differently for active, sleeping, wantsdeactivation states |
---|
| 1009 | if (colObj->getActivationState() == 1) //active |
---|
| 1010 | { |
---|
| 1011 | if (i & 1) |
---|
| 1012 | { |
---|
| 1013 | wireColor += btVector3 (1.f,0.f,0.f); |
---|
| 1014 | } |
---|
| 1015 | else |
---|
| 1016 | { |
---|
| 1017 | wireColor += btVector3 (.5f,0.f,0.f); |
---|
| 1018 | } |
---|
| 1019 | } |
---|
| 1020 | if(colObj->getActivationState()==2) //ISLAND_SLEEPING |
---|
| 1021 | { |
---|
| 1022 | if(i&1) |
---|
| 1023 | { |
---|
| 1024 | wireColor += btVector3 (0.f,1.f, 0.f); |
---|
| 1025 | } |
---|
| 1026 | else |
---|
| 1027 | { |
---|
| 1028 | wireColor += btVector3 (0.f,0.5f,0.f); |
---|
| 1029 | } |
---|
| 1030 | } |
---|
| 1031 | |
---|
| 1032 | btVector3 aabbMin,aabbMax; |
---|
| 1033 | m_dynamicsWorld->getBroadphase()->getBroadphaseAabb(aabbMin,aabbMax); |
---|
| 1034 | |
---|
| 1035 | aabbMin-=btVector3(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT); |
---|
| 1036 | aabbMax+=btVector3(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT); |
---|
| 1037 | // printf("aabbMin=(%f,%f,%f)\n",aabbMin.getX(),aabbMin.getY(),aabbMin.getZ()); |
---|
| 1038 | // printf("aabbMax=(%f,%f,%f)\n",aabbMax.getX(),aabbMax.getY(),aabbMax.getZ()); |
---|
| 1039 | // m_dynamicsWorld->getDebugDrawer()->drawAabb(aabbMin,aabbMax,btVector3(1,1,1)); |
---|
| 1040 | |
---|
| 1041 | |
---|
| 1042 | switch(pass) |
---|
| 1043 | { |
---|
| 1044 | case 0: m_shapeDrawer->drawOpenGL(m,colObj->getCollisionShape(),wireColor,getDebugMode(),aabbMin,aabbMax);break; |
---|
| 1045 | case 1: m_shapeDrawer->drawShadow(m,m_sundirection*rot,colObj->getCollisionShape(),aabbMin,aabbMax);break; |
---|
| 1046 | case 2: m_shapeDrawer->drawOpenGL(m,colObj->getCollisionShape(),wireColor*0.3,0,aabbMin,aabbMax);break; |
---|
| 1047 | } |
---|
| 1048 | } |
---|
| 1049 | } |
---|
| 1050 | |
---|
| 1051 | // |
---|
| 1052 | void LocalGui::renderme() |
---|
| 1053 | { |
---|
| 1054 | m_dynamicsWorld = m_env |
---|
| 1055 | ->getDynamicsWorld(); |
---|
| 1056 | |
---|
| 1057 | init |
---|
| 1058 | (); |
---|
| 1059 | |
---|
| 1060 | updateCamera(); |
---|
| 1061 | |
---|
| 1062 | if (m_dynamicsWorld) |
---|
| 1063 | { |
---|
| 1064 | if(m_enableshadows) |
---|
| 1065 | { |
---|
| 1066 | glClear(GL_STENCIL_BUFFER_BIT); |
---|
| 1067 | glEnable(GL_CULL_FACE); |
---|
| 1068 | renderscene(0); |
---|
| 1069 | |
---|
| 1070 | glDisable(GL_LIGHTING); |
---|
| 1071 | glDepthMask(GL_FALSE); |
---|
| 1072 | glDepthFunc(GL_LEQUAL); |
---|
| 1073 | glEnable(GL_STENCIL_TEST); |
---|
| 1074 | glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE); |
---|
| 1075 | glStencilFunc(GL_ALWAYS,1,0xFFFFFFFFL); |
---|
| 1076 | glFrontFace(GL_CCW); |
---|
| 1077 | glStencilOp(GL_KEEP,GL_KEEP,GL_INCR); |
---|
| 1078 | renderscene(1); |
---|
| 1079 | glFrontFace(GL_CW); |
---|
| 1080 | glStencilOp(GL_KEEP,GL_KEEP,GL_DECR); |
---|
| 1081 | renderscene(1); |
---|
| 1082 | glFrontFace(GL_CCW); |
---|
| 1083 | |
---|
| 1084 | glPolygonMode(GL_FRONT,GL_FILL); |
---|
| 1085 | glPolygonMode(GL_BACK,GL_FILL); |
---|
| 1086 | glShadeModel(GL_SMOOTH); |
---|
| 1087 | glEnable(GL_DEPTH_TEST); |
---|
| 1088 | glDepthFunc(GL_LESS); |
---|
| 1089 | glEnable(GL_LIGHTING); |
---|
| 1090 | glDepthMask(GL_TRUE); |
---|
| 1091 | glCullFace(GL_BACK); |
---|
| 1092 | glFrontFace(GL_CCW); |
---|
| 1093 | glEnable(GL_CULL_FACE); |
---|
| 1094 | glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE); |
---|
| 1095 | |
---|
| 1096 | glDepthFunc(GL_LEQUAL); |
---|
| 1097 | glStencilFunc( GL_NOTEQUAL, 0, 0xFFFFFFFFL ); |
---|
| 1098 | glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP ); |
---|
| 1099 | glDisable(GL_LIGHTING); |
---|
| 1100 | renderscene(2); |
---|
| 1101 | glEnable(GL_LIGHTING); |
---|
| 1102 | glDepthFunc(GL_LESS); |
---|
| 1103 | glDisable(GL_STENCIL_TEST); |
---|
| 1104 | glDisable(GL_CULL_FACE); |
---|
| 1105 | } |
---|
| 1106 | else |
---|
| 1107 | { |
---|
| 1108 | glDisable(GL_CULL_FACE); |
---|
| 1109 | renderscene(0); |
---|
| 1110 | } |
---|
| 1111 | |
---|
| 1112 | int xOffset = 10; |
---|
| 1113 | int yStart = 20; |
---|
| 1114 | int yIncr = 20; |
---|
| 1115 | char buf[124]; |
---|
| 1116 | |
---|
| 1117 | glDisable(GL_LIGHTING); |
---|
| 1118 | glColor3f(0, 0, 0); |
---|
| 1119 | |
---|
| 1120 | if ((m_debugMode & btIDebugDraw::DBG_NoHelpText)==0) |
---|
| 1121 | { |
---|
| 1122 | setOrthographicProjection(); |
---|
| 1123 | |
---|
| 1124 | showProfileInfo(xOffset,yStart,yIncr); |
---|
| 1125 | |
---|
| 1126 | #ifdef USE_QUICKPROF |
---|
| 1127 | |
---|
| 1128 | |
---|
| 1129 | if ( getDebugMode() & btIDebugDraw::DBG_ProfileTimings) |
---|
| 1130 | { |
---|
| 1131 | static int counter = 0; |
---|
| 1132 | counter++; |
---|
| 1133 | std::map<std::string, hidden::ProfileBlock*>::iterator iter; |
---|
| 1134 | for (iter = btProfiler::mProfileBlocks.begin(); iter != btProfiler::mProfileBlocks.end(); ++iter) |
---|
| 1135 | { |
---|
| 1136 | char blockTime[128]; |
---|
| 1137 | sprintf(blockTime, "%s: %lf",&((*iter).first[0]),btProfiler::getBlockTime((*iter).first, btProfiler::BLOCK_CYCLE_SECONDS));//BLOCK_TOTAL_PERCENT)); |
---|
| 1138 | glRasterPos3f(xOffset,yStart,0); |
---|
| 1139 | GLDebugDrawString(BMF_GetFont(BMF_kHelvetica10),blockTime); |
---|
| 1140 | yStart += yIncr; |
---|
| 1141 | |
---|
| 1142 | } |
---|
| 1143 | |
---|
| 1144 | } |
---|
| 1145 | #endif //USE_QUICKPROF |
---|
| 1146 | |
---|
| 1147 | |
---|
| 1148 | sprintf(buf,"mouse to interact"); |
---|
| 1149 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1150 | yStart += yIncr; |
---|
| 1151 | |
---|
| 1152 | sprintf(buf,"ALT + mouse to move camera"); |
---|
| 1153 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1154 | yStart += yIncr; |
---|
| 1155 | |
---|
| 1156 | sprintf(buf,"space to reset"); |
---|
| 1157 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1158 | yStart += yIncr; |
---|
| 1159 | |
---|
| 1160 | sprintf(buf,"cursor keys and z,x to navigate"); |
---|
| 1161 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1162 | yStart += yIncr; |
---|
| 1163 | |
---|
| 1164 | sprintf(buf,"i to toggle simulation, s single step"); |
---|
| 1165 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1166 | yStart += yIncr; |
---|
| 1167 | |
---|
| 1168 | sprintf(buf,"q to quit"); |
---|
| 1169 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1170 | yStart += yIncr; |
---|
| 1171 | |
---|
| 1172 | sprintf(buf,". to shoot box"); |
---|
| 1173 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1174 | yStart += yIncr; |
---|
| 1175 | |
---|
| 1176 | // not yet hooked up again after refactoring... |
---|
| 1177 | |
---|
| 1178 | sprintf(buf,"d to toggle deactivation"); |
---|
| 1179 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1180 | yStart += yIncr; |
---|
| 1181 | |
---|
| 1182 | |
---|
| 1183 | sprintf(buf,"g to toggle mesh animation (ConcaveDemo)"); |
---|
| 1184 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1185 | yStart += yIncr; |
---|
| 1186 | |
---|
| 1187 | |
---|
| 1188 | sprintf(buf,"h to toggle help text"); |
---|
| 1189 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1190 | yStart += yIncr; |
---|
| 1191 | |
---|
| 1192 | sprintf(buf,"o to toggle orthogonal/perspective view"); |
---|
| 1193 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1194 | yStart += yIncr; |
---|
| 1195 | |
---|
| 1196 | |
---|
| 1197 | //bool useBulletLCP = !(getDebugMode() & btIDebugDraw::DBG_DisableBulletLCP); |
---|
| 1198 | //bool useCCD = (getDebugMode() & btIDebugDraw::DBG_EnableCCD); |
---|
| 1199 | //glRasterPos3f(xOffset,yStart,0); |
---|
| 1200 | //sprintf(buf,"1 CCD mode (adhoc) = %i",useCCD); |
---|
| 1201 | //GLDebugDrawString(BMF_GetFont(BMF_kHelvetica10),buf); |
---|
| 1202 | //yStart += yIncr; |
---|
| 1203 | |
---|
| 1204 | |
---|
| 1205 | |
---|
| 1206 | sprintf(buf,"+- shooting speed = %10.2f",m_ShootBoxInitialSpeed); |
---|
| 1207 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1208 | yStart += yIncr; |
---|
| 1209 | |
---|
| 1210 | #ifdef SHOW_NUM_DEEP_PENETRATIONS |
---|
| 1211 | |
---|
| 1212 | |
---|
| 1213 | sprintf(buf,"gNumDeepPenetrationChecks = %d",gNumDeepPenetrationChecks); |
---|
| 1214 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1215 | yStart += yIncr; |
---|
| 1216 | |
---|
| 1217 | sprintf(buf,"gNumGjkChecks= %d",gNumGjkChecks); |
---|
| 1218 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1219 | yStart += yIncr; |
---|
| 1220 | |
---|
| 1221 | sprintf(buf,"gNumClampedCcdMotions = %d",gNumClampedCcdMotions); |
---|
| 1222 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1223 | yStart += yIncr; |
---|
| 1224 | |
---|
| 1225 | sprintf(buf,"gNumSplitImpulseRecoveries= %d",gNumSplitImpulseRecoveries); |
---|
| 1226 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1227 | yStart += yIncr; |
---|
| 1228 | |
---|
| 1229 | sprintf(buf,"gNumAlignedAllocs = %d",gNumAlignedAllocs); |
---|
| 1230 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1231 | yStart += yIncr; |
---|
| 1232 | |
---|
| 1233 | sprintf(buf,"gNumAlignedFree= %d",gNumAlignedFree); |
---|
| 1234 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1235 | yStart += yIncr; |
---|
| 1236 | |
---|
| 1237 | sprintf(buf,"# alloc-free = %d",gNumAlignedAllocs-gNumAlignedFree); |
---|
| 1238 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1239 | yStart += yIncr; |
---|
| 1240 | |
---|
| 1241 | //enable BT_DEBUG_MEMORY_ALLOCATIONS define in Bullet/src/LinearMath/btAlignedAllocator.h for memory leak detection |
---|
| 1242 | #ifdef BT_DEBUG_MEMORY_ALLOCATIONS |
---|
| 1243 | glRasterPos3f(xOffset,yStart,0); |
---|
| 1244 | sprintf(buf,"gTotalBytesAlignedAllocs = %d",gTotalBytesAlignedAllocs); |
---|
| 1245 | GLDebugDrawString(BMF_GetFont(BMF_kHelvetica10),buf); |
---|
| 1246 | yStart += yIncr; |
---|
| 1247 | #endif //BT_DEBUG_MEMORY_ALLOCATIONS |
---|
| 1248 | |
---|
| 1249 | if (getDynamicsWorld()) |
---|
| 1250 | { |
---|
| 1251 | glRasterPos3f(xOffset,yStart,0); |
---|
| 1252 | sprintf(buf,"# objects = %d",getDynamicsWorld()->getNumCollisionObjects()); |
---|
| 1253 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1254 | yStart += yIncr; |
---|
| 1255 | glRasterPos3f(xOffset,yStart,0); |
---|
| 1256 | sprintf(buf,"# pairs = %d",getDynamicsWorld()->getBroadphase()->getOverlappingPairCache()->getNumOverlappingPairs()); |
---|
| 1257 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1258 | yStart += yIncr; |
---|
| 1259 | sprintf(buf,"# hitPos = %f,%f,%f",gHitPos.getX(),gHitPos.getY(),gHitPos.getZ()); |
---|
| 1260 | GLDebugDrawString(xOffset,yStart,buf); |
---|
| 1261 | yStart += yIncr; |
---|
| 1262 | |
---|
| 1263 | } |
---|
| 1264 | |
---|
| 1265 | |
---|
| 1266 | #endif //SHOW_NUM_DEEP_PENETRATIONS |
---|
| 1267 | |
---|
| 1268 | resetPerspectiveProjection(); |
---|
| 1269 | } |
---|
| 1270 | |
---|
| 1271 | glEnable(GL_LIGHTING); |
---|
| 1272 | |
---|
| 1273 | |
---|
| 1274 | } |
---|
| 1275 | |
---|
| 1276 | updateCamera(); |
---|
| 1277 | |
---|
| 1278 | } |
---|
| 1279 | #include "BulletCollision/BroadphaseCollision/btAxisSweep3.h" |
---|
| 1280 | |
---|
| 1281 | void LocalGui::clientResetScene() |
---|
| 1282 | { |
---|
| 1283 | m_dynamicsWorld = m_env |
---|
| 1284 | ->getDynamicsWorld(); |
---|
| 1285 | |
---|
| 1286 | #ifdef SHOW_NUM_DEEP_PENETRATIONS |
---|
| 1287 | gNumDeepPenetrationChecks = 0; |
---|
| 1288 | gNumGjkChecks = 0; |
---|
| 1289 | #endif //SHOW_NUM_DEEP_PENETRATIONS |
---|
| 1290 | |
---|
| 1291 | gNumClampedCcdMotions = 0; |
---|
| 1292 | int numObjects = 0; |
---|
| 1293 | int i; |
---|
| 1294 | |
---|
| 1295 | if (m_dynamicsWorld) |
---|
| 1296 | { |
---|
| 1297 | numObjects = m_dynamicsWorld->getNumCollisionObjects(); |
---|
| 1298 | |
---|
| 1299 | ///create a copy of the array, not a reference! |
---|
| 1300 | btCollisionObjectArray copyArray = m_dynamicsWorld->getCollisionObjectArray(); |
---|
| 1301 | |
---|
| 1302 | for (i=0;i<numObjects;i++) |
---|
| 1303 | { |
---|
| 1304 | btCollisionObject* colObj = copyArray[i]; |
---|
| 1305 | btRigidBody* body = btRigidBody::upcast(colObj); |
---|
| 1306 | if (body) |
---|
| 1307 | { |
---|
| 1308 | if (body->getMotionState()) |
---|
| 1309 | { |
---|
| 1310 | btDefaultMotionState* myMotionState = (btDefaultMotionState*)body->getMotionState(); |
---|
| 1311 | myMotionState->m_graphicsWorldTrans = myMotionState->m_startWorldTrans; |
---|
| 1312 | body->setCenterOfMassTransform( myMotionState->m_graphicsWorldTrans ); |
---|
| 1313 | colObj->setInterpolationWorldTransform( myMotionState->m_startWorldTrans ); |
---|
| 1314 | colObj->forceActivationState(ACTIVE_TAG); |
---|
| 1315 | colObj->activate(); |
---|
| 1316 | colObj->setDeactivationTime(0); |
---|
| 1317 | //colObj->setActivationState(WANTS_DEACTIVATION); |
---|
| 1318 | } |
---|
| 1319 | //removed cached contact points (this is not necessary if all objects have been removed from the dynamics world) |
---|
| 1320 | //m_dynamicsWorld->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(colObj->getBroadphaseHandle(),getDynamicsWorld()->getDispatcher()); |
---|
| 1321 | |
---|
| 1322 | btRigidBody* body = btRigidBody::upcast(colObj); |
---|
| 1323 | if (body && !body->isStaticObject()) |
---|
| 1324 | { |
---|
| 1325 | btRigidBody::upcast(colObj)->setLinearVelocity(btVector3(0,0,0)); |
---|
| 1326 | btRigidBody::upcast(colObj)->setAngularVelocity(btVector3(0,0,0)); |
---|
| 1327 | } |
---|
| 1328 | } |
---|
| 1329 | |
---|
| 1330 | } |
---|
| 1331 | |
---|
| 1332 | ///reset some internal cached data in the broadphase |
---|
| 1333 | m_dynamicsWorld->getBroadphase()->resetPool(getDynamicsWorld()->getDispatcher()); |
---|
| 1334 | m_dynamicsWorld->getConstraintSolver()->reset(); |
---|
| 1335 | |
---|
| 1336 | } |
---|
| 1337 | |
---|
| 1338 | } |
---|
| 1339 | |
---|
| 1340 | void LocalGui::updateModifierKeys() |
---|
| 1341 | { |
---|
| 1342 | m_modifierKeys = 0; |
---|
| 1343 | if (glutGetModifiers() & GLUT_ACTIVE_ALT) |
---|
| 1344 | m_modifierKeys |= BT_ACTIVE_ALT; |
---|
| 1345 | |
---|
| 1346 | if (glutGetModifiers() & GLUT_ACTIVE_CTRL) |
---|
| 1347 | m_modifierKeys |= BT_ACTIVE_CTRL; |
---|
| 1348 | |
---|
| 1349 | if (glutGetModifiers() & GLUT_ACTIVE_SHIFT) |
---|
| 1350 | m_modifierKeys |= BT_ACTIVE_SHIFT; |
---|
| 1351 | } |
---|
| 1352 | |
---|
| 1353 | void LocalGui::specialKeyboard(int key, int x, int y) |
---|
| 1354 | { |
---|
| 1355 | m_dynamicsWorld = m_env |
---|
| 1356 | ->getDynamicsWorld(); |
---|
| 1357 | |
---|
| 1358 | (void)x; |
---|
| 1359 | (void)y; |
---|
| 1360 | |
---|
| 1361 | switch (key) |
---|
| 1362 | { |
---|
| 1363 | case GLUT_KEY_F1: |
---|
| 1364 | { |
---|
| 1365 | |
---|
| 1366 | break; |
---|
| 1367 | } |
---|
| 1368 | |
---|
| 1369 | case GLUT_KEY_F2: |
---|
| 1370 | { |
---|
| 1371 | |
---|
| 1372 | break; |
---|
| 1373 | } |
---|
| 1374 | |
---|
| 1375 | |
---|
| 1376 | case GLUT_KEY_END: |
---|
| 1377 | { |
---|
| 1378 | int numObj = getDynamicsWorld()->getNumCollisionObjects(); |
---|
| 1379 | if (numObj) |
---|
| 1380 | { |
---|
| 1381 | btCollisionObject* obj = getDynamicsWorld()->getCollisionObjectArray()[numObj-1]; |
---|
| 1382 | |
---|
| 1383 | getDynamicsWorld()->removeCollisionObject(obj); |
---|
| 1384 | btRigidBody* body = btRigidBody::upcast(obj); |
---|
| 1385 | if (body && body->getMotionState()) |
---|
| 1386 | { |
---|
| 1387 | delete body->getMotionState(); |
---|
| 1388 | } |
---|
| 1389 | delete obj; |
---|
| 1390 | |
---|
| 1391 | |
---|
| 1392 | } |
---|
| 1393 | break; |
---|
| 1394 | } |
---|
| 1395 | case GLUT_KEY_LEFT : stepLeft(); break; |
---|
| 1396 | case GLUT_KEY_RIGHT : stepRight(); break; |
---|
| 1397 | case GLUT_KEY_UP : stepFront(); break; |
---|
| 1398 | case GLUT_KEY_DOWN : stepBack(); break; |
---|
| 1399 | case GLUT_KEY_PAGE_UP : zoomIn(); break; |
---|
| 1400 | case GLUT_KEY_PAGE_DOWN : zoomOut(); break; |
---|
| 1401 | case GLUT_KEY_HOME : toggleIdle(); break; |
---|
| 1402 | default: |
---|
| 1403 | // std::cout << "unused (special) key : " << key << std::endl; |
---|
| 1404 | break; |
---|
| 1405 | } |
---|
| 1406 | |
---|
| 1407 | glutPostRedisplay(); |
---|
| 1408 | |
---|
| 1409 | } |
---|
| 1410 | |
---|
| 1411 | void LocalGui::swapBuffers() |
---|
| 1412 | { |
---|
| 1413 | glutSwapBuffers(); |
---|
| 1414 | |
---|
| 1415 | } |
---|
| 1416 | |
---|
| 1417 | void LocalGui::clientMoveAndDisplay() |
---|
| 1418 | { |
---|
| 1419 | m_dynamicsWorld = m_env |
---|
| 1420 | ->getDynamicsWorld(); |
---|
| 1421 | |
---|
| 1422 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
---|
| 1423 | |
---|
| 1424 | ///simple dynamics world doesn't handle fixed-time-stepping |
---|
| 1425 | float ms = getDeltaTimeMicroseconds(); |
---|
| 1426 | ///step the simulation |
---|
| 1427 | if (m_dynamicsWorld) |
---|
| 1428 | { |
---|
| 1429 | m_dynamicsWorld->stepSimulation(ms / 1000000.f); |
---|
| 1430 | //optional but useful: debug drawing |
---|
| 1431 | m_dynamicsWorld->debugDrawWorld(); |
---|
| 1432 | } |
---|
| 1433 | |
---|
| 1434 | renderme(); |
---|
| 1435 | |
---|
| 1436 | glFlush(); |
---|
| 1437 | glutSwapBuffers(); |
---|
| 1438 | } |
---|
| 1439 | |
---|
| 1440 | void LocalGui::displayCallback(void) { |
---|
| 1441 | m_dynamicsWorld = m_env |
---|
| 1442 | ->getDynamicsWorld(); |
---|
| 1443 | |
---|
| 1444 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
---|
| 1445 | renderme(); |
---|
| 1446 | //optional but useful: debug drawing to detect problems |
---|
| 1447 | if (m_dynamicsWorld) |
---|
| 1448 | m_dynamicsWorld->debugDrawWorld(); |
---|
| 1449 | glFlush(); |
---|
| 1450 | glutSwapBuffers(); |
---|
| 1451 | } |
---|