CrashTestDummiesDemo::CrashTestDummiesDemo(hkDemoEnvironment* env): hkDefaultPhysicsDemo( env )
{
    // Disable warnings:
    hkError::getInstance().setEnabled(0xafe97523, false); //'This utility is intended primarily for Havok demo use. If you wish to step the world asynchronously,...'

    // XXX remove once async stepping fixed
    hkpWorld::IgnoreForceMultithreadedSimulation ignoreForceMultithreaded;

    enableDisplayingToiInformation(true);

    m_ragdoll = HK_NULL;

    //
    //	Create the world
    //
    {
        hkpWorldCinfo info;
        info.m_gravity.set( 0.0f, 0.0f, -10.0f );
        //info.m_enableDeactivation = false;
        info.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_CONTINUOUS;
        //info.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_BACKSTEP_SIMPLE;
        m_world = new hkpWorld( info );
        m_world->lock();

        // Register ALL agents (though some may not be necessary)
        hkpAgentRegisterUtil::registerAllAgents(m_world->getCollisionDispatcher());
    }

    //
    // Collision Filter
    //
    {
        m_filter = new hkpGroupFilter();
        hkpGroupFilterSetup::setupGroupFilter( m_filter );
        m_world->setCollisionFilter(m_filter);
    }

    //
    // Setup the camera
    //
    {
        hkVector4 from(0.0f, 8.0f, 3.0f);
        hkVector4 to(0.0f, 0.0f, 1.0f);
        hkVector4 up(0.0f, 0.0f, 1.0f);
        setupDefaultCameras( env, from, to, up, 1.f, 1000.0f );

        setupGraphics();
    }

    m_car =	createSimpleCarHull();
    m_world->addEntity( m_car )->removeReference();
    HK_SET_OBJECT_COLOR(hkUlong(m_car->getCollidable()), hkColor::rgbFromChars(255, 255, 255, 50));

    fitRagdollsIn(hkVector4::getZero());
    //hkVector4 pos(3.0f, 1.0f, 0.8f);
    //putBoxesIn( pos );
    //putBoxesIn(hkVector4(4.1f, 1.0f, 0.8f));

    createGroundBox();
    createFastObject();

    m_world->unlock();
}
Exemplo n.º 2
0
SqueezedBallDemo::SqueezedBallDemo(hkDemoEnvironment* env)
:	hkDefaultPhysicsDemo(env)
{
	enableDisplayingToiInformation( true );

	// Disable warnings
	hkError::getInstance().setEnabled(0xf0de4356, false);	// 'Your m_contactRestingVelocity seems to be too small'
	hkError::getInstance().setEnabled(0xad45d441, false);	// 'SCR generated invalid velocities'
	hkError::getInstance().setEnabled(0xafe97523, false); //'This utility is intended primarily for Havok demo use. If you wish to step the world asynchronously,...'

	
	//
	// Setup the camera
	//
	{
		hkVector4 from( 6, 0, 50);
		hkVector4 to  ( 6, 0, 0);
		hkVector4 up  ( 0, 1, 0);
		setupDefaultCameras(env, from, to, up);
	}


	//
	// Setup and create the hkpWorld
	//
	{
		hkpWorldCinfo info;
		info.setBroadPhaseWorldSize(350.0f);
		info.m_collisionTolerance = .03f; 
		info.m_gravity.set(0.0f, -100.0f, 0.0f);
		info.m_enableDeactivation = false;
		info.m_simulationType = info.SIMULATION_TYPE_CONTINUOUS;

		m_world = new hkpWorld( info );
		m_world->lock();

		m_debugViewerNames.pushBack( hkpBroadphaseViewer::getName() );

		hkRegisterAlternateShapeTypes(  m_world->getCollisionDispatcher() );
		hkpPredGskfAgent::registerAgent( m_world->getCollisionDispatcher() );

		setupGraphics();		
	}


	// Create a row of boxes
	int numBodies = 0;

	for (int r = 0; r < 1; r++)
	{
		for (int i = 0; i < 1; i++)
		{
			//hkVector4 boxSize(  0.5f, 0.5f, 0.5f);			// the end pos
			//hkpConvexShape* shape = new hkpBoxShape( boxSize, 0.05f );
			hkpConvexShape* shape = new hkpSphereShape( 0.5f ); 

			hkpRigidBodyCinfo ci;
			ci.m_motionType = hkpMotion::MOTION_DYNAMIC;
			ci.m_shape = shape;
			ci.m_mass = 1.0f;
			ci.m_angularDamping = 0.0f;
			ci.m_linearDamping = 0.0f;
			hkReal d = 1.0f;
			ci.m_inertiaTensor.setDiagonal( d,d,d );
			ci.m_position.set( i * -5.0f, i * -5.0f, 0);
			ci.m_restitution = 0.9f;
			ci.m_qualityType = HK_COLLIDABLE_QUALITY_CRITICAL;
			ci.m_maxLinearVelocity = 1000.0f;
	
			hkpRigidBody* body = new hkpRigidBody(ci);
			char buff[10];
			hkString::sprintf(buff, "body%d", numBodies++);
			body->setName(buff);
			hkVector4 vel(1500.0f, 500.0f, 0.0f);
			body->setLinearVelocity(vel);

			m_world->addEntity( body )->removeReference();

			shape->removeReference();


		}
	}

	hkVector4 halfSize(40.0f, 0.5f, 10.0f);

	// Create bottom fixed body
	{
		hkpConvexShape* shape = new hkpBoxShape(halfSize, 0.0f); 

		hkpRigidBodyCinfo ci;
		ci.m_motionType = hkpMotion::MOTION_FIXED;
		ci.m_shape = shape;
		ci.m_mass = 1.0f;
		ci.m_angularDamping = 0.0f;
		ci.m_linearDamping = 0.0f;
		hkReal d = 1.0f;
		ci.m_inertiaTensor.setDiagonal( d,d,d );
		ci.m_position.set( halfSize(0), -2.0f, 0);
		ci.m_restitution = 0.9f;

		hkpRigidBody* body = new hkpRigidBody(ci);
		
		char buff[10];
		hkString::sprintf(buff, "wall%d", 0);
		body->setName(buff);

		//bodies.pushBack( body );
		m_world->addEntity( body );
		body->removeReference();
		shape->removeReference();

	}

	// Create top body
	{
		hkpConvexShape* shape = new hkpBoxShape(halfSize, 0.0f); 

		hkpRigidBodyCinfo ci;
		ci.m_motionType = hkpMotion::MOTION_DYNAMIC;
		ci.m_shape = shape;
		ci.m_mass = 1000.0f;
		ci.m_angularDamping = 0.0f;
		ci.m_linearDamping = 0.0f;
		ci.m_inertiaTensor.setDiagonal( 10e7,10e7,10e5 );
		ci.m_position.set( halfSize(0), 2.1f, 0);
		ci.m_restitution = 0.9f;
		ci.m_rotation = hkQuaternion(hkVector4(0,0,-1), 4.0f * HK_REAL_PI / 180.0f);
		ci.m_qualityType = HK_COLLIDABLE_QUALITY_MOVING;

		hkpMassProperties mp;
		hkpInertiaTensorComputer::computeBoxVolumeMassProperties(halfSize, ci.m_mass, mp);

		hkpRigidBody* body = new hkpRigidBody(ci);

		char buff[10];
		hkString::sprintf(buff, "wall%d", 1);
		body->setName(buff);

		//bodies.pushBack( body );
		m_world->addEntity( body );
		body->removeReference();

		shape->removeReference();
	}

	m_world->unlock();
}
Exemplo n.º 3
0
HingeHittingTableDemo::HingeHittingTableDemo(hkDemoEnvironment* env)
:	hkDefaultPhysicsDemo(env)
{
	// Disable warnings:									
	hkError::getInstance().setEnabled(0xafe97523, false); //'This utility is intended primarily for Havok demo use. If you wish to step the world asynchronously,...'

	enableDisplayingToiInformation(true);

	//
	// Setup the camera
	//
	{
		hkVector4 from( 0, 0, 10);
		hkVector4 to  ( 0, 0, 0);
		hkVector4 up  ( 0, 1, 0);
		setupDefaultCameras(env, from, to, up);
	}


	//
	// Setup and create the hkpWorld
	//
	{
		hkpWorldCinfo info;
		info.setBroadPhaseWorldSize(150.0f);
		info.m_collisionTolerance = .03f; 
		info.m_gravity.setZero4();
		info.m_simulationType = info.SIMULATION_TYPE_CONTINUOUS;
		
		m_world = new hkpWorld( info );
		m_world->lock();

		hkpAgentRegisterUtil::registerAllAgents( m_world->getCollisionDispatcher() );

		setupGraphics();		
	}

	const HingeHittingTableDemoVariant& variant =  g_variants[this->m_variantId];

	//
	// Collision Filter
	//
	{ 
		hkpGroupFilter* filter = new hkpGroupFilter();
		hkpGroupFilterSetup::setupGroupFilter( filter );
		m_world->setCollisionFilter(filter);
		filter->disableCollisionsBetween(30,30);
		filter->removeReference();
	}

	// Create a box
	{
		hkReal mass = 0.0f;
		hkVector4 size( 2.0f, 0.2f, 2.0f );
		hkVector4 position( 1.0f, 0.0f, 0.0f );

		hkpRigidBody* body = HK_NULL;

		if( 1 ) 
		{
			// use a hkpBoxShape
			body = GameUtils::createBox( size, mass, position );
		}
		else
		{
			// use a hkpConvexVerticesShape
			body = GameUtils::createConvexVerticesBox( size, mass, position );
		}

		body->setName("table0");
		m_world->addEntity( body )->removeReference();
	}

	hkVector4 pos(-2.0f, 0.0f, 0.0f);
	hkVector4 vel(45.0f, 0.0f, 0.0f);

	switch(variant.m_sceneType)
	{
		case VARIANT_HINGE:
			createHinge(m_world, variant.m_objectQualityType, variant.m_constraintPriorityLevel, pos, vel);
			break;
		case VARIANT_RAGDOLL:
		case VARIANT_RAGDOLL_INCREASED_INERTIA:
			createRagdoll(m_world, variant.m_objectQualityType, variant.m_constraintPriorityLevel, pos, vel, variant.m_sceneType);
			break;

	}

	m_world->unlock();
}