示例#1
0
bool CPhysicController::UpdateCharacterExtents (bool bent, float ammount)
{
	NxF32 height = m_fHeightControler;
	NxF32 radius = m_fRadiusControler;
	NxExtendedVec3 pos = m_pPhXController->getPosition();
	if ( bent )
	{
		//Ponerse de pie
		height += ammount;
		pos.y += ammount*0.5f;
	} 
	else 
	{ 
		//Agacharse
		height -= ammount;
		pos.y -= ammount*0.5f;
	}

	NxCapsule worldCapsule;
	worldCapsule.p0.x = worldCapsule.p1.x = (NxReal)pos.x;
	worldCapsule.p0.y = worldCapsule.p1.y = (NxReal)pos.y;
	worldCapsule.p0.z = worldCapsule.p1.z = (NxReal)pos.z;
	worldCapsule.p0.y -= height*0.5f;
	worldCapsule.p1.y += height*0.5f;
	worldCapsule.radius = radius;
	m_pPhXController->setCollision(false);	// Avoid checking overlap with ourself
	bool Status = m_pPhXScene->checkOverlapCapsule(worldCapsule);
	m_pPhXController->setCollision(true);
	if(Status)
	{
		return false;
	}

	NxExtendedVec3 position(pos.x, pos.y, pos.z);
	m_pPhXController->setPosition(position);
	SetPosition ( Vect3f ( (float)pos.x, (float)pos.y, (float)pos.z ) );
	NxCapsuleController* c = static_cast<NxCapsuleController*> (m_pPhXController);
	c->setHeight(height);
	m_fHeightControler = height;
	//CObject3D::InitMat44();
	return 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);
	}
}