Пример #1
0
HRESULT APPLICATION::Render()
{
	//Setup the viewport
	D3DVIEWPORT9 v, v2;
	v.Width = 800;
	v.Height = 600;
	v.X = 0;
	v.Y = 0;
	v.MaxZ = 1.0f;
	v.MinZ = 0.0f;
	m_pDevice->SetViewport(&v);
	v2 = v;

    // Clear the viewport
    m_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff4444ff, 1.0f, 0L );

    // Begin the scene 
    if(SUCCEEDED(m_pDevice->BeginScene()))
    {
		//Render big city
		m_city.Render(&m_camera);

		RECT r[] = {{10, 10, 0, 0}, {10, 30, 0, 0}, {10, 50, 0, 0}};
		m_pFont->DrawText(NULL, "Mouse Wheel: Change Camera Radius", -1, &r[0], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000);
		m_pFont->DrawText(NULL, "Arrows: Change Camera Angle", -1, &r[1], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000);
		
		//Render city overview, set viewport
		v.X = 550;
		v.Y = 20;
		v.Width = 230;
		v.Height = 230;
		m_pDevice->SetViewport(&v);
		m_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0L );

		//Setup camera view to orthogonal view looking down on city
		D3DXMATRIX viewTop, projectionTop;
		D3DXMatrixLookAtLH(&viewTop, &(m_city.GetCenter() + D3DXVECTOR3(0.0f, 100.0f, 0.0f)), &m_city.GetCenter(), &D3DXVECTOR3(0,0,1));
		D3DXMatrixOrthoLH(&projectionTop, m_city.m_size.x * TILE_SIZE, m_city.m_size.y * TILE_SIZE, 0.1f, 1000.0f);
		m_pDevice->SetTransform(D3DTS_VIEW, &viewTop);
		m_pDevice->SetTransform(D3DTS_PROJECTION, &projectionTop);
		
		//Draw city blocks that are in view
		m_city.Render(NULL);

		//Restore viewport
		m_pDevice->SetViewport(&v2);

		//Draw line around smaller window
		D3DXVECTOR2 outline[] = {D3DXVECTOR2(550, 20), D3DXVECTOR2(779, 20), D3DXVECTOR2(779, 249), D3DXVECTOR2(550, 249), D3DXVECTOR2(550, 20)};
		m_pLine->SetWidth(3.0f);
		m_pLine->Begin();
		m_pLine->Draw(outline, 5, 0xff000000);
		m_pLine->End();

		//Draw mouse
		m_mouse.Paint();

        // End the scene.
		m_pDevice->EndScene();
		m_pDevice->Present(0, 0, 0, 0);
    }

	return S_OK;
}
Пример #2
0
HRESULT APPLICATION::Render()
{
    // Clear the viewport
    m_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0L );
	
    // Begin the scene 
    if(SUCCEEDED(m_pDevice->BeginScene()))
    {
		for(int i=0;i<(int)m_objects.size();i++)
			m_objects[i].Render();
		
		//Find intersecting object closest to the camera
		D3DXMATRIX identity;
		D3DXMatrixIdentity(&identity);

		int object = -1;
		float bestDist = 100000.0f;
		for(int i=0;i<(int)m_objects.size() - 1;i++)
		{
			float dist = -1.0f; 
			
			//Do intersection tests
			if(m_intersectType == 0)
			{
				m_pDevice->SetTransform(D3DTS_WORLD, &m_objects[i].m_meshInstance.GetWorldMatrix());
				RAY ray = m_mouse.GetRay();
				dist = ray.Intersect(m_objects[i].m_meshInstance);
			}
			else if(m_intersectType == 1)
			{				
				m_pDevice->SetTransform(D3DTS_WORLD, &identity);
				RAY ray = m_mouse.GetRay();
				dist = ray.Intersect(m_objects[i].m_BBox);
			}
			else if(m_intersectType == 2)
			{
				m_pDevice->SetTransform(D3DTS_WORLD, &identity);
				RAY ray = m_mouse.GetRay();
				dist = ray.Intersect(m_objects[i].m_BSphere);
			}

			m_objects[i].RenderBoundingVolume(m_intersectType);

			if(dist >= 0.0f && dist < bestDist)
			{
				object = i;
				bestDist = dist;
			}
		}

		//Write m_mouse text
		if(object != -1)
		{
			RECT mr[] = {{m_mouse.x + 2, m_mouse.y + 24, 0, 0}, {m_mouse.x, m_mouse.y + 22, 0, 0}};
			m_pFontMouse->DrawText(NULL, m_objects[object].m_name.c_str(), -1, &mr[0], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000);
			m_pFontMouse->DrawText(NULL, m_objects[object].m_name.c_str(), -1, &mr[1], DT_LEFT| DT_TOP | DT_NOCLIP, 0xffff0000);
		}

		RECT r[] = {{10, 10, 0, 0}, {10, 30, 0, 0}, {10, 50, 0, 0}};
		m_pFont->DrawText(NULL, "Mouse Wheel: Change Camera Radius", -1, &r[0], DT_LEFT| DT_TOP | DT_NOCLIP, 0xffffffff);
		m_pFont->DrawText(NULL, "Arrows: Change Camera Angle", -1, &r[1], DT_LEFT| DT_TOP | DT_NOCLIP, 0xffffffff);
		m_pFont->DrawText(NULL, "Space: Change Bounding Volume", -1, &r[2], DT_LEFT| DT_TOP | DT_NOCLIP, 0xffffffff);

		RECT rc = {500, 10, 0, 0};
		if(m_intersectType == 0)
			m_pFont->DrawText(NULL, "Mesh Intersection Test", -1, &rc, DT_LEFT| DT_TOP | DT_NOCLIP, 0xffffffff);
		else if(m_intersectType == 1)
			m_pFont->DrawText(NULL, "Box Intersection Test", -1, &rc, DT_LEFT| DT_TOP | DT_NOCLIP, 0xffffffff);
		else if(m_intersectType == 2)
			m_pFont->DrawText(NULL, "Sphere Intersection Test", -1, &rc, DT_LEFT| DT_TOP | DT_NOCLIP, 0xffffffff);
		
		//Draw m_mouse
		m_mouse.Paint();

        // End the scene.
		m_pDevice->EndScene();
		m_pDevice->Present(0, 0, 0, 0);
    }

	return S_OK;
}