void VehicleManagerDemo::buildLandscape() { if (1) { // // Create the ground we'll drive on. // { hkpRigidBodyCinfo groundInfo; // // Set the if condition to 0 if you want to test the heightfield // if ( 1 ) { FlatLand* fl = new FlatLand(); m_track = fl; groundInfo.m_shape = fl->createMoppShapeForSpu(); groundInfo.m_position.set(5.0f, -2.0f, 5.0f); groundInfo.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo( GROUND_LAYER, 0 ); } { groundInfo.m_motionType = hkpMotion::MOTION_FIXED; groundInfo.m_friction = 0.5f; hkpRigidBody* groundbody = new hkpRigidBody(groundInfo); m_world->addEntity(groundbody); groundbody->removeReference(); } groundInfo.m_shape->removeReference(); } } if (1) { hkVector4 halfExtents(10.0f, 0.1f, 10.0f); hkVector4 startPos(-240.0f, -7.8f, 0.0f); hkVector4 diffPos (30.0f, 0.0f, 0.0f); createDodgeBoxes(5, halfExtents, startPos, diffPos); } if (1) { hkVector4 halfExtents(10.0f, 0.05f, 10.0f); hkVector4 startPos(-240.0f, -7.85f, 30.0f); hkVector4 diffPos (30.0f, 0.0f, 0.0f); createDodgeBoxes(5, halfExtents, startPos, diffPos); } if (1) { int gridSize = 1 + int(hkMath::sqrt( hkReal(m_env->m_cpuMhz/100) )); createRagdollGrid( m_world, gridSize, gridSize, 4.0f, 4.0f, m_ragdolls ); } }
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(); }