void hkDefaultPhysicsDemo::setAutoInstancingEnabled( bool on ) { hkpShapeDisplayViewer* viewer = (hkpShapeDisplayViewer*) getLocalViewerByName("Shapes"); if (viewer) { viewer->setInstancingEnabled( on ); } }
void hkDefaultPhysicsDemo::setAutoDisplayCachingEnabled( bool on ) { hkpShapeDisplayViewer* viewer = (hkpShapeDisplayViewer*) getLocalViewerByName("Shapes"); if (viewer) { viewer->setDisplayBodyCachingEnabled( on ); } if (m_env->m_displayHandler) { m_env->m_displayHandler->setDisplayBodyCachingEnabled( on ); } }
BenchmarkSuiteDemo::BenchmarkSuiteDemo(hkDemoEnvironment* env) : hkDefaultPhysicsDemo(env) { const BenchmarkSuiteVariant& variant = g_variants[m_variantId]; // Disable warnings: hkError::getInstance().setEnabled(0x7dd65995, false); //'The system has requested a heap allocation on stack overflow.' hkError::getInstance().setEnabled(0xaf55adde, false); //'No runtime block of size 637136 currently available. Allocating new block from unmanaged memory.' // // Setup the camera // { hkVector4 from(55.0f, 50.0f, 55.0f); hkVector4 to ( 0.0f, 0.0f, 0.0f); hkVector4 up ( 0.0f, 1.0f, 0.0f); setupDefaultCameras(env, from, to, up, 0.1f, 20000.0f); } // // Create the world // { hkpWorldCinfo worldInfo; { worldInfo.m_gravity.set(-0.0f, -9.81f, -0.0f); worldInfo.setBroadPhaseWorldSize(500.0f); worldInfo.setupSolverInfo( hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM ); if (variant.m_type == TYPE_3000_BODY_PILE) { worldInfo.m_enableSimulationIslands = false; } worldInfo.m_enableDeactivation = false; } m_world = new hkpWorld(worldInfo); m_world->lock(); // Register ALL agents (though some may not be necessary) hkpAgentRegisterUtil::registerAllAgents(m_world->getCollisionDispatcher()); setupGraphics(); // enable instancing (if present on platform). Call this after setup graphics (as it makes the local viewers..) hkpShapeDisplayViewer* shapeViewer = (hkpShapeDisplayViewer*)getLocalViewerByName( hkpShapeDisplayViewer::getName() ); if (shapeViewer) { shapeViewer->setInstancingEnabled( true ); } } // // Setup the camera // { hkVector4 from(15.0f, 15.0f, 15.0f); hkVector4 to (0.0f, 0.0f, 0.0f); hkVector4 up (0.0f, 1.0f, 0.0f); setupDefaultCameras( env, from, to, up ); } switch (variant.m_type) { case TYPE_10x10x1_ON_BOX: { CreateGroundPlane( m_world ); CreateStack(m_world, 10); break; } case TYPE_5x5x5_ON_BOX: { CreateGroundPlane(m_world); for (int q = -3; q <= 2; q++ ) { CreateStack(m_world,5, q * 10.0f); } break; } case TYPE_300_BODY_PILE: { CreateGroundPlane(m_world); CreateFall(m_world, 5); break; } case TYPE_OBJECTS_ON_MOPP_SMALL: { CreatePhysicsTerrain(m_world, 16, 1.0f); CreateFlatCubeGrid(m_world,8); break; } case TYPE_LIST_PILE_SMALL: { int side = 16; CreatePhysicsTerrain(m_world, side, 1.0f); CreateListGrid(m_world, hkReal(side), 3, 3); break; } case TYPE_30x30x1_ON_BOX: { CreateGroundPlane( m_world ); CreateStack(m_world, 30); break; } case TYPE_20x20x5_ON_BOX: { CreateGroundPlane(m_world); for (int q = -3; q <= 2; q++ ) { CreateStack(m_world,20, q * 10.0f); } break; } case TYPE_12x12x10_ON_BOX: { CreateGroundPlane(m_world); for (int q = -5; q <= 4; q++ ) { CreateStack(m_world,12, q * 2.5f); } break; } case TYPE_3000_BODY_PILE: { CreateGroundPlane(m_world); CreateFall(m_world, 50); break; } case TYPE_OBJECTS_ON_MOPP_LARGE: { CreatePhysicsTerrain(m_world, 64, 1.0f); CreateFlatCubeGrid(m_world,30); break; } case TYPE_LIST_PILE_LARGE: { int side = 16; CreatePhysicsTerrain(m_world, side, 1.0f); CreateListGrid(m_world, hkReal(side), 5, 5); break; } default: { CreateGroundPlane(m_world); CreateStack(m_world, 20); break; } } // // Some values // m_world->unlock(); }
BrickWallDemo::BrickWallDemo(hkDemoEnvironment* env) : hkDefaultPhysicsDemo(env) { // Disable warnings: hkError::getInstance().setEnabled(0xaf55adde, false); //'No runtime block of size 637136 currently available. Allocating new block from unmanaged memory.' hkDefaultPhysicsDemo::enableDisplayingToiInformation( true ); m_frameToSimulationFrequencyRatio = 1.0f; m_timestep = 1.0f / 60.0f; const BrickWallVariant& variant = g_variants[m_variantId]; int wallHeight = variant.m_height; int wallWidth = variant.m_width; int numWalls = variant.m_numWalls; hkpWorldCinfo::SimulationType simulationType; simulationType = hkpWorldCinfo::SIMULATION_TYPE_CONTINUOUS; // // Setup the camera so that we can see the ball hit the (first) wall. // { hkVector4 from(40.0f, 20.0f, 40.0f); hkVector4 to ( 0.0f, 10.0f, 0.0f); hkVector4 up ( 0.0f, 1.0f, 0.0f); setupDefaultCameras( env, from, to, up ); } { hkpWorldCinfo info; info.setBroadPhaseWorldSize( 5000.0f ); info.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_HARD); info.m_collisionTolerance = 0.01f; info.m_gravity = hkVector4( 0.0f,-9.8f,0.0f); info.m_simulationType = simulationType; info.m_broadPhaseBorderBehaviour = info.BROADPHASE_BORDER_FIX_ENTITY; //info.m_enableDeactivation = false; //info.m_enableSimulationIslands = false; info.m_enableDeactivation = false; m_world = new hkpWorld( info ); m_world->lock(); } { // Register ALL agents (though some may not be necessary) hkpAgentRegisterUtil::registerAllAgents(m_world->getCollisionDispatcher()); setupGraphics(); // enable instancing (if present on platform) hkpShapeDisplayViewer* shapeViewer = (hkpShapeDisplayViewer*)getLocalViewerByName( hkpShapeDisplayViewer::getName() ); if (shapeViewer) { shapeViewer->setInstancingEnabled( true ); } } // // Create the ground box // { hkVector4 groundRadii( 70.0f, 2.0f, 70.0f ); hkpConvexShape* shape = new hkpBoxShape( groundRadii , 0 ); hkpRigidBodyCinfo ci; ci.m_shape = shape; ci.m_motionType = hkpMotion::MOTION_FIXED; ci.m_position = hkVector4( 0.0f, -2.0f, 0.0f ); ci.m_qualityType = HK_COLLIDABLE_QUALITY_FIXED; m_world->addEntity( new hkpRigidBody( ci ) )->removeReference(); shape->removeReference(); } hkVector4 groundPos( 0.0f, 0.0f, 0.0f ); hkVector4 posy = groundPos; // // Create the walls // if(1) { hkVector4 boxSize( 1.0f, 0.5f, 0.5f); hkpBoxShape* box = new hkpBoxShape( boxSize , 0 ); box->setRadius( 0.0f ); hkReal deltaZ = 25.0f; posy(2) = -deltaZ * numWalls * 0.5f; for ( int y = 0; y < numWalls; y ++ ) // first wall { createBrickWall( m_world, wallHeight, wallWidth, posy, 0.2f, box, boxSize ); posy(2) += deltaZ; } box->removeReference(); } // // Create the ball // if (1) { const hkReal radius = 1.5f; const hkReal sphereMass = 150.0f; hkVector4 relPos( 0.0f,radius + 0.0f, 20.0f ); hkpRigidBodyCinfo info; hkpMassProperties massProperties; hkpInertiaTensorComputer::computeSphereVolumeMassProperties(radius, sphereMass, massProperties); info.m_mass = massProperties.m_mass; info.m_centerOfMass = massProperties.m_centerOfMass; info.m_inertiaTensor = massProperties.m_inertiaTensor; info.m_shape = new hkpSphereShape( radius ); info.m_position.setAdd4(posy, relPos ); info.m_motionType = hkpMotion::MOTION_BOX_INERTIA; if ( variant.m_usePredictive) { info.m_qualityType = HK_COLLIDABLE_QUALITY_BULLET; } else { info.m_qualityType = HK_COLLIDABLE_QUALITY_DEBRIS; } hkpRigidBody* sphereRigidBody = new hkpRigidBody( info ); m_world->addEntity( sphereRigidBody ); sphereRigidBody->removeReference(); info.m_shape->removeReference(); hkVector4 vel( 0.0f,4.9f, -200.0f ); sphereRigidBody->setLinearVelocity( vel ); } m_world->unlock(); }