Esempio n. 1
0
//------------------------------------------------------------------------
// [2011/3/15 jjuiddong]
//------------------------------------------------------------------------
void CChunkManager::RenderDepth()
{
	Matrix44 mat;
	mat.SetIdentity();
	g_pDevice->SetTransform( D3DTS_WORLD, (D3DXMATRIX*)&mat );

	for (int i=0; i < m_ChunkSize; ++i)
		m_pChunk[ i].RenderDepth();

	m_pWater->Render();
}
Esempio n. 2
0
//---------------------------
//
//---------------------------
Matrix44 Matrix44::GetBillboardX() const
{
	static Matrix44	matWorld;
	static Vector3	vDir;

	vDir.x = _13;
	vDir.y = _23;
	vDir.z = _33;

	if( vDir.x == 0.0F )
	{
		matWorld.SetIdentity();
	}
	else	if( vDir.x > 0.0F )
	{
		matWorld.SetRotationY( -atanf( vDir.z / vDir.x ) + MATH_PI / 2 );
	}
	else
	{
		matWorld.SetRotationY( -atanf( vDir.z / vDir.x ) - MATH_PI / 2 );
	} //if..else if..else..

	return matWorld;
} //Matrix44::GetBillboardX
Esempio n. 3
0
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_MY2DTRANSFORM, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// vertices1
	//       (-50,-50)  ----------------- (+50, -50)
	//       |                                                       |
	//       |                         +                           |
	//       |                                                       |
	//       (-50,+50)  ----------------- (+50, +50)
	const float w = 50.f;
	g_vertices1.push_back( Vector3(-w,-w,1) );
	g_vertices1.push_back( Vector3(w,-w,1) );
	g_vertices1.push_back( Vector3(w,w,1) );
	g_vertices1.push_back( Vector3(-w,w,1) );
	g_vertices1.push_back( Vector3(-w,-w,1) );


	// vertices2
	//       +(0,0)  ----------------- (+100, 0)
	//       |                                               |
	//       |                                               |
	//       |                                               |
	//       (0,+100)  ------------- (+1-0, +100)
	const float w2 = 100.f;
	g_vertices2.push_back( Vector3(0,0,1) );
	g_vertices2.push_back( Vector3(w2,0,1) );
	g_vertices2.push_back( Vector3(w2,w2,1) );
	g_vertices2.push_back( Vector3(0,w2,1) );
	g_vertices2.push_back( Vector3(0,0,1) );


	g_matWorld1.SetIdentity();
	g_matWorld1.Translate(Vector3(150,200,0));
	g_matLocal1.SetIdentity();

	g_matWorld2.SetIdentity();
	g_matWorld2.Translate(Vector3(400,200,0));	
	g_matLocal2.SetIdentity();

	g_matWorld3.SetIdentity();
	g_matWorld3.Translate(Vector3(600,200,0));	
	g_matLocal3.SetIdentity();


	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}

	MSG msg;
	HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MY2DTRANSFORM));
	int oldT = GetTickCount();
	while (GetMessage(&msg, NULL, 0, 0))
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

		const int curT = GetTickCount();
		const int elapseT = min(curT - oldT, 100);
		oldT = curT;
		MainLoop(elapseT);	
	}

	return (int) msg.wParam;
}
Esempio n. 4
0
void cViewer::MessageProc( UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_DROPFILES:
		{
			HDROP hdrop = (HDROP)wParam;
			char filePath[ MAX_PATH];
			const UINT size = DragQueryFileA(hdrop, 0, filePath, MAX_PATH);
			if (size == 0) 
				return;// handle error...

			m_filePath = filePath;
			m_model->Create(filePath);
		}
		break;

	case WM_MOUSEWHEEL:
		{
			int fwKeys = GET_KEYSTATE_WPARAM(wParam);
			int zDelta = GET_WHEEL_DELTA_WPARAM(wParam);
			dbg::Print( "%d %d", fwKeys, zDelta);

			Vector3 dir = m_lookAtPos - m_camPos;
			dir.Normalize();

			float zoomLen = 50;
			if (fwKeys & 0x4)
				zoomLen = 1;

			m_camPos += (zDelta<0)? dir*-zoomLen : dir*zoomLen;
			UpdateCamera();
		}
		break;

	case WM_KEYDOWN:
		switch (wParam)
		{
		case VK_F5: // Refresh
			{
				if (m_filePath.empty())
					return;
				m_model->Create(m_filePath);
			}
			break;
		case VK_BACK:
			// 회전 행렬 초기화.
			m_rotateTm.SetIdentity();
			m_model->SetTM(m_rotateTm);
			break;
		case VK_TAB:
			{
				static bool flag = false;
				graphic::GetDevice()->SetRenderState(D3DRS_CULLMODE, flag);
				graphic::GetDevice()->SetRenderState(D3DRS_FILLMODE, flag? D3DFILL_SOLID : D3DFILL_WIREFRAME);
				flag = !flag;
			}
			break;
		}
		break;

	case WM_LBUTTONDOWN:
		{
			m_LButtonDown = true;
			m_curPos.x = LOWORD(lParam);
			m_curPos.y = HIWORD(lParam);
		}
		break;

	case WM_LBUTTONUP:
		m_LButtonDown = false;
		break;

	case WM_RBUTTONDOWN:
		{
			m_RButtonDown = true;
			m_curPos.x = LOWORD(lParam);
			m_curPos.y = HIWORD(lParam);
		}
		break;

	case WM_RBUTTONUP:
		m_RButtonDown = false;
		break;

	case WM_MOUSEMOVE:
		if (m_LButtonDown)
		{
			POINT pos = {LOWORD(lParam), HIWORD(lParam)};
			const int x = pos.x - m_curPos.x;
			const int y = pos.y - m_curPos.y;
			m_curPos = pos;

			Matrix44 mat1;
			mat1.SetRotationY( -x * 0.01f );
			Matrix44 mat2;
			mat2.SetRotationX( -y * 0.01f );

			m_rotateTm *= (mat1 * mat2);
		}
		else if (m_RButtonDown)
		{
			POINT pos = {LOWORD(lParam), HIWORD(lParam)};
			const int x = pos.x - m_curPos.x;
			const int y = pos.y - m_curPos.y;
			m_curPos = pos;

			{ // rotate Y-Axis
				Quaternion q(Vector3(0,1,0), x * 0.005f); 
				Matrix44 m = q.GetMatrix();
				m_camPos *= m;
			}

			{ // rotate X-Axis
				Quaternion q(Vector3(1,0,0), y * 0.005f); 
				Matrix44 m = q.GetMatrix();
				m_camPos *= m;
			}

			UpdateCamera();
		}
		break;
	}
}
Esempio n. 5
0
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_SOFTWARERENDERER, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	//                   Y    Z
	//                   |   /
	//                   | /
	//    -----------------------> X
	const float axisLineLength = 300.f;
	g_axises.reserve(8);
	g_axises.push_back( Vector3(0,0,0) );
	g_axises.push_back( Vector3(axisLineLength,0,0) ); // x-axis
	g_axises.push_back( Vector3(0,0,0) );
	g_axises.push_back( Vector3(0,axisLineLength,0) ); // y-axis
	g_axises.push_back( Vector3(0,0,0) );
	g_axises.push_back( Vector3(0,0,axisLineLength) ); // z-axis


	// vertices1
	//       (-50,+50, +50)  ----------------- (+50, +50, +50)
	//       |                                                       |
	//       |                         +                           |
	//       |                                                       |
	//       (-50,+50, -50)  ----------------- (+50, +50, -50)
	//
	//       (-50,-50, +50)  ----------------- (+50, -50, +50)
	//       |                                                       |
	//       |                         +                           |
	//       |                                                       |
	//       (-50,-50, -50)  ----------------- (+50, -50, -50)

	const float w = 30.f;
	g_vertices.reserve(128);
	g_vertices.push_back( Vector3(-w,w,w) );
	g_vertices.push_back( Vector3(w,w,w) );
	g_vertices.push_back( Vector3(w,w,-w) );
	g_vertices.push_back( Vector3(-w,w,-w) );
	g_vertices.push_back( Vector3(-w,-w,w) );
	g_vertices.push_back( Vector3(w,-w,w) );
	g_vertices.push_back( Vector3(w,-w,-w) );
	g_vertices.push_back( Vector3(-w,-w,-w) );

	g_indices.reserve(128);
	// top
	g_indices.push_back(0);
	g_indices.push_back(2);
	g_indices.push_back(3);
	g_indices.push_back(0);
	g_indices.push_back(1);
	g_indices.push_back(2);
	// front
	g_indices.push_back(3);
	g_indices.push_back(2);
	g_indices.push_back(7);
	g_indices.push_back(2);
	g_indices.push_back(6);
	g_indices.push_back(7);
	// back
	g_indices.push_back(1);
	g_indices.push_back(4);
	g_indices.push_back(5);
	g_indices.push_back(1);
	g_indices.push_back(0);
	g_indices.push_back(4);
	// left
	g_indices.push_back(3);
	g_indices.push_back(4);
	g_indices.push_back(0);
	g_indices.push_back(7);
	g_indices.push_back(4);
	g_indices.push_back(3);
	// right
	g_indices.push_back(2);
	g_indices.push_back(5);
	g_indices.push_back(6);
	g_indices.push_back(2);
	g_indices.push_back(1);
	g_indices.push_back(5);
	// bottom
	g_indices.push_back(4);
	g_indices.push_back(7);
	g_indices.push_back(6);
	g_indices.push_back(4);
	g_indices.push_back(6);
	g_indices.push_back(5);


	g_matWorld.SetIdentity();
	g_matWorld.Translate(Vector3(0,0,0));
	g_matLocal.SetIdentity();

	g_matView.SetIdentity();
	Vector3 dir = g_cameraLookat - g_cameraPos;
	dir.Normalize();
	g_matView.SetView(g_cameraPos, dir, Vector3(0,1,0));
	g_matProjection.SetProjection( MATH_PI / 4.f, 1.0f, 1.0f, 100.0f );

	const float width = 800.f;
	const float height = 600.f;
	g_matViewPort.SetIdentity();
	g_matViewPort._11 = width/2;
	g_matViewPort._22 = -height/2;
	g_matViewPort._33 = 0;
	g_matViewPort._41 = width/2;
	g_matViewPort._42 = height/2;
	g_matViewPort._43 = 0;

	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}

	MSG msg;
	HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SOFTWARERENDERER));
	int oldT = GetTickCount();
	while (1)
	{
		if (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
			if(msg.message == WM_QUIT)
				break;
		}

		const int curT = GetTickCount();
		const int elapseT = curT - oldT;
		if (elapseT > 15)
		{
			oldT = curT;
			MainLoop(elapseT);	
		}
	}

	return (int) msg.wParam;
}