void Hinge2Vehicle::resetForklift() { gVehicleSteering = 0.f; gBreakingForce = defaultBreakingForce; gEngineForce = 0.f; m_carChassis->setCenterOfMassTransform(btTransform::getIdentity()); m_carChassis->setLinearVelocity(btVector3(0,0,0)); m_carChassis->setAngularVelocity(btVector3(0,0,0)); m_dynamicsWorld->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(m_carChassis->getBroadphaseHandle(),getDynamicsWorld()->getDispatcher()); #if 0 if (m_vehicle) { m_vehicle->resetSuspension(); for (int i=0;i<m_vehicle->getNumWheels();i++) { //synchronize the wheels with the (interpolated) chassis worldtransform m_vehicle->updateWheelTransform(i,true); } } #endif btTransform liftTrans; liftTrans.setIdentity(); liftTrans.setOrigin(m_liftStartPos); m_liftBody->activate(); m_liftBody->setCenterOfMassTransform(liftTrans); m_liftBody->setLinearVelocity(btVector3(0,0,0)); m_liftBody->setAngularVelocity(btVector3(0,0,0)); btTransform forkTrans; forkTrans.setIdentity(); forkTrans.setOrigin(m_forkStartPos); m_forkBody->activate(); m_forkBody->setCenterOfMassTransform(forkTrans); m_forkBody->setLinearVelocity(btVector3(0,0,0)); m_forkBody->setAngularVelocity(btVector3(0,0,0)); // m_liftHinge->setLimit(-LIFT_EPS, LIFT_EPS); m_liftHinge->setLimit(0.0f, 0.0f); m_liftHinge->enableAngularMotor(false, 0, 0); m_forkSlider->setLowerLinLimit(0.1f); m_forkSlider->setUpperLinLimit(0.1f); m_forkSlider->setPoweredLinMotor(false); btTransform loadTrans; loadTrans.setIdentity(); loadTrans.setOrigin(m_loadStartPos); m_loadBody->activate(); m_loadBody->setCenterOfMassTransform(loadTrans); m_loadBody->setLinearVelocity(btVector3(0,0,0)); m_loadBody->setAngularVelocity(btVector3(0,0,0)); }
void Hinge2Vehicle::lockLiftHinge(void) { btScalar hingeAngle = m_liftHinge->getHingeAngle(); btScalar lowLim = m_liftHinge->getLowerLimit(); btScalar hiLim = m_liftHinge->getUpperLimit(); m_liftHinge->enableAngularMotor(false, 0, 0); if(hingeAngle < lowLim) { // m_liftHinge->setLimit(lowLim, lowLim + LIFT_EPS); m_liftHinge->setLimit(lowLim, lowLim); } else if(hingeAngle > hiLim) { // m_liftHinge->setLimit(hiLim - LIFT_EPS, hiLim); m_liftHinge->setLimit(hiLim, hiLim); } else { // m_liftHinge->setLimit(hingeAngle - LIFT_EPS, hingeAngle + LIFT_EPS); m_liftHinge->setLimit(hingeAngle, hingeAngle); } return; } // Hinge2Vehicle::lockLiftHinge()
void Hinge2Vehicle::specialKeyboard(int key, int x, int y) { #if 0 if (key==GLUT_KEY_END) return; // printf("key = %i x=%i y=%i\n",key,x,y); int state; state=glutGetModifiers(); if (state & GLUT_ACTIVE_SHIFT) { switch (key) { case GLUT_KEY_LEFT : { m_liftHinge->setLimit(-M_PI/16.0f, M_PI/8.0f); m_liftHinge->enableAngularMotor(true, -0.1, maxMotorImpulse); break; } case GLUT_KEY_RIGHT : { m_liftHinge->setLimit(-M_PI/16.0f, M_PI/8.0f); m_liftHinge->enableAngularMotor(true, 0.1, maxMotorImpulse); break; } case GLUT_KEY_UP : { m_forkSlider->setLowerLinLimit(0.1f); m_forkSlider->setUpperLinLimit(3.9f); m_forkSlider->setPoweredLinMotor(true); m_forkSlider->setMaxLinMotorForce(maxMotorImpulse); m_forkSlider->setTargetLinMotorVelocity(1.0); break; } case GLUT_KEY_DOWN : { m_forkSlider->setLowerLinLimit(0.1f); m_forkSlider->setUpperLinLimit(3.9f); m_forkSlider->setPoweredLinMotor(true); m_forkSlider->setMaxLinMotorForce(maxMotorImpulse); m_forkSlider->setTargetLinMotorVelocity(-1.0); break; } default: DemoApplication::specialKeyboard(key,x,y); break; } } else { switch (key) { case GLUT_KEY_LEFT : { gVehicleSteering += steeringIncrement; if ( gVehicleSteering > steeringClamp) gVehicleSteering = steeringClamp; break; } case GLUT_KEY_RIGHT : { gVehicleSteering -= steeringIncrement; if ( gVehicleSteering < -steeringClamp) gVehicleSteering = -steeringClamp; break; } case GLUT_KEY_UP : { gEngineForce = maxEngineForce; gBreakingForce = 0.f; break; } case GLUT_KEY_DOWN : { gEngineForce = -maxEngineForce; gBreakingForce = 0.f; break; } case GLUT_KEY_F7: { btDiscreteDynamicsWorld* world = (btDiscreteDynamicsWorld*)m_dynamicsWorld; world->setLatencyMotionStateInterpolation(!world->getLatencyMotionStateInterpolation()); printf("world latencyMotionStateInterpolation = %d\n", world->getLatencyMotionStateInterpolation()); break; } case GLUT_KEY_F6: { //switch solver (needs demo restart) useMCLPSolver = !useMCLPSolver; printf("switching to useMLCPSolver = %d\n", useMCLPSolver); delete m_solver; if (useMCLPSolver) { btDantzigSolver* mlcp = new btDantzigSolver(); //btSolveProjectedGaussSeidel* mlcp = new btSolveProjectedGaussSeidel; btMLCPSolver* sol = new btMLCPSolver(mlcp); m_solver = sol; } else { m_solver = new btSequentialImpulseConstraintSolver(); } m_dynamicsWorld->setConstraintSolver(m_solver); //exitPhysics(); //initPhysics(); break; } case GLUT_KEY_F5: m_useDefaultCamera = !m_useDefaultCamera; break; default: DemoApplication::specialKeyboard(key,x,y); break; } } // glutPostRedisplay(); #endif }
bool Hinge2Vehicle::keyboardCallback(int key, int state) { bool handled = false; bool isShiftPressed = m_guiHelper->getAppInterface()->m_window->isModifierKeyPressed(B3G_SHIFT); if (state) { if (isShiftPressed) { switch (key) { case B3G_LEFT_ARROW : { m_liftHinge->setLimit(-M_PI/16.0f, M_PI/8.0f); m_liftHinge->enableAngularMotor(true, -0.1, maxMotorImpulse); handled = true; break; } case B3G_RIGHT_ARROW : { m_liftHinge->setLimit(-M_PI/16.0f, M_PI/8.0f); m_liftHinge->enableAngularMotor(true, 0.1, maxMotorImpulse); handled = true; break; } case B3G_UP_ARROW : { m_forkSlider->setLowerLinLimit(0.1f); m_forkSlider->setUpperLinLimit(3.9f); m_forkSlider->setPoweredLinMotor(true); m_forkSlider->setMaxLinMotorForce(maxMotorImpulse); m_forkSlider->setTargetLinMotorVelocity(1.0); handled = true; break; } case B3G_DOWN_ARROW : { m_forkSlider->setLowerLinLimit(0.1f); m_forkSlider->setUpperLinLimit(3.9f); m_forkSlider->setPoweredLinMotor(true); m_forkSlider->setMaxLinMotorForce(maxMotorImpulse); m_forkSlider->setTargetLinMotorVelocity(-1.0); handled = true; break; } } } else { switch (key) { case B3G_LEFT_ARROW : { handled = true; gVehicleSteering += steeringIncrement; if ( gVehicleSteering > steeringClamp) gVehicleSteering = steeringClamp; break; } case B3G_RIGHT_ARROW : { handled = true; gVehicleSteering -= steeringIncrement; if ( gVehicleSteering < -steeringClamp) gVehicleSteering = -steeringClamp; break; } case B3G_UP_ARROW : { handled = true; gEngineForce = maxEngineForce; gBreakingForce = 0.f; break; } case B3G_DOWN_ARROW : { handled = true; gEngineForce = -maxEngineForce; gBreakingForce = 0.f; break; } case B3G_F7: { handled = true; btDiscreteDynamicsWorld* world = (btDiscreteDynamicsWorld*)m_dynamicsWorld; world->setLatencyMotionStateInterpolation(!world->getLatencyMotionStateInterpolation()); printf("world latencyMotionStateInterpolation = %d\n", world->getLatencyMotionStateInterpolation()); break; } case B3G_F6: { handled = true; //switch solver (needs demo restart) useMCLPSolver = !useMCLPSolver; printf("switching to useMLCPSolver = %d\n", useMCLPSolver); delete m_solver; if (useMCLPSolver) { btDantzigSolver* mlcp = new btDantzigSolver(); //btSolveProjectedGaussSeidel* mlcp = new btSolveProjectedGaussSeidel; btMLCPSolver* sol = new btMLCPSolver(mlcp); m_solver = sol; } else { m_solver = new btSequentialImpulseConstraintSolver(); } m_dynamicsWorld->setConstraintSolver(m_solver); //exitPhysics(); //initPhysics(); break; } case B3G_F5: handled = true; m_useDefaultCamera = !m_useDefaultCamera; break; default: break; } } } else { switch (key) { case B3G_UP_ARROW: { lockForkSlider(); gEngineForce = 0.f; gBreakingForce = defaultBreakingForce; handled=true; break; } case B3G_DOWN_ARROW: { lockForkSlider(); gEngineForce = 0.f; gBreakingForce = defaultBreakingForce; handled=true; break; } case B3G_LEFT_ARROW: case B3G_RIGHT_ARROW: { lockLiftHinge(); handled=true; break; } default: break; } } return handled; }