예제 #1
0
파일: main.cpp 프로젝트: chenbk85/3dlearn
void GetUserInput(void)
{
	g_fFrame_Time = g_Timer.Stop();
	g_Timer.Restart();
	GutReadKeyboard();
	g_Control.Update(g_fFrame_Time, CGutUserControl::CONTROLLER_ROTATEOBJECT);
}
예제 #2
0
파일: main.cpp 프로젝트: as2120/ZNginx
void GetUserInput(void)
{
	// 讀取滑鼠
	GutMouseInfo mouse;
	if ( GutReadMouse(&mouse) )
	{
		// 取得畫完前一個畫面到現在所經歷的時間
		g_fFrame_Time = g_Timer.Stop();
		g_Timer.Restart();

		float moving_speed = 2.0f * g_fFrame_Time;
		float rotation_speed = 1.0 * g_fFrame_Time;

		// 如果按下滑鼠左鍵,就旋轉鏡頭
		if ( mouse.button[0] ) 
		{
			Matrix4x4 rotate_matrix;
			rotate_matrix.RotateY_Replace(mouse.x * rotation_speed);
			rotate_matrix.RotateX(mouse.y * rotation_speed);
			g_world_matrix = g_world_matrix * rotate_matrix;
		}
	}
}
예제 #3
0
파일: main.cpp 프로젝트: chenbk85/3dlearn
void GetUserInput(void)
{
	// `讀取滑鼠`
	GutMouseInfo mouse;
	GutReadMouse(&mouse);
	// `讀取鍵盤`
	char keyboard_state[256];
	GutReadKeyboard(keyboard_state);
	// `取得畫完前一個畫面到現在所經歷的時間`
	float time_diff = g_Timer.Stop();
	g_Timer.Restart();

	float moving_speed = 2.0f * time_diff;
	float rotation_speed = 1.0 * time_diff;

	// `極座標系統`
	static float theta = -MATH_PI * 0.5f;
	static float phi = 0.0f;

	// `如果按下滑鼠左鍵, 就旋轉鏡頭.`
	if ( mouse.button[0] ) 
	{
		theta += mouse.x * rotation_speed;
		phi -= mouse.y * rotation_speed;
	}

	float sin_phi, cos_phi;
	float sin_theta, cos_theta;

	FastMath::SinCos(phi, sin_phi, cos_phi);
	FastMath::SinCos(theta, sin_theta, cos_theta);

	// `計算鏡頭的面向`
	Vector4 camera_facing;

	camera_facing[0] = cos_phi * cos_theta;
	camera_facing[1] = sin_phi;
	camera_facing[2] = cos_phi * sin_theta;

	// `計算鏡頭正上方的軸向`
	Vector4 camera_up;
	FastMath::SinCos(phi + MATH_PI*0.5f, sin_phi, cos_phi);

	camera_up[0] = cos_phi * cos_theta;
	camera_up[1] = sin_phi;
	camera_up[2] = cos_phi * sin_theta;

	// `取得鏡面右方的方向`
	Vector4 camera_right = Vector3CrossProduct(camera_facing, camera_up);

	// `按下W或方向鍵向上`
	if ( keyboard_state[GUTKEY_W] || keyboard_state[GUTKEY_UP] )
	{
		g_eye += camera_facing * moving_speed;
	}
	// `按下S或方向鍵向下`
	if ( keyboard_state[GUTKEY_S] || keyboard_state[GUTKEY_DOWN] )
	{
		g_eye -= camera_facing * moving_speed;
	}
	// `按下A或方向鍵向左`
	if ( keyboard_state[GUTKEY_A] || keyboard_state[GUTKEY_LEFT] )
	{
		g_eye -= camera_right * moving_speed;
	}
	// `按下D或方向鍵向右`
	if ( keyboard_state[GUTKEY_D] || keyboard_state[GUTKEY_RIGHT] )
	{
		g_eye += camera_right * moving_speed;
	}

	// `計算出鏡頭對準的點, 產生鏡頭轉換矩陣時會用到.`
	g_lookat = g_eye + camera_facing;
	// `因為是對2個軸轉動, 需要更新鏡頭朝上的軸.`
	g_up = camera_up;
}