Ejemplo n.º 1
0
QPoint Ghost::pinkyChaseTarget()
{
    QPoint pacmanTarget = pacman->position();
    pacmanTarget += directionToMove(pacman->direction()) * 4;
    return pacmanTarget;
}
Ejemplo n.º 2
0
QPoint Ghost::inkyChaseTarget()
{
    QPoint inkyTarget = pacman->position() + directionToMove(pacman->direction()) * 2;
    inkyTarget = inkyTarget * 2 - blinky->position();
    return inkyTarget;
}
Ejemplo n.º 3
0
void ColoredCubeApp::updateScene(float dt)
{
	D3DApp::updateScene(dt);

	if(GetAsyncKeyState(VK_ESCAPE)) PostQuitMessage(0);

	float moveRate = 1.0f;
	if(GetAsyncKeyState(VK_LSHIFT))
		moveRate *= 2.0f;
	if(GetAsyncKeyState(VK_LCONTROL))
		moveRate *= 0.1f;


	//Move camera with mouse
	if(!createdOriginPos)
	{
		mCursorOriginPos.x = 100;
		mCursorOriginPos.y = 100;
		ClientToScreen(mhMainWnd, &mCursorOriginPos);
		SetCursorPos(mCursorOriginPos.x, mCursorOriginPos.y);
		ShowCursor(false);
		createdOriginPos = true;
	}

	GetCursorPos(&mCursorPos);
	float myX = ((float)mCursorOriginPos.x - (float)mCursorPos.x);
	float myY = ((float)mCursorOriginPos.y - (float)mCursorPos.y);

	//if(dt < 0.01f)
	{
		mTheta += myX * 0.005f;//  * dt * 4.0f;
		mPhi   -= myY * 0.005f;//  * dt * 4.0f;
		//myOutFile  << std::fixed << std::setprecision(4) << dt << " " << mTheta << " " << mPhi << "\n";
	}

	SetCursorPos(mCursorOriginPos.x, mCursorOriginPos.y);


	//Move camera with gamepad
	XINPUT_STATE state;
	ZeroMemory( &state, sizeof(XINPUT_STATE) );
	DWORD gamepadConnected = XInputGetState(0, &state);

	if( gamepadConnected == ERROR_SUCCESS )
	{
		float RX = state.Gamepad.sThumbRX;
		float RY = state.Gamepad.sThumbRY;
		float magnitude = sqrt(RX*RX + RY*RY);
		if(magnitude > 10000.0f)
		{
			mTheta += RX * dt * -0.0001f;
			mPhi   += RY * dt * -0.00005f;
		}
	}


	// Move camera with keyboard
	// Update angles based on input to orbit camera around box.
	if(GetAsyncKeyState('J') & 0x8000)	mTheta += 2.0f*dt;
	if(GetAsyncKeyState('L') & 0x8000)	mTheta -= 2.0f*dt;
	if(GetAsyncKeyState('I') & 0x8000)	mPhi -= 2.0f*dt;
	if(GetAsyncKeyState('K') & 0x8000)	mPhi += 2.0f*dt;

	// Restrict the angle mPhi.
	if( mPhi < 0.1f )	mPhi = 0.1f;
	if( mPhi > PI-0.1f)	mPhi = PI-0.1f;
	
	// Convert Spherical to Cartesian coordinates: mPhi measured from +y
	// and mTheta measured counterclockwise from -z.

	D3DXVECTOR3 targetPos(
		5.0f*sinf(mPhi)*sinf(mTheta),
		5.0f*cosf(mPhi),
		-5.0f*sinf(mPhi)*cosf(mTheta)
		);


	if(gamepadConnected == ERROR_SUCCESS)
	{
		// Move the camera with the left thumbstick
		float LX = state.Gamepad.sThumbLX;
		float LY = state.Gamepad.sThumbLY;
		float magnitude = sqrt(LX*LX + LY*LY);
		if(magnitude > 10000.0f)
		{
			// Forward and Backward movement added to move; directionToMoveForwardBackward
			D3DXVECTOR3 directionToMoveForwardBackward(0.0f,0.0f,0.0f);
			directionToMoveForwardBackward = targetPos;
			D3DXVec3Normalize(&directionToMoveForwardBackward, &directionToMoveForwardBackward);
			directionToMoveForwardBackward *= state.Gamepad.sThumbLY * dt * 0.001f;
			mCameraPos += directionToMoveForwardBackward;

			// Right and Left movement added to move; directionToMoveRightLeft
			D3DXVECTOR3 directionToMoveRightLeft(0.0f,0.0f,0.0f);
			D3DXVECTOR3 pointAboveTarget(
				5.0f*sinf(mPhi)*sinf(mTheta),
				5.0f*cosf(mPhi)+0.1f,
				-5.0f*sinf(mPhi)*cosf(mTheta)
				);
			D3DXVec3Cross(&directionToMoveRightLeft, &targetPos, &pointAboveTarget);
			D3DXVec3Normalize(&directionToMoveRightLeft, &directionToMoveRightLeft);
			directionToMoveRightLeft *= state.Gamepad.sThumbLX * dt * -0.001f;
			mCameraPos +=directionToMoveRightLeft;
		}
	}


	if( (GetAsyncKeyState('D') & 0x8000) ||
		(GetAsyncKeyState('A') & 0x8000) ||
		(GetAsyncKeyState('W') & 0x8000) ||
		(GetAsyncKeyState('S') & 0x8000) ||
		(gamepadConnected == ERROR_SUCCESS && state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) ||
		(gamepadConnected == ERROR_SUCCESS && state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT)  ||
		(gamepadConnected == ERROR_SUCCESS && state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP)    ||
		(gamepadConnected == ERROR_SUCCESS && state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN)
		)
	{
		D3DXVECTOR3 move(0.0f,0.0f,0.0f);

		if((GetAsyncKeyState('D') & 0x8000) || (gamepadConnected == ERROR_SUCCESS && state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT))
		{
			D3DXVECTOR3 pointAboveTarget(
				5.0f*sinf(mPhi)*sinf(mTheta),
				5.0f*cosf(mPhi)+0.1f,
				-5.0f*sinf(mPhi)*cosf(mTheta)
				);
			D3DXVECTOR3 directionToMove(0.0f,0.0f,0.0f);
			D3DXVec3Cross(&directionToMove, &targetPos, &pointAboveTarget);
			D3DXVec3Normalize(&directionToMove, &directionToMove);
			move = move - directionToMove;
		}
		if((GetAsyncKeyState('A') & 0x8000) || (gamepadConnected == ERROR_SUCCESS && state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT))
		{
			D3DXVECTOR3 pointAboveTarget(
				5.0f*sinf(mPhi)*sinf(mTheta),
				5.0f*cosf(mPhi)+0.1f,
				-5.0f*sinf(mPhi)*cosf(mTheta)
				);
			D3DXVECTOR3 directionToMove(0.0f,0.0f,0.0f);
			D3DXVec3Cross(&directionToMove, &targetPos, &pointAboveTarget);
			D3DXVec3Normalize(&directionToMove, &directionToMove);
			move = move + directionToMove;
		}
		if((GetAsyncKeyState('W') & 0x8000) || (gamepadConnected == ERROR_SUCCESS && state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP))
		{
			D3DXVECTOR3 directionToMove(0.0f,0.0f,0.0f);
			directionToMove = targetPos;
			D3DXVec3Normalize(&directionToMove, &directionToMove);
			move = move + directionToMove;
		}
		if((GetAsyncKeyState('S') & 0x8000) || (gamepadConnected == ERROR_SUCCESS && state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN))
		{
			D3DXVECTOR3 directionToMove(0.0f,0.0f,0.0f);
			directionToMove = targetPos;
			D3DXVec3Normalize(&directionToMove, &directionToMove);
			move = move - directionToMove;
		}


		D3DXVec3Normalize(&move, &move);
		mCameraPos += move * dt * 20.0f * moveRate;
	}

	if(GetAsyncKeyState('1'))
	{
		//mLights[1].specular = BLUE;
		mLights[1].pos = mCameraPos;
	}
	if(GetAsyncKeyState('2'))
	{
		mLights[1].specular = GREEN;
	}
	
	
	targetPos = targetPos + mCameraPos;

	// Build the view matrix.
	//D3DXVECTOR3 pos(cameraPos.x, cameraPos.y, cameraPos.z);
	//D3DXVECTOR3 target(mCameraVec.x, mCameraVec.y, mCameraVec.z);
	D3DXVECTOR3 target(targetPos.x, targetPos.y, targetPos.z);
	D3DXVECTOR3 pos(mCameraPos.x, mCameraPos.y, mCameraPos.z);
	D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
	D3DXMatrixLookAtLH(&mView, &pos, &target, &up);
}