Exemplo n.º 1
0
void Camera::UpdatePosition(float dt)
{
	InputSystem* inputSystem = EngineStatics::getInputSystem();
	//HydraManager* hydra = inputSystem->getHydra();

	float speedScalar = 14.0f * mMaxSpeed;
	Vector3 forwardOffset = mDirection * speedScalar * dt;
	Vector3 sidewaysOffset = Cross(mDirection, Vector3(0.0f, 1.0f, 0.0f)) * speedScalar * dt;

	if (!mFreeRoam)
	{
		//Add to position based on direction
		//XMStoreFloat3(&mPosition, XMLoadFloat3(&mPosition) + forwardOffset);

		if (inputSystem->getKeyboardState()->IsKeyPressed(KeyboardKey::KEY_W))
		{
			mVelocity *= powf(2.0f, dt * 2.0f);
		}
		if (inputSystem->getKeyboardState()->IsKeyPressed(KeyboardKey::KEY_S))
		{
			mVelocity *= powf(0.5f, dt * 2.0f);
		}
	}
	else
	{
		if (inputSystem->getKeyboardState()->IsKeyPressed(KeyboardKey::KEY_W))
		{
			mVelocity += forwardOffset;
			//mPosition += forwardOffset;
		}

		if (inputSystem->getKeyboardState()->IsKeyPressed(KeyboardKey::KEY_S))
		{
			mVelocity -= forwardOffset;
			//mPosition -= forwardOffset;
		}

		if (inputSystem->getKeyboardState()->IsKeyPressed(KeyboardKey::KEY_A))
		{
			mVelocity -= sidewaysOffset;
			//mPosition -= sidewaysOffset;
		}

		if (inputSystem->getKeyboardState()->IsKeyPressed(KeyboardKey::KEY_D))
		{
			mVelocity += sidewaysOffset;
			//mPosition += sidewaysOffset;
		}
	}

	if (Length(mVelocity) > mMaxSpeed)
	{
		mVelocity = Normalize(mVelocity);
		mVelocity *= mMaxSpeed;
	}

	mPosition += mVelocity * dt;
	mVelocity *= powf(0.01f, dt);

}