void RearWheel::setPosAndRot(float posX, float posY, float posZ,
		float rotX, float rotY, float rotZ)	// In Radians
{
	drawable->setPosAndRot(posX, posY, posZ,
		rotX, rotY, rotZ);

	hkQuaternion quat;
	quat.setAxisAngle(hkVector4(1.0f, 0.0f, 0.0f), rotX);
	quat.mul(hkQuaternion(hkVector4(0.0f, 1.0f, 0.0f), rotY));
	quat.mul(hkQuaternion(hkVector4(0.0f, 0.0f, 1.0f), rotZ));

	hkVector4 pos = hkVector4(posX, posY, posZ);

	body->setPositionAndRotation(hkVector4(posX, posY, posZ), quat);
}
void BoxHavok::Init(ObjectInfo* o)
{
	hkRefPtr<hkpBoxShape> boxShape = new hkpBoxShape(halfExtent);
	
	hkpRigidBodyCinfo bodyCinfo;
	bodyCinfo.m_shape = boxShape;
	bodyCinfo.m_solverDeactivation = bodyCinfo.SOLVER_DEACTIVATION_MEDIUM;
	// Place box somewhere above floor...
	bodyCinfo.m_position = this->startingPosition;
	bodyCinfo.m_rotation = hkQuaternion(this->startingRotation);
	bodyCinfo.m_restitution = this->restitution;
	bodyCinfo.m_friction = this->friction;
	if(moveable)
	{
		//  Calculate the mass properties for the shape
		const hkReal boxMass = this->mass;
		hkMassProperties massProperties;
		hkpInertiaTensorComputer::computeShapeVolumeMassProperties(boxShape, boxMass, massProperties);

		bodyCinfo.setMassProperties(massProperties);
	}
	else
	{
		bodyCinfo.m_motionType = hkpMotion::MOTION_FIXED;
	}

	// Create the rigid body
	this->m_RigidBody = new hkpRigidBody(bodyCinfo);
	
	this->AddBodyToHavok();
}
void Object_Player::convertPosition()
{
	D3DXVECTOR3 NormRot;
	position.x = (float)objectBody->getPosition().getComponent(0);
	position.y = (float)objectBody->getPosition().getComponent(1);
	position.z = (float)objectBody->getPosition().getComponent(2);
	position.w = (float)objectBody->getPosition().getComponent(3);

	D3DXVec3Normalize(&NormRot, &rotation);

	hk_rotation = hkQuaternion(NormRot.x, NormRot.y, NormRot.z, 0.0f);
	
}
void Racer::setPosAndRot(float posX, float posY, float posZ,
		float rotX, float rotY, float rotZ)	// In Radians
{
	drawable->setPosAndRot(posX, posY, posZ,
		rotX, rotY, rotZ);

	hkQuaternion quat;
	quat.setAxisAngle(hkVector4(1.0f, 0.0f, 0.0f), rotX);
	quat.mul(hkQuaternion(hkVector4(0.0f, 1.0f, 0.0f), rotY));
	quat.mul(hkQuaternion(hkVector4(0.0f, 0.0f, 1.0f), rotZ));

	hkVector4 pos = hkVector4(posX, posY, posZ);

	body->setPositionAndRotation(hkVector4(posX, posY, posZ), quat);

	wheelFL->setPosAndRot(attachFL(0) + pos(0), attachFL(1) + pos(1), attachFL(2) + pos(2), rotX, rotY, rotZ);
	wheelFR->setPosAndRot(attachFR(0) + pos(0), attachFR(1) + pos(1), attachFR(2) + pos(2), rotX, rotY, rotZ);
	wheelRL->setPosAndRot(attachRL(0) + pos(0), attachRL(1) + pos(1), attachRL(2) + pos(2), rotX, rotY, rotZ);
	wheelRR->setPosAndRot(attachRR(0) + pos(0), attachRR(1) + pos(1), attachRR(2) + pos(2), rotX, rotY, rotZ);

	update();
}
Beispiel #5
0
void AddRemoveBodiesDemo::createGround()
{
	const hkVector4 halfExtents(20.0f, 4.0f, 20.0f);
	hkpShape* groundShape = new hkpBoxShape(halfExtents, 0.05f );

	hkpRigidBodyCinfo bodyInfo;
	bodyInfo.m_mass = 0.0f;	
	bodyInfo.m_shape = groundShape;
	bodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
	bodyInfo.m_position.set(0.0f, 0.0f, 0.0f);
	hkVector4 axis(0.0f, 0.0f, 1.0f);
	bodyInfo.m_rotation = hkQuaternion(axis, -0.3f);

	hkpRigidBody* groundBody = new hkpRigidBody(bodyInfo);
	groundShape->removeReference();

	m_world->addEntity(groundBody);
	groundBody->removeReference();	
}
Beispiel #6
0
Wall::Wall(Ogre::Vector3 Pos, Ogre::Vector3 size,Physics * physics, Ogre::SceneManager * manager, float rotation)
	: StaticObject(Pos,
					Ogre::Vector3(size.x, size.y, 20.0f),
					"cube.mesh",
					physics,
					manager)
{
	mOrintation = Ogre::Quaternion(Ogre::Radian(Ogre::Degree(rotation)), Ogre::Vector3(0,1,0));
	hkVector4 HalfSize( mSize.x / 2.0, mSize.y / 2.0, mSize.z / 2.0);
	hkpBoxShape* Hbox =						new hkpBoxShape(HalfSize,0);
	Hbox->setRadius(0.0f);
	
	hkpRigidBodyCinfo						WallInfo;
	WallInfo.m_mass =						100.0f;
	hkMassProperties massProperties;
	hkpInertiaTensorComputer::computeBoxVolumeMassProperties(
		HalfSize, WallInfo.m_mass, massProperties);
	WallInfo.m_mass =						massProperties.m_mass;
	WallInfo.m_centerOfMass =				massProperties.m_centerOfMass;
	WallInfo.m_inertiaTensor =				massProperties.m_inertiaTensor;
	WallInfo.m_solverDeactivation =			WallInfo.SOLVER_DEACTIVATION_MEDIUM;
	WallInfo.m_shape =						Hbox;
	WallInfo.m_restitution =				0.0f;
	WallInfo.m_qualityType =				HK_COLLIDABLE_QUALITY_FIXED;
	WallInfo.m_motionType =					hkpMotion::MOTION_FIXED;
	WallInfo.m_rotation =					hkQuaternion(mOrintation.x, mOrintation.y, mOrintation.z, mOrintation.w);
	WallInfo.m_position = 					hkVector4(mPosition.x,mPosition.y,mPosition.z);
	Body =									new hkpRigidBody(WallInfo);
	Body->setUserData(hkUlong(this));
	mPhysicsManager->GetPhysicsWorld()->addEntity(Body);
	ObjectNode->setScale(mSize.x / ObjectEnt->getBoundingBox().getSize().x,
		mSize.y / ObjectEnt->getBoundingBox().getSize().y, mSize.z / ObjectEnt->getBoundingBox().getSize().z);
	ObjectNode->setPosition(Ogre::Vector3(Body->getPosition()(0), Body->getPosition()(1),Body->getPosition()(2)));
	ObjectEnt->setMaterialName("Examples/RustySteel");
	hkQuaternion GetBodyAngle = Body->getRotation();
	hkVector4 GetrotationAxis(0,0,0);
	if(GetBodyAngle.hasValidAxis())
	{
		GetBodyAngle.getAxis(GetrotationAxis);
	}
	Ogre::Quaternion UpdateOrintation(Ogre::Radian(GetBodyAngle.getAngle()), Ogre::Vector3(GetrotationAxis(0),GetrotationAxis(1),GetrotationAxis(2)));
	ObjectNode->setOrientation(UpdateOrintation);
}
Beispiel #7
0
Turret::Turret(Ogre::Vector3 Pos, Ogre::SceneManager* manager, Physics* physicsManager)
		:	DynamicObject( Pos,
						"cube.mesh",
						Ogre::Vector3(20.0,50.0,20.0),
						Ogre::Quaternion( Ogre::Radian(0), Ogre::Vector3(0,1,0)),
						manager,
						physicsManager )
				,mRotateValue(0)
				,mChangeInRotation(0.001)
				,mKillTimer(0)
				,mShutdown(false)
{
	hkVector4 HalfSize( mSize.x / 2.0, mSize.y / 2.0, mSize.z / 2.0);
	hkpBoxShape* Hbox =						new hkpBoxShape(HalfSize,0);
	Hbox->setRadius(0.0f);
	
	hkpRigidBodyCinfo						TurretInfo;
	TurretInfo.m_mass =						5000.0f;
	hkMassProperties massProperties;
	hkpInertiaTensorComputer::computeBoxVolumeMassProperties(
		HalfSize, TurretInfo.m_mass, massProperties);
	TurretInfo.m_mass =						massProperties.m_mass;
	TurretInfo.m_centerOfMass =				hkVector4(massProperties.m_centerOfMass(0),massProperties.m_centerOfMass(1) - 20,massProperties.m_centerOfMass(2));
	TurretInfo.m_inertiaTensor =			massProperties.m_inertiaTensor;
	TurretInfo.m_solverDeactivation =		TurretInfo.SOLVER_DEACTIVATION_MEDIUM;
	TurretInfo.m_shape =					Hbox;
	TurretInfo.m_restitution =				0.0f;
	TurretInfo.m_qualityType =				HK_COLLIDABLE_QUALITY_MOVING;
	TurretInfo.m_motionType =				hkpMotion::MOTION_BOX_INERTIA;
	TurretInfo.m_rotation =					hkQuaternion(mOrintation.x, mOrintation.y, mOrintation.z, mOrintation.w);
	TurretInfo.m_position = 				hkVector4(mPosition.x,mPosition.y,mPosition.z);
	Body =									new hkpRigidBody(TurretInfo);
	Body->setUserData(hkUlong(this));
	mPhysicsManager->GetPhysicsWorld()->addEntity(Body);
	ObjectNode->setScale(mSize.x / ObjectEnt->getBoundingBox().getSize().x,
		mSize.y / ObjectEnt->getBoundingBox().getSize().y, mSize.z / ObjectEnt->getBoundingBox().getSize().z);
	ObjectNode->setPosition(Ogre::Vector3(Body->getPosition()(0), Body->getPosition()(1),Body->getPosition()(2)));
}
Beispiel #8
0
Create::Create(Ogre::Vector3 Pos, Ogre::SceneManager* manager, Physics* physicsManager)
	:	DynamicObject( Pos,
						"cube.mesh",
						Ogre::Vector3(34.0,34.0,34.0),
						Ogre::Quaternion( Ogre::Radian(0), Ogre::Vector3(0,1,0)),
						manager,
						physicsManager )
						,Hit(false)
{
	hkVector4 HalfSize( mSize.x / 2.0, mSize.y / 2.0, mSize.z / 2.0);
	hkpBoxShape* Hbox =						new hkpBoxShape(HalfSize,0);
	Hbox->setRadius(0.0f);
	
	hkpRigidBodyCinfo						CreateInfo;
	CreateInfo.m_mass =						100.0f;
	hkMassProperties massProperties;
	hkpInertiaTensorComputer::computeBoxVolumeMassProperties(
		HalfSize, CreateInfo.m_mass, massProperties);
	CreateInfo.m_mass =						massProperties.m_mass;
	CreateInfo.m_centerOfMass =				massProperties.m_centerOfMass;
	CreateInfo.m_inertiaTensor =			massProperties.m_inertiaTensor;
	CreateInfo.m_solverDeactivation =		CreateInfo.SOLVER_DEACTIVATION_MEDIUM;
	CreateInfo.m_shape =					Hbox;
	CreateInfo.m_restitution =				0.0f;
	CreateInfo.m_qualityType =				HK_COLLIDABLE_QUALITY_MOVING;
	CreateInfo.m_motionType =				hkpMotion::MOTION_BOX_INERTIA;
	CreateInfo.m_rotation =					hkQuaternion(mOrintation.x, mOrintation.y, mOrintation.z, mOrintation.w);
	CreateInfo.m_position = 				hkVector4(mPosition.x,mPosition.y,mPosition.z);
	Body =									new hkpRigidBody(CreateInfo);
	Body->setUserData(hkUlong(this));
	RecptorFront = mOrintation * Ogre::Vector3::UNIT_X;
	RecptorSide = mOrintation * Ogre::Vector3::UNIT_Z;
	mPhysicsManager->GetPhysicsWorld()->addEntity(Body);
	ObjectNode->setScale(mSize.x / ObjectEnt->getBoundingBox().getSize().x,
		mSize.y / ObjectEnt->getBoundingBox().getSize().y, mSize.z / ObjectEnt->getBoundingBox().getSize().z);
	ObjectNode->setPosition(Ogre::Vector3(Body->getPosition()(0), Body->getPosition()(1),Body->getPosition()(2)));
}
Beispiel #9
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();
}
Beispiel #10
0
OffsetObject* ObjectPool::getObject(const irr::core::vector3df& apos, const irr::core::vector3df& scale, const irr::core::vector3df& rot, bool addToOffsetManager)
{
    //dprintf(MY_DEBUG_NOTE, "ObjectPool::getObject(): %s\n", name.c_str());
    OffsetObject* offsetObject = 0;
    if (!objectList.empty())
    {
        offsetObject = objectList.front(); // *objectList.begin();
        objectList.erase(objectList.begin());
    }
    else
    {
        offsetObject = createNewInstance();
    }

    offsetObject->setUpdateCB(0);
    //offsetObject->setPos(apos);
    offsetObject->getNode()->setPosition(apos);
    offsetObject->getNode()->setScale(scale);
    offsetObject->getNode()->setRotation(rot);
    offsetObject->getNode()->setMaterialType(material);
    if (Shaders::getInstance()->getSupportedSMVersion() < 2)
    {
        offsetObject->getNode()->setMaterialFlag(irr::video::EMF_LIGHTING, Settings::getInstance()->nonshaderLight);
    }
    else
    {
        offsetObject->getNode()->setMaterialFlag(irr::video::EMF_LIGHTING, false);
    }
    //printf("-------------- texture: %p\n", texture);
    offsetObject->getNode()->setMaterialTexture(0, texture);

    if (hkShape)
    {
    
        hk::lock();
        hkpRigidBodyCinfo groundInfo;
        groundInfo.m_shape = hkShape;
        groundInfo.m_position.set(apos.X, apos.Y, apos.Z);
        if (rot != irr::core::vector3df())
        {
            irr::core::vector3df rotRad = rot * irr::core::DEGTORAD;
            irr::core::quaternion rotQuat(rotRad);
            groundInfo.m_rotation = hkQuaternion(rotQuat.X, rotQuat.Y, rotQuat.Z, rotQuat.W);
        }
        if (objectType == Vehicle)
        {
            groundInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA;
            groundInfo.m_mass = mass;
            // TODO
            //groundInfo.m_position.set(0.0f, 0.0f, 0.0f);
            groundInfo.m_inertiaTensor.setDiagonal(1.0f, 1.0f, 1.0f);
            groundInfo.m_centerOfMass.set(center.X, center.Y, center.Z);
            groundInfo.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(hk::materialType::vehicleId);
        }
        else
        {
            groundInfo.m_motionType = hkpMotion::MOTION_FIXED;
            groundInfo.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(hk::materialType::treeId);
        }
        groundInfo.m_friction = friction;
        hkpRigidBody* hkBody = new hkpRigidBody(groundInfo);
        if (objectType != Vehicle)
        {
            hkpPropertyValue val(1);
            hkBody->addProperty(hk::materialType::treeId, val);
            hk::hkWorld->addEntity(hkBody);
        }
        else
        {
            hkpPropertyValue val(1);
            hkBody->addProperty(hk::materialType::vehicleId, val);
        }
        hk::unlock();
        offsetObject->setBody(hkBody);
        //hkBody->activate();
    }

    offsetObject->setPool(this);
    inUse++;

    if (addToOffsetManager)
    {
        offsetObject->addToManager();
    }
    offsetObject->getNode()->setVisible(true);
    switch (objectType)
    {
    case Grass:
    case MyTree:
        break;
    default:
        ObjectPoolManager::getInstance()->addShadowNode(offsetObject->getNode());
        break;
    }
    return offsetObject;
}
Beispiel #11
0
void Game::dropSphere(){
	pSphere->getRigidBody()->setPosition(hkVector4(pLevel1->getPos().x+0.1,pLevel1->getPos().y + 3.0,pLevel1->getPos().z));
	pSphere->getRigidBody()->setRotation(hkQuaternion(1,0,0,0));
	pSphere->getRigidBody()->setAngularVelocity(hkVector4(0,0,0));
	pSphere->getRigidBody()->setLinearVelocity(hkVector4(0,0,0));
}
Beispiel #12
0
void Game::rotatePlatformXZZero(){
	pLevel1->getRigidBody()->setRotation(hkQuaternion(1, 0, 0, 0));
}
Beispiel #13
0
void Game::rotatePlatformZPostiveXNegative(){
	pLevel1->getRigidBody()->setRotation(hkQuaternion(0.9980973490458728, 0.04357787137382908, -0.0019026509541272335, -0.04357787137382908));
}
Beispiel #14
0
void Game::rotatePlatformZAxisNegative(){
//	hkQuaternion* quat = pLevel1->getRigidBody()->getRotation().getAngle;
	pLevel1->getRigidBody()->setRotation(hkQuaternion(0.9990482215818578, -0.04361938736533599, 0,0));
}
Beispiel #15
0
void DemoKeeper::createGround( void )
{
	const hkVector4 halfExtents(12.0f, 1.0f, 12.0f);
	hkpShape* groundShape = new hkpBoxShape(halfExtents, 0 );

	hkpRigidBodyCinfo bodyInfo;
	bodyInfo.m_mass = 0.0f;	
	bodyInfo.m_shape = groundShape;
	bodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
	bodyInfo.m_position.set(0.0f, 10.0f, 0.0f);
	hkVector4 axis(1.0f, 0.0f, 0.0f);


	{
		axis.set(1,0,1);
		axis.normalize3();
		bodyInfo.m_rotation = hkQuaternion(axis, 0.5f);
		bodyInfo.m_position.set(10.0f, 10.0f, -10.0f);
		hkpRigidBody* groundBody = new hkpRigidBody(bodyInfo);

		mWorld->addEntity(groundBody);
		groundBody->removeReference();

		//render it with Ogre
		Ogre::SceneNode* boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();

		//scale and rotate
		boxNode->scale(24, 2, 24);
		Ogre::Quaternion q = HkOgre::Convert::hkQuatToOgre(bodyInfo.m_rotation);
		boxNode->rotate(q);

		//display and sync
		Ogre::Entity *ent = mSceneMgr->createEntity(Ogre::StringConverter::toString(mLabMgr->getEntityCount()),"defCube.mesh");
		mLabMgr->setColor(ent, Ogre::Vector3(0.3047,0.3047,0.3047));
		HkOgre::Renderable* rend = new HkOgre::Renderable(boxNode, groundBody, mWorld);
		boxNode->attachObject(ent);

		//register to lab manager
		mLabMgr->registerEnity( boxNode, groundBody);
	}

	{
		axis.set(-1,0,1);
		axis.normalize3();
		bodyInfo.m_rotation = hkQuaternion(axis, 0.5f);
		bodyInfo.m_position.set(10.0f, 10.0f, 10.0f);
		hkpRigidBody* groundBody = new hkpRigidBody(bodyInfo);

		mWorld->addEntity(groundBody);
		groundBody->removeReference();

		//render it with Ogre
		Ogre::SceneNode* boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();

		//scale and rotate
		boxNode->scale(24, 2, 24);
		Ogre::Quaternion q = HkOgre::Convert::hkQuatToOgre(bodyInfo.m_rotation);
		boxNode->rotate(q);

		//display and sync
		Ogre::Entity *ent = mSceneMgr->createEntity(Ogre::StringConverter::toString(mLabMgr->getEntityCount()),"defCube.mesh");
		mLabMgr->setColor(ent, Ogre::Vector3(0.3047,0.3047,0.3047));
		HkOgre::Renderable* rend = new HkOgre::Renderable(boxNode, groundBody, mWorld);
		boxNode->attachObject(ent);

		//register to lab manager
		mLabMgr->registerEnity( boxNode, groundBody);
	}

	{
		axis.set(1,0,-1);
		axis.normalize3();
		bodyInfo.m_rotation = hkQuaternion(axis, 0.5f);
		bodyInfo.m_position.set(-10.0f, 10.0f, -10.0f);
		hkpRigidBody* groundBody = new hkpRigidBody(bodyInfo);

		mWorld->addEntity(groundBody);
		groundBody->removeReference();

		//render it with Ogre
		Ogre::SceneNode* boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();

		//scale and rotate
		boxNode->scale(24, 2, 24);
		Ogre::Quaternion q = HkOgre::Convert::hkQuatToOgre(bodyInfo.m_rotation);
		boxNode->rotate(q);

		//display and sync
		Ogre::Entity *ent = mSceneMgr->createEntity(Ogre::StringConverter::toString(mLabMgr->getEntityCount()),"defCube.mesh");
		mLabMgr->setColor(ent, Ogre::Vector3(0.3047,0.3047,0.3047));
		HkOgre::Renderable* rend = new HkOgre::Renderable(boxNode, groundBody, mWorld);
		boxNode->attachObject(ent);

		//register to lab manager
		mLabMgr->registerEnity( boxNode, groundBody);
	}


	{
		axis.set(-1,0,-1);
		axis.normalize3();
		bodyInfo.m_rotation = hkQuaternion(axis, 0.5f);
		bodyInfo.m_position.set(-10.0f, 10.0f, 10.0f);
		hkpRigidBody* groundBody = new hkpRigidBody(bodyInfo);

		mWorld->addEntity(groundBody);
		groundBody->removeReference();

		//render it with Ogre
		Ogre::SceneNode* boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();

		//scale and rotate
		boxNode->scale(24, 2, 24);
		Ogre::Quaternion q = HkOgre::Convert::hkQuatToOgre(bodyInfo.m_rotation);
		boxNode->rotate(q);

		//display and sync
		Ogre::Entity *ent = mSceneMgr->createEntity(Ogre::StringConverter::toString(mLabMgr->getEntityCount()),"defCube.mesh");
		mLabMgr->setColor(ent, Ogre::Vector3(0.3047,0.3047,0.3047));
		HkOgre::Renderable* rend = new HkOgre::Renderable(boxNode, groundBody, mWorld);
		boxNode->attachObject(ent);

		//register to lab manager
		mLabMgr->registerEnity( boxNode, groundBody);
	}

	groundShape->removeReference();
}
Beispiel #16
0
FrictionChangeDemo::FrictionChangeDemo( hkDemoEnvironment* env ) :
	hkDefaultPhysicsDemo( env )
{

	// Setup the camera.
	{
		hkVector4 from(0.0f, 10.0f, 40.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.setBroadPhaseWorldSize( 1000.0f );
		m_world = new hkpWorld(info);
		m_world->lock();

		setupGraphics();
	}

	//
	// Setup game logic variables
	//

	m_frameCount = 0;
	m_frictionChangePeriod = 100;

	//
	// Register the agents
	//
	{
		hkpAgentRegisterUtil::registerAllAgents(m_world->getCollisionDispatcher());
	}


	// In this demo we have two rigid bodies (both hkBoxShapes); the floor, which is fixed, and the sliding dynamic box.
	// These are constructed in the usual manner by filling out the hkpRigidBodyCinfo template for each. Both
	// bodies have initially been given a frictional value of 1.0:

	//
	// Create a fixed body
	//
	{	
		const hkVector4 halfExtents(20.0f, 2.f, 10.0f);
		hkpShape* shape = new hkpBoxShape(halfExtents, 0 );

		// Compute the inertia tensor from the shape
		hkpMassProperties massProperties;
		hkpInertiaTensorComputer::computeShapeVolumeMassProperties(shape, 5.0f, massProperties);

		// Assign the rigid body properties
		hkpRigidBodyCinfo bodyInfo;
		bodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
		bodyInfo.m_shape = shape;

		hkVector4 axis(0.0f, 0.0f, 1.0f);
		bodyInfo.m_rotation = hkQuaternion(axis, -0.3f);
	
		bodyInfo.m_friction = 1.f;

		hkpRigidBody *body = new hkpRigidBody(bodyInfo);
		m_world->addEntity( body );
		body->removeReference();

		shape->removeReference();
	}

	//
	// Create a moving body - we update the friction to this in the stepGame function
	//
	{	
		const hkVector4 halfExtents(2.0f, .5f, 2.0f);
		hkpShape* shape = new hkpBoxShape(halfExtents, 0 );

		// Compute the inertia tensor from the shape
		hkpMassProperties massProperties;
		hkpInertiaTensorComputer::computeShapeVolumeMassProperties(shape, 5.0f, massProperties);

		// Assign the rigid body properties
		hkpRigidBodyCinfo bodyInfo;
		bodyInfo.m_mass = massProperties.m_mass;
		bodyInfo.m_centerOfMass = massProperties.m_centerOfMass;
		bodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor;
		bodyInfo.m_shape = shape;
		bodyInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA;
		bodyInfo.m_position.set(-10.0f, 8.0f, 0.0f);

		bodyInfo.m_friction = 1.f;

		m_movingBody = new hkpRigidBody(bodyInfo);
		m_world->addEntity( m_movingBody );

		m_movingBody->removeReference();

		shape->removeReference();
	}
	
	/// As the demo runs we will dynamically alter the friction value for the moving body, alternatively setting it to 0.0 and 1.0.

	m_world->unlock();
}
void KeyframingDemo::createGround()
{
	///
	const hkVector4 halfExtents(12.0f, 1.0f, 12.0f);
	hkpShape* groundShape = new hkpBoxShape(halfExtents, 0 );

	hkpRigidBodyCinfo bodyInfo;
	bodyInfo.m_mass = 0.0f;	
	bodyInfo.m_shape = groundShape;
	bodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
	bodyInfo.m_position.set(0.0f, 0.0f, 0.0f);
	hkVector4 axis(1.0f, 0.0f, 0.0f);


	{
		axis.set(1,0,1);
		axis.normalize3();
		bodyInfo.m_rotation = hkQuaternion(axis, 0.5f);
		bodyInfo.m_position.set(10.0f, 0.0f, -10.0f);
		hkpRigidBody* groundBody = new hkpRigidBody(bodyInfo);

		m_world->addEntity(groundBody);
		groundBody->removeReference();
	}

	{
		axis.set(-1,0,1);
		axis.normalize3();
		bodyInfo.m_rotation = hkQuaternion(axis, 0.5f);
		bodyInfo.m_position.set(10.0f, 0.0f, 10.0f);
		hkpRigidBody* groundBody = new hkpRigidBody(bodyInfo);

		m_world->addEntity(groundBody);
		groundBody->removeReference();
	}

	{
		axis.set(1,0,-1);
		axis.normalize3();
		bodyInfo.m_rotation = hkQuaternion(axis, 0.5f);
		bodyInfo.m_position.set(-10.0f, 0.0f, -10.0f);
		hkpRigidBody* groundBody = new hkpRigidBody(bodyInfo);

		m_world->addEntity(groundBody);
		groundBody->removeReference();
	}


	{
		axis.set(-1,0,-1);
		axis.normalize3();
		bodyInfo.m_rotation = hkQuaternion(axis, 0.5f);
		bodyInfo.m_position.set(-10.0f, 0.0f, 10.0f);
		hkpRigidBody* groundBody = new hkpRigidBody(bodyInfo);

		m_world->addEntity(groundBody);
		groundBody->removeReference();
	}
	
	groundShape->removeReference();
}
Beispiel #18
0
void Turret::Update()
{
	
	bool PlayerInRoom = false;
	DynamicObject::Update();
	hkpWorldRayCastOutput	OutPut;
	hkpWorldRayCastInput	Ray;
	Player* theplayer = 0;
	Ogre::Vector3 RayDirection = (mPlayerPos - mPosition).normalisedCopy();
	Ray.m_from = hkVector4(mPosition.x + (RayDirection.x * 25)
						,mPosition.y + (RayDirection.y * 25)
						,mPosition.z + (RayDirection.z * 25));
    Ray.m_to = hkVector4(mPlayerPos.x, mPlayerPos.y, mPlayerPos.z);
	mPhysicsManager->GetPhysicsWorld()->castRay(Ray,OutPut);
	if(OutPut.hasHit())
	{
		const hkpCollidable* col = OutPut.m_rootCollidable;
		hkpRigidBody* body = hkpGetRigidBody(col);
		theplayer = dynamic_cast<Player*> ((BaseObject *)body->getUserData());
		if(theplayer != 0)
		{
			PlayerInRoom = true;
		}
		else
		{
			mPlayerInSight = false;
			mKillTimer = 0;
		}
	}
	Ogre::Vector3 NewDir = Ogre::Vector3(RayDirection.x,0,RayDirection.z);
	NewDir.normalise();
	Ogre::Radian angle = NewDir.angleBetween(ObjectNode->getOrientation() * Ogre::Vector3::UNIT_X);
	if(PlayerInRoom || !mPlayerInSight)
	{
		if(angle.valueDegrees() < 20 || angle.valueDegrees() > -20)
		{
			mPlayerInSight = true;
		}
	}
	if(mPlayerInSight)
	{
		mRotateValue += angle.valueRadians();
		Body->setRotation(hkQuaternion(hkVector4(0,1,0),mRotateValue));
		mKillTimer++;
		if(mKillTimer > 800)
		{
			mShutdown = true;
			//theplayer->OnDeath();
		}
	}
	else
	{
		if(mRotateValue < -2)
		{
			mChangeInRotation = 0.001;
		}
		else if (mRotateValue > 2)
		{
			mChangeInRotation = -0.001;
		}
		mRotateValue += mChangeInRotation;
		Body->setRotation(hkQuaternion(hkVector4(0,1,0),mRotateValue));
	}
}