Exemplo n.º 1
0
		void CharacterController::UpdateData()
		{
			if (!this->GetReady()) 
				return;

			if (controller != 0)
			{
				// reset the defaults for recreating from actorDesc.
				DllMain::ControllerManager->releaseController(*controller);
				desc.setToDefault();
			}

			desc.position	 = NxExtendedVec3(center.x, center.y, center.z);
			desc.radius		 = radius;
			desc.height		 = height;
			desc.upDirection = NX_Y;
			desc.slopeLimit	 = cosf(NxMath::degToRad(slopeLimit));
			desc.skinWidth	 = radius * 0.10f; // make it 10% of radius, gives best results (unity doc)
			desc.stepOffset	 = stepOffset;
			desc.callback	 = &hitReport;
			//desc.userData	 = dynamic_cast<ICollider*>(this);	// don't set this here, else shape has the userdata, not the actor itself
			controller = DllMain::ControllerManager->createController(DllMain::Scene, desc);

			// set the underlying kinematic actor from controller
			actor = controller->getActor();
			actor->userData = dynamic_cast<ICollider*>(this);
			rigidBody->SetActor(actor);

			// a controller is always kinematic
			rigidBody->SetKinematic(true);
		}
Exemplo n.º 2
0
		void CharacterController::SetCenter(const Vector3& center)
		{
			// don't updateData if we have a valid controller
			this->center = center.arr;
			if (controller != 0)
				controller->setPosition(NxExtendedVec3(center.X, center.Y, center.Z));
			else
				UpdateData();
		}
Exemplo n.º 3
0
void PhysXCharacter::InitCharacterAsBox(PhysX* pPhysX, const Vector3& dim)
{
    m_pPhysX = pPhysX;

    NxBoxControllerDesc bdesc;

    bdesc.extents = dim;

    bdesc.callback = dynamic_cast<NxUserControllerHitReport*>(this);
    bdesc.interactionFlag = NXIF_INTERACTION_INCLUDE;
    bdesc.position = NxExtendedVec3(0, 0, 0);
    bdesc.skinWidth = 0.1f;
    bdesc.slopeLimit = 0.707f;
    bdesc.stepOffset = 0.5f;
    bdesc.upDirection = NX_Y;

    m_pController = pPhysX->GetControllerManager()->createController(pPhysX->GetScene(), bdesc);
}
Exemplo n.º 4
0
void PhysXCharacter::InitCharacterAsCapsule(PhysX* pPhysX, float radius, float height)
{
    m_pPhysX = pPhysX;

    NxCapsuleControllerDesc cdesc;

    cdesc.climbingMode = CLIMB_CONSTRAINED;
    cdesc.height = height;
    cdesc.radius = radius;

    cdesc.callback = dynamic_cast<NxUserControllerHitReport*>(this);
    cdesc.interactionFlag = NXIF_INTERACTION_INCLUDE;
    cdesc.position = NxExtendedVec3(0, 0, 0);
    cdesc.skinWidth = 0.1f;
    cdesc.slopeLimit = 0.707f;
    cdesc.stepOffset = 0.5f;
    cdesc.upDirection = NX_Y;

    m_pController = pPhysX->GetControllerManager()->createController(pPhysX->GetScene(), cdesc);
    m_pController->setCollision(true);
}
bool UpdateCharacterExtents(NxU32 index, bool& increase)
{
	if(index&1)
	{
		NxBoxController* c = static_cast<NxBoxController*>(gManager->getController(index));
		NxVec3 extents = c->getExtents();
		NxF32 inc = 1.0f;
		NxExtendedVec3 pos = GetCharacterPos(index);
		if (increase)
		{
			extents.y += inc;
			pos.y += inc;
		} 
		else 
		{ 
			extents.y -= inc;
			pos.y -= inc;
		}

		if(1)
		{
			NxBounds3 worldBounds;
			worldBounds.setCenterExtents(NxVec3(pos.x, pos.y, pos.z), extents);
			c->setCollision(false);	// Avoid checking overlap with ourself
			bool Status = gScene->checkOverlapAABB(worldBounds);
			c->setCollision(true);
			if(Status)
			{
				printf("Can not resize box!\n");
				return false;
			}
		}

		increase = !increase;	// Increase or decrease height each time we're called

		// WARNING: the SDK currently doesn't check for collisions when changing extents, so if you're close
		// to a wall you might end up penetrating it. In some cases you might also fall through the level.
		// A more advanced implementation will take care of that later.
		c->setPosition(pos);
		return c->setExtents(extents);
	}
	else
	{
		NxCapsuleController* c = static_cast<NxCapsuleController*>(gManager->getController(index));
		NxF32 height = c->getHeight();
		NxF32 radius = c->getRadius();
		NxF32 inc = 1.0f;
		NxExtendedVec3 pos = GetCharacterPos(index);
		if (increase)
		{
			height += inc;
			pos.y += inc*0.5f;
		} 
		else 
		{ 
			height -= inc;
			pos.y -= inc*0.5f;
		}

		if(1)
		{
			NxCapsule worldCapsule;
			worldCapsule.p0.x = worldCapsule.p1.x = pos.x;
			worldCapsule.p0.y = worldCapsule.p1.y = pos.y;
			worldCapsule.p0.z = worldCapsule.p1.z = pos.z;
			worldCapsule.p0.y -= height*0.5f;
			worldCapsule.p1.y += height*0.5f;
			worldCapsule.radius = radius;
			c->setCollision(false);	// Avoid checking overlap with ourself
			bool Status = gScene->checkOverlapCapsule(worldCapsule);
			c->setCollision(true);
			if(Status)
			{
				printf("Can not resize capsule!\n");
				return false;
			}
		}

		increase = !increase;	// Increase or decrease height each time we're called

		// WARNING: the SDK currently doesn't check for collisions when changing height, so if you're close
		// to a wall you might end up penetrating it. In some cases you might also fall through the level.
		// A more advanced implementation will take care of that later.
		c->setPosition(NxExtendedVec3(pos.x, pos.y, pos.z));
		return c->setHeight(height);
	}
}
bool ResetCharacterPos(NxU32 index, const NxVec3& pos)
{
	return gManager->getController(index)->setPosition(NxExtendedVec3(pos.x, pos.y, pos.z));
}