示例#1
0
void PhysXPhysics::VSyncVisibleScene()
{
	for (ActorIdToPysXRigidBodyTable::const_iterator it = m_actorRigidBodyMap.begin(); it != m_actorRigidBodyMap.end(); it++)
	{
		ActorId const id = it->first;

		PxTransform pxLoc = it->second->getGlobalPose();
		Mat4x4 loc;
		PxMatrixToMat4x4(PxMat44(pxLoc), &loc);
		
		Actor* pActor = g_pApp->m_pGame->VGetActor(id);
		if (pActor)
		{
			TransformComponent* pTransformComponent = pActor->GetComponent<TransformComponent>(TransformComponent::g_Name);

			if (pTransformComponent)
			{
				if (pTransformComponent->GetTransform() != loc)
				{
					Vec3 rot = loc.GetYawPitchRoll();
					pTransformComponent->SetPosition(loc.GetPosition());
					pTransformComponent->SetRotation(Vec3(XMConvertToDegrees(rot.x), XMConvertToDegrees(rot.y), XMConvertToDegrees(rot.z)));
					EventDataPtr pEvent(BE_NEW EvtData_Move_Actor(id, loc));
					IEventManager::Get()->VQueueEvent(pEvent);
				}
			}
		}
	}
}
示例#2
0
//
// TeapotWarsGame::VOnUpdate			- Chapter 19, page 709
//
void CometConquestGame::VOnUpdate(float time, float elapsedTime)
{
	int deltaMilliseconds = int(elapsedTime * 1000.0f);
	m_Lifetime += elapsedTime;
	unsigned int currentTime = timeGetTime();
	BaseGameLogic::VOnUpdate(time, elapsedTime);

	if (m_bProxy)
		return;

	switch(m_State)
	{
	case BGS_LoadingGameEnvironment:
		break;

	case BGS_MainMenu:
		break;

	case BGS_WaitingForPlayers:
		if (m_ExpectedPlayers + m_ExpectedRemotePlayers == m_HumanPlayersAttached ) 
		{
			VChangeState(BGS_LoadingGameEnvironment);
		}
		break;

	case BGS_Running:
		if(currentTime > (m_data.m_lastCometTime + 5000))
		{
			Vec4 at = -g_Right4 * 2.0f;
			Vec4 atWorld = Mat4x4::g_Identity.Xform(at);
			int randVertical = m_random.Random(115) + 1 - 60;
			Vec3 normalDir(atWorld);
			normalDir.Normalize();
			Mat4x4 temp = Mat4x4::g_Identity;
			temp.SetPosition(Vec3(110,10,randVertical));
			CometParams cp;
			cp.m_Pos = temp.GetPosition() + Vec3(atWorld);
			cp.m_Radius = 6.0f;
			cp.m_Color = g_Cyan;
			cp.m_NormalDir = normalDir;
			cp.m_Force = 40000.0f;

			const EvtData_Request_New_Actor cannonBallEvt( &cp );
			safeTriggerEvent( cannonBallEvt );
			m_data.m_lastCometTime = currentTime;
		}
		break;
	default:
		assert(0 && _T("Unrecognized state."));
	}

	// look in Chapter 15, page 563 for more on this bit of code
	if(m_pPhysics)
	{
		m_pPhysics->VOnUpdate(elapsedTime);
		m_pPhysics->VSyncVisibleScene();
	}
}
示例#3
0
void PhysicsComponent::RotateY(float angleRadians)
{
    shared_ptr<TransformComponent> pTransformComponent = MakeStrongPtr(m_pOwner->GetComponent<TransformComponent>(TransformComponent::g_Name));
    if (pTransformComponent)
    {
        Mat4x4 transform = pTransformComponent->GetTransform();
        Vec3 position = transform.GetPosition();

        Mat4x4 rotateY;
        rotateY.BuildRotationY(angleRadians);
        rotateY.SetPosition(position);

        KinematicMove(rotateY);
    }
    else
        GCC_ERROR("Attempting to call RotateY() on actor with no transform component");
}