void VehicleManagerDemo::setUpWorld() { m_tag = 0; // Initially "controller" is at (0,0), ie. neither pointing left/right nor up/down. m_inputXPosition = 0.0f; m_inputYPosition = 0.0f; // // Setup the camera. Actually overwritten by step function, and when we first add the vehicle. // { hkVector4 from(0.0f, 0.0f, 10.0f); hkVector4 to(0.0f, 0.0f, 0.0f); hkVector4 up(0.0f, 1.0f, 0.0f); setupDefaultCameras( m_env, from, to, up ); } // // Create the world. // { hkpWorldCinfo info; info.m_collisionTolerance = 0.1f; info.m_gravity.set(0.0f, -9.8f, 0.0f); info.setBroadPhaseWorldSize(2050.0f) ; info.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM); info.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_MULTITHREADED; m_world = new hkpWorld( info ); m_world->lock(); // Register all agents. hkpAgentRegisterUtil::registerAllAgents(m_world->getCollisionDispatcher()); // Graphics. setupGraphics(); } // // Create a filter, so that the ray casts of car do not collide with the ragdolls // { hkpGroupFilter* filter = new hkpGroupFilter(); //filter->disableCollisionsBetween( WHEEL_LAYER, RAGDOLL_LAYER ); m_world->setCollisionFilter( filter ); filter->removeReference(); } // Build the landscape to drive on and add it to m_world. buildLandscape(); m_reorientAction = HK_NULL; m_world->unlock(); }
void VehicleCloning::setUpWorld() { m_tag = 0; // // Setup the camera. // { hkVector4 from(0.0f, 10.0f, 20.0f); hkVector4 to(0.0f, 0.0f, -30.0f); hkVector4 up(0.0f, 1.0f, 0.0f); setupDefaultCameras( m_env, from, to, up ); } // // Create the world. // { hkpWorldCinfo info; info.m_collisionTolerance = 0.1f; info.m_gravity.set(0.0f, -9.8f, 0.0f); info.setBroadPhaseWorldSize(850.0f) ; info.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM); m_world = new hkpWorld( info ); m_world->lock(); // Register all agents. hkpAgentRegisterUtil::registerAllAgents(m_world->getCollisionDispatcher()); // Graphics. setupGraphics(); } // Build the landscape to drive on and add it to m_world. buildLandscape(); m_world->unlock(); }
VehicleApiDemo::VehicleApiDemo(hkDemoEnvironment* env) : hkDefaultPhysicsDemo(env) { m_tag = 0; ///[driverInput] /// Initially controller is set to 0,0 i.e. neither turning left/right or forward/backward, /// so vehicle is not accelerating or turning. /// m_inputXPosition = 0.0f; m_inputYPosition = 0.0f; ///> { hkVector4 from(0.0f, 0.0f, 10.0f); hkVector4 to(0.0f, 0.0f, 0.0f); hkVector4 up(0.0f, 1.0f, 0.0f); setupDefaultCameras( env, from, to, up ); } // // Create the world. // { hkpWorldCinfo info; info.m_collisionTolerance = 0.1f; info.m_gravity.set(0.0f, -9.8f, 0.0f); info.setBroadPhaseWorldSize(1000.0f) ; info.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM); m_world = new hkpWorld( info ); m_world->lock(); // Register all agents. hkpAgentRegisterUtil::registerAllAgents(m_world->getCollisionDispatcher()); // Graphics. setupGraphics(); } ///[buildLandscape] /// Build the landscape to drive on and add it to m_world. The landscape is simply five /// boxes, one for the ground and four for the walls. /// buildLandscape(); ///> /// /// Create the chassis /// hkpConvexVerticesShape* chassisShape = VehicleApiUtils::createCarChassisShape(); hkpRigidBody* chassisRigidBody; { hkpRigidBodyCinfo chassisInfo; // NB: The inertia value is reset by the vehicle SDK. However we give it a // reasonable value so that the hkpRigidBody does not assert on construction. See // VehicleSetup for the yaw, pitch and roll values used by hkVehicle. chassisInfo.m_mass = 750.0f; chassisInfo.m_shape = chassisShape; chassisInfo.m_friction = 0.4f; // The chassis MUST have m_motionType hkpMotion::MOTION_BOX_INERTIA to correctly simulate // vehicle roll, pitch and yaw. chassisInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA; chassisInfo.m_position.set(0.0f, 1.0f, 0.0f); hkpInertiaTensorComputer::setShapeVolumeMassProperties(chassisInfo.m_shape, chassisInfo.m_mass, chassisInfo); chassisRigidBody = new hkpRigidBody(chassisInfo); // No longer need reference to shape as the hkpRigidBody holds one. chassisShape->removeReference(); m_world->addEntity(chassisRigidBody); } ///> /// In this example, the chassis is added to the Vehicle Kit in the createVehicle() method. /// createVehicle( chassisRigidBody ); chassisRigidBody->removeReference(); ///> ///[buildVehicleCamera] /// This camera follows the vehicle when it moves. /// { VehicleApiUtils::createCamera( m_camera ); } ///> createDisplayWheels(); m_world->unlock(); }
SuspendInactiveAgentsDemo::SuspendInactiveAgentsDemo( hkDemoEnvironment* env ) : hkDefaultPhysicsDemo(env) { // Disable warnings: hkError::getInstance().setEnabled(0x7dd65995, false); //'The system has requested a heap allocation on stack overflow.' hkError::getInstance().setEnabled(0x86bc014f, false); //'For the default implementation to work the class must be passed in' // // Setup the camera. Actually overwritten by step function, and when we first add the vehicle. // { hkVector4 from(0.0f, 2.0f, 12.0f); hkVector4 to(0.0f, 0.0f, 0.0f); hkVector4 up(0.0f, 1.0f, 0.0f); setupDefaultCameras( m_env, from, to, up ); } // // Create the world. // { hkpWorldCinfo info; info.m_collisionTolerance = 0.01f; info.m_gravity.set(0.0f, -9.8f, 0.0f); info.setBroadPhaseWorldSize(850.0f) ; info.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM); m_world = new hkpWorld( info ); m_world->lock(); // Register all agents. hkpAgentRegisterUtil::registerAllAgents(m_world->getCollisionDispatcher()); // Graphics. m_debugViewerNames.pushBack( hkpSimulationIslandViewer::getName()); setupGraphics(); } // // Enable deleting inactive agents // { m_suspendInactiveAgentsUtil = new hkpSuspendInactiveAgentsUtil( m_world, hkpSuspendInactiveAgentsUtil::SUSPEND_ALL_COLLECTION_AGENTS ); } // // Create a filter, so that the raycasts of car does not collide with the ragdolls // { hkpGroupFilter* filter = new hkpGroupFilter(); filter->disableCollisionsBetween(1,3); m_world->setCollisionFilter( filter ); filter->removeReference(); } // Build the landscape to drive on and add it to m_world. buildLandscape(); if (getDemoVariant() < 2) { int gridSize = hkMath::clamp(m_env->m_cpuMhz / 150, 2, 4); createRagdollGrid( m_world, gridSize, gridSize, 4.0f, 4.0f ); m_boxRigidBody = HK_NULL; } else { // // Warm starting manifold - just illustrate with one box on a simple landscape // hkVector4 boxRadii( 1, .2f, 1); hkpShape* smallBox = new hkpBoxShape(boxRadii, 0 ); hkpRigidBodyCinfo boxInfo; boxInfo.m_mass = 1.0f; boxInfo.m_shape = smallBox; hkpInertiaTensorComputer::setShapeVolumeMassProperties(boxInfo.m_shape, boxInfo.m_mass, boxInfo); boxInfo.m_rotation.setIdentity(); boxInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA; boxInfo.m_position.set(2, 2, 2); boxInfo.m_restitution = .3f; boxInfo.m_qualityType = HK_COLLIDABLE_QUALITY_CRITICAL; //XXX m_boxRigidBody = new hkpRigidBody(boxInfo); smallBox->removeReference(); m_world->addEntity( m_boxRigidBody ); m_frameCount = 0; // Change the camera position to view the box close up hkVector4 from(0.91f, 0.87f, 5.52f); hkVector4 to(2.66f, -.16f, -.06f); hkVector4 up(0.0f, 1.0f, 0.0f); setupDefaultCameras( m_env, from, to, up ); } m_world->unlock(); }