NxPhysicsCapsuleShape::NxPhysicsCapsuleShape( NxPhysicsActor * Actor, const NxCapsuleDesc & Desc ) : NxPhysicsShape( Actor, Desc )
{
	NxCapsuleShapeDesc ShapeDesc;
	ShapeDesc.setToDefault();
	ShapeDesc.radius = Desc.Radius;
	ShapeDesc.height =  Desc.Height-(Desc.Radius*2) ;//Desc.Height;
	ShapeDesc.name = std::string( "Capsule" + Ogre::StringConverter::toString( instance_count() )).c_str();
	ShapeDesc.density = 1000.0f;

	mShape = Actor->GetNxActor()->createShape( ShapeDesc );

	mShape->setFlag( NX_SF_DYNAMIC_DYNAMIC_CCD, true ); 

	//mShape->setFlag( NX_TRIGGER_ENABLE, IsTrigger );

	Actor->SetBodyProperties( Actor->GetBodyProperty() );
}
Example #2
0
void PhysXCapsule::createCapsule(const CapsuleInfo& info)
{
	NxCapsuleShapeDesc capsuleDesc;
	capsuleDesc.setToDefault();
	capsuleDesc.height = info.mHeight;
	capsuleDesc.radius = info.mRadius;

	NxMat33 rot0, rot1,rot2;
	rot0.rotX(info.mLocalPose.x);
	rot1.rotY(info.mLocalPose.y);
	rot2.rotZ(info.mLocalPose.z);
	rot0 = rot0 * rot1 * rot2;
	capsuleDesc.localPose.M = rot0;

	NxActorDesc actorDesc;
	actorDesc.setToDefault();
	actorDesc.shapes.pushBack(&capsuleDesc);
	actorDesc.density = 1.0;
	actorDesc.globalPose.t = info.mGlobalPose;

	mCapsule = mScene->createActor(actorDesc);
	mCapsule->userData = (void*) &mInvisible;
}
		//-----------------------------------------------------------------------
		PhysicsActor* PhysXActorExtern::createPhysicsActor(PhysicsActorDesc* physicsActorDesc, PhysicsShapeDesc* physicsShapeDesc)
		{
			if (!PhysXBridge::getSingletonPtr()->getScene() || !physicsActorDesc || !physicsShapeDesc)
				return 0;

			NxBodyDesc bodyDesc;
			bodyDesc.setToDefault();
			NxReal angularDamping = bodyDesc.angularDamping;
			NxVec3 angularVelocity = bodyDesc.angularVelocity;
			NxVec3 linearVelocity = bodyDesc.linearVelocity;
			bodyDesc.angularDamping = physicsShapeDesc->mAngularDamping;
			bodyDesc.angularVelocity = PhysXMath::convert(physicsShapeDesc->mAngularVelocity);
			bodyDesc.linearVelocity = PhysXMath::convert(physicsActorDesc->direction);

			NxActorDesc actorDesc;
			NxActorDesc defaultActorDesc;
			actorDesc.setToDefault();
			defaultActorDesc.setToDefault();
			switch (physicsShapeDesc->mPhysicsShapeType)
			{
				case ST_BOX:
				{
					PhysicsBoxDesc* physicsBoxDesc = static_cast<PhysicsBoxDesc*>(physicsShapeDesc);
					NxBoxShapeDesc boxDesc;
					boxDesc.setToDefault();
					boxDesc.dimensions = PhysXMath::convert(physicsBoxDesc->mDimensions);
					boxDesc.group = physicsBoxDesc->mCollisionGroup;
					boxDesc.groupsMask = PhysXMath::convert(physicsBoxDesc->mGroupMask);
					boxDesc.materialIndex = physicsBoxDesc->mMaterialIndex;
					actorDesc.density = NxComputeBoxDensity(2 * boxDesc.dimensions, physicsActorDesc->mass);
					actorDesc.shapes.pushBack(&boxDesc);
				}
				break;

				case ST_SPHERE:
				{
					PhysicsSphereDesc* physicsSphereDesc = static_cast<PhysicsSphereDesc*>(physicsShapeDesc);
					NxSphereShapeDesc sphereDec;
					sphereDec.setToDefault();
					sphereDec.radius = physicsSphereDesc->mRadius;
					sphereDec.group = physicsSphereDesc->mCollisionGroup;
					sphereDec.groupsMask = PhysXMath::convert(physicsSphereDesc->mGroupMask);
					sphereDec.materialIndex = physicsSphereDesc->mMaterialIndex;
					actorDesc.density = NxComputeSphereDensity(sphereDec.radius, physicsActorDesc->mass);
					actorDesc.shapes.pushBack(&sphereDec);
				}
				break;

				case ST_CAPSULE:
				{
					PhysicsCapsuleDesc* physicsCapsuleDesc = static_cast<PhysicsCapsuleDesc*>(physicsShapeDesc);
					NxCapsuleShapeDesc capsuleDec;
					capsuleDec.setToDefault();
					capsuleDec.radius = physicsCapsuleDesc->mRadius;
					capsuleDec.height = physicsCapsuleDesc->mHeight;
					capsuleDec.group = physicsCapsuleDesc->mCollisionGroup;
					capsuleDec.groupsMask = PhysXMath::convert(physicsCapsuleDesc->mGroupMask);
					capsuleDec.materialIndex = physicsCapsuleDesc->mMaterialIndex;
					actorDesc.density = NxComputeCylinderDensity(capsuleDec.radius, capsuleDec.height, physicsActorDesc->mass);
					actorDesc.shapes.pushBack(&capsuleDec);
				}
				break;
			}
			actorDesc.globalPose.t = PhysXMath::convert(physicsActorDesc->position);
			actorDesc.body = &bodyDesc;
			actorDesc.group = physicsActorDesc->collisionGroup;
			PhysXActor* physXActor = 0;
			if (!actorDesc.isValid())
			{
				actorDesc = defaultActorDesc;
				Ogre::LogManager::getSingleton().logMessage("ParticleUniverse PhysXActor: Cannot create actor; use default attributes.");
			}
			NxActor* nxActor = PhysXBridge::getSingletonPtr()->getScene()->createActor(actorDesc);

			if (nxActor)
			{
				physXActor = OGRE_NEW_T(PhysXActor, Ogre::MEMCATEGORY_SCENE_OBJECTS)();
				physXActor->position = PhysXMath::convert(nxActor->getGlobalPosition());
				physXActor->direction = PhysXMath::convert(nxActor->getLinearVelocity());
				nxActor->setGlobalOrientationQuat(PhysXMath::convert(physicsActorDesc->orientation));
				physXActor->orientation = physicsActorDesc->orientation;
				physXActor->mass = nxActor->getMass();
				physXActor->collisionGroup = nxActor->getGroup();
				physXActor->nxActor = nxActor;
			}
			return physXActor;
		}
Example #4
0
NxShape *pFactory::_createWheelShape1(NxActor *actor,pWheel1 *dstWheel,pObjectDescr *descr,pWheelDescr *wheelDescr,CK3dEntity*srcReference,CKMesh *mesh,VxVector localPos,VxQuaternion localRotation)
{
	
	#ifdef _DEBUG
		assert(dstWheel);
		assert(descr);
		assert(wheelDescr);
		assert(srcReference || mesh );
	#endif // _DEBUG

	NxShape *result = NULL;


	//################################################################
	//
	// some setup data
	//
	NxQuat rot = pMath::getFrom(localRotation);
	NxVec3 pos = getFrom(localPos);
	CK_ID srcID = mesh->GetID();

	NxConvexShapeDesc shape;
	if (!_createConvexCylinder(&shape,srcReference))
		xLogger::xLog(XL_START,ELOGERROR,E_LI_MANAGER,"Couldn't create convex cylinder mesh");

	shape.density  = descr->density;
	shape.localPose.t = pMath::getFrom(localPos);
	shape.localPose.M = rot;
	if (descr->skinWidth!=-1.0f)
		shape.skinWidth =  descr->skinWidth;
	

	//################################################################
	//
	// Create the convex shape : 
	//
	dstWheel->setWheelConvex(actor->createShape(shape)->isConvexMesh());
	
	//if (!_createConvexCylinder(shape,srcReference))
	//	xLogger::xLog(XL_START,ELOGERROR,E_LI_MANAGER,"Couldn't create convex cylinder mesh");


	//################################################################
	//
	// Find the wheels cylinder description

	pConvexCylinderSettings cylDescr;
	findSettings(cylDescr,srcReference);
	cylDescr.radius.value *=0.5f; 

	//################################################################
	//
	// Create a joint spring for the suspension 
	//

	NxReal heightModifier = (wheelDescr->wheelSuspension + cylDescr.radius.value) / wheelDescr->wheelSuspension;
	if (wheelDescr->wheelSuspension < 1)
		heightModifier = 1.f / wheelDescr->wheelSuspension;

	NxSpringDesc wheelSpring;
	wheelSpring.spring					= wheelDescr->springRestitution*heightModifier;
	wheelSpring.damper					= wheelDescr->springDamping*heightModifier;
	wheelSpring.targetValue				= wheelDescr->springBias*heightModifier;


	//################################################################
	//
	// The original code creates a material here ! We skip this !
	//

			//#########################
	

	//################################################################
	//
	// The wheel capsule is perpendicular to the floor
	//

	NxVec3 forwardAxis = getFrom(cylDescr.forwardAxis);
	NxVec3 downAxis = getFrom(cylDescr.downAxis);
	NxVec3 wheelAxis = getFrom(cylDescr.rightAxis);


	NxMaterialDesc materialDesc;
	materialDesc.restitution			= 0.0f;
	materialDesc.dynamicFriction		= wheelDescr->frictionToSide;
	materialDesc.staticFriction			= 2.0f;
	materialDesc.staticFrictionV		= wheelDescr->frictionToFront*4;
	materialDesc.dynamicFrictionV		= wheelDescr->frictionToFront;
	materialDesc.dirOfAnisotropy		= forwardAxis;
	materialDesc.frictionCombineMode	= NX_CM_MULTIPLY;
	materialDesc.flags					|=  NX_MF_ANISOTROPIC;

	

	dstWheel->material = actor->getScene().createMaterial(materialDesc);

	NxCapsuleShapeDesc capsuleShape;
	capsuleShape.radius = cylDescr.radius.value * 0.1f;
	capsuleShape.height = wheelDescr->wheelSuspension + cylDescr.radius.value;
	capsuleShape.flags = NX_SWEPT_SHAPE;

	//capsuleShape.localPose.M.setColumn(0, NxVec3( 1, 0, 0));
	//capsuleShape.localPose.M.setColumn(1, NxVec3( 0,-1, 0));
	//capsuleShape.localPose.M.setColumn(2, NxVec3( 0, 0,-1));	//rotate 180 degrees around x axis to cast downward!

	capsuleShape.materialIndex = dstWheel->material->getMaterialIndex();


	capsuleShape.localPose.M.setColumn(0, forwardAxis);
	capsuleShape.localPose.M.setColumn(1, downAxis);
	capsuleShape.localPose.M.setColumn(2, wheelAxis);
	if(wheelDescr->wheelSuspension >= 1) 
	{
		capsuleShape.localPose.t = pos + downAxis*(cylDescr.radius.value);
	}
	else 
	{
		capsuleShape.localPose.t = pos + (-1.0f *downAxis)*((cylDescr.radius.value + wheelDescr->wheelSuspension)*0.5f);
	}

	//################################################################
	//
	// Finalize 
	//
	result = dstWheel->getWheelConvex();
	if (!capsuleShape.isValid())
	{
		xLogger::xLog(XL_START,ELOGERROR,E_LI_MANAGER,"Capsule shape description during wheel1 construction was invalid");
	}
	
	dstWheel->setWheelCapsule(actor->createShape(capsuleShape)->isCapsule());
	


	dstWheel->_radius = cylDescr.radius.value;
	dstWheel->_turnAngle = 0;
	dstWheel->_turnVelocity = 0;
	dstWheel->_perimeter = dstWheel->_radius * NxTwoPi;
	dstWheel->_maxSuspension = wheelDescr->wheelSuspension;
	dstWheel->_wheelWidth = cylDescr.height.value;
	dstWheel->_maxPosition = localPos;
	
	dstWheel->_frictionToFront = wheelDescr->frictionToFront;
	dstWheel->_frictionToSide = wheelDescr->frictionToSide;


	NxU32 contactReportFlags = actor->getContactReportFlags();
	contactReportFlags |=NX_NOTIFY_ON_TOUCH;
	actor->setContactReportFlags(contactReportFlags);
	return dstWheel->getWheelCapsule();

}