void BasicDemo::clientMoveAndDisplay() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //simple dynamics world doesn't handle fixed-time-stepping float ms = getDeltaTimeMicroseconds(); int key; int x = 0, y = 0; //step the simulation if (m_dynamicsWorld) { specialKeyboard(key, x, y); if (gStepSim == true) { printf("Simulation step is %d\n", i); m_dynamicsWorld->stepSimulation(ms / 1000000.f); i += 1; } gStepSim = false; //optional but useful: debug drawing m_dynamicsWorld->debugDrawWorld(); } renderme(); glFlush(); swapBuffers(); }
void ForkLiftDemo::keyboardCallback(unsigned char key, int x, int y) { switch (key) { case ',': if (_modifier == GLUT_ACTIVE_SHIFT) _modifier = 0; else _modifier = GLUT_ACTIVE_SHIFT; break; case 'k': { int oldModifier = _modifier; _modifier = 0; specialKeyboard(GLUT_KEY_F5, 0, 0); _modifier = oldModifier; break; } default: DemoApplication::keyboardCallback(key, x, y); break; } }
void ForkLiftDemo::clientMoveAndDisplay() { #ifdef __QNX__ // Simulate arrow key input using the accelerometer. static float threshold = 0.3; static float pitch, roll, x, y, lx = 0, ly = 0; getAccelerometerPitchAndRoll(&pitch, &roll); x = -sinf(2.0f * MATH_DEG_TO_RAD(roll)); y = -sinf(2.0f * MATH_DEG_TO_RAD(pitch)); // Negate the pitch input when operating the fork. if (_modifier) y = -y; if (x > threshold) specialKeyboard(GLUT_KEY_RIGHT, 0, 0); else if (x < -threshold) specialKeyboard(GLUT_KEY_LEFT, 0, 0); else { if (lx > threshold) specialKeyboardUp(GLUT_KEY_RIGHT, 0, 0); else if (lx < -threshold) specialKeyboardUp(GLUT_KEY_LEFT, 0, 0); } if (y > threshold) specialKeyboard(GLUT_KEY_UP, 0, 0); else if (y < -threshold) specialKeyboard(GLUT_KEY_DOWN, 0, 0); else { if (ly > threshold) specialKeyboardUp(GLUT_KEY_UP, 0, 0); else if (ly < -threshold) specialKeyboardUp(GLUT_KEY_DOWN, 0, 0); } lx = x; ly = y; #endif glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); { int wheelIndex = 2; m_vehicle->applyEngineForce(gEngineForce,wheelIndex); m_vehicle->setBrake(gBreakingForce,wheelIndex); wheelIndex = 3; m_vehicle->applyEngineForce(gEngineForce,wheelIndex); m_vehicle->setBrake(gBreakingForce,wheelIndex); wheelIndex = 0; m_vehicle->setSteeringValue(gVehicleSteering,wheelIndex); wheelIndex = 1; m_vehicle->setSteeringValue(gVehicleSteering,wheelIndex); } float dt = getDeltaTimeMicroseconds() * 0.000001f; if (m_dynamicsWorld) { //during idle mode, just run 1 simulation step maximum int maxSimSubSteps = m_idle ? 1 : 2; if (m_idle) dt = 1.0/420.f; int numSimSteps; numSimSteps = m_dynamicsWorld->stepSimulation(dt,maxSimSubSteps); //#define VERBOSE_FEEDBACK #ifdef VERBOSE_FEEDBACK if (!numSimSteps) printf("Interpolated transforms\n"); else { if (numSimSteps > maxSimSubSteps) { //detect dropping frames printf("Dropped (%i) simulation steps out of %i\n",numSimSteps - maxSimSubSteps,numSimSteps); } else { printf("Simulated (%i) steps\n",numSimSteps); } } #endif //VERBOSE_FEEDBACK } #ifdef USE_QUICKPROF btProfiler::beginBlock("render"); #endif //USE_QUICKPROF renderme(); //optional but useful: debug drawing if (m_dynamicsWorld) m_dynamicsWorld->debugDrawWorld(); #ifdef USE_QUICKPROF btProfiler::endBlock("render"); #endif glFlush(); glutSwapBuffers(); }