Ejemplo n.º 1
0
PhysXRigidBody::PhysXRigidBody(
    PxPhysics* PxDevice, PhysXMaterial* Material, const ERigidBodies Type,
    scene::SceneNode* RootNode, const SRigidBodyConstruction &Construct) :
    BaseObject          (               ),
    PhysicsBaseObject   (               ),
    RigidBody           (Type, Construct),
    PhysXBaseObject     (Material       ),
    PxActor_            (0              )
{
    if (!PxDevice || !RootNode || !Material)
        throw io::stringc("Invalid arguments for rigid body");
    
    /* Create dynamic rigid body */
    PxBaseActor_ = PxActor_ = PxDevice->createRigidDynamic(
        PxTransform(PxMat44(RootNode->getTransformMatrix(true).getArray()))
    );
    
    PxBaseActor_->userData = RootNode;
    
    if (!PxActor_)
        throw io::stringc("Could not create PhysX actor for rigid body");
    
    /* Create base shape */
    switch (Type)
    {
        case RIGIDBODY_BOX:         createBox       (Construct); break;
        case RIGIDBODY_SPHERE:      createSphere    (Construct); break;
        case RIGIDBODY_CAPSULE:     createCapsule   (Construct); break;
        default:
            throw io::stringc("Unsupported rigid body type");
    }
    
    /* Initialize root node and actor */
    setRootNode(RootNode);
    
    setMass(1.0f);
}
Ejemplo n.º 2
0
PhysXCapsule::PhysXCapsule(NxScene* scene, const CapsuleInfo& info)
	: mScene(scene), mCapsule(NULL), mInvisible(0)
{
	createCapsule(info);
}
Ejemplo n.º 3
0
void SpiderDemo::buildLeg( hkpWorld* world, hkpRigidBody* rootBody, const SpiderDemo::calcLegMatrizesIn& in, int filterInfo,  Leg& legOut )
{
	hkVector4 pivot;
	hkRotation mA;
	hkRotation mB;
	doLegIk( in, pivot, mA, mB );

	const hkReal radius = .1f;

	hkpRigidBody* bodyA = createCapsule( mA, in.m_from, pivot, filterInfo, radius );
	hkpRigidBody* bodyB = createCapsule( mB, pivot, in.m_to, filterInfo, radius );

	world->addEntity( bodyA )->removeReference();
	world->addEntity( bodyB )->removeReference();

	legOut.m_lenA = in.m_lenA;
	legOut.m_lenB = in.m_lenB;
	legOut.m_constraint = HK_NULL;

	hkpConstraintChainInstance* chainInstance;
	{
		//CONSTRAINT_6D
		hkpPoweredChainData* chainData = new hkpPoweredChainData();
		chainInstance = new hkpConstraintChainInstance( chainData );

		hkpPositionConstraintMotor* strongMotor = new hkpPositionConstraintMotor();
		{
			strongMotor->m_tau = 1.0f;
			strongMotor->m_maxForce = 150000.0f;
			strongMotor->m_damping = 1.0f;
			strongMotor->m_constantRecoveryVelocity = 1.0f;
			strongMotor->m_proportionalRecoveryVelocity = 1.1f;
		}
		hkpPositionConstraintMotor* weakMotor = new hkpPositionConstraintMotor();
		{
			weakMotor->m_tau = 1.0f;
			weakMotor->m_maxForce = 550.0f;
			weakMotor->m_damping = 1.0f;
			weakMotor->m_constantRecoveryVelocity = 1.0f;
			weakMotor->m_proportionalRecoveryVelocity = 1.1f;
		}

		chainInstance->addEntity( rootBody );

		{
			hkVector4 pivotinA; pivotinA.setTransformedInversePos( rootBody->getTransform(), in.m_from );
			hkVector4 pivotinB; pivotinB.setTransformedInversePos( bodyA->getTransform(),    in.m_from );

			hkQuaternion aTw; aTw.setInverse( rootBody->getRotation() );
			hkQuaternion aTb; aTb.setMul( aTw, bodyA->getRotation() );

			chainData->addConstraintInfoInBodySpace( pivotinA, pivotinB, aTb, strongMotor, strongMotor, weakMotor );
			chainInstance->addEntity( bodyA );
		}
		{
			hkVector4 pivotinA; pivotinA.setTransformedInversePos( bodyA->getTransform(), pivot );
			hkVector4 pivotinB; pivotinB.setTransformedInversePos( bodyB->getTransform(), pivot );

			hkQuaternion aTw; aTw.setInverse( bodyA->getRotation() );
			hkQuaternion aTb; aTb.setMul( aTw, bodyB->getRotation() );

			chainData->addConstraintInfoInBodySpace( pivotinA, pivotinB, aTb, strongMotor, strongMotor, strongMotor );

			chainInstance->addEntity( bodyB );
		}
		strongMotor->removeReference();
		weakMotor->removeReference();
		chainData->removeReference();
	}
	world->addConstraint( chainInstance );
	legOut.m_constraint = chainInstance;
}
Ejemplo n.º 4
0
 iPhysicsCollision* iPhysics::createCapsule(float32 radius, float32 height, const iaMatrixf& offset)
 {
     return createCapsule(radius, height, offset, _shadowWorldID);
 }