//-------------------------------------------------------------- // append world transform void mgGL33Services::appendModelTransform( const mgMatrix4& xform) { m_modelMatrix.leftMultiply(xform); mgMatrix4 viewMatrix; viewMatrix.translate(-m_eyePt.x, -m_eyePt.y, -m_eyePt.z); viewMatrix.multiply(m_eyeMatrix); m_worldMatrix = m_modelMatrix; m_worldMatrix.multiply(viewMatrix); frustumBuildPlanes(); m_updateShaderVars = true; }
//-------------------------------------------------------------- // draw the view void mgDX9Display::drawView() { mg_d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); // if too early, do nothing if (m_theApp == NULL) return; mg_d3dDevice->BeginScene(); D3DXMatrixIdentity(&m_state->m_worldMatrix); // render sky (before light and fog, or we can't see sky) D3DXMATRIX eyeMatrix; toD3DMatrix(m_eyeMatrix, eyeMatrix); m_state->m_viewMatrix = eyeMatrix; mg_d3dDevice->SetTransform(D3DTS_PROJECTION, &m_state->m_projMatrix); mg_d3dDevice->SetTransform(D3DTS_WORLD, &m_state->m_worldMatrix); mg_d3dDevice->SetTransform(D3DTS_VIEW, &m_state->m_viewMatrix); // set defaults setMatColor(0.5, 0.5, 0.5); setLighting(false); m_theApp->drawSky(); // set up for world object rendering D3DXMatrixIdentity(&m_state->m_worldMatrix); mg_d3dDevice->SetTransform(D3DTS_PROJECTION, &m_state->m_projMatrix); mg_d3dDevice->SetTransform(D3DTS_WORLD, &m_state->m_worldMatrix); // set up view transform D3DXMATRIX translate; D3DXMatrixTranslation(&translate, (FLOAT) -m_eyePt.x, (FLOAT) -m_eyePt.y, (FLOAT) -m_eyePt.z); D3DXMatrixMultiply(&m_state->m_viewMatrix, &translate, &eyeMatrix); mg_d3dDevice->SetTransform(D3DTS_VIEW, &m_state->m_viewMatrix); frustumBuildPlanes(); setLightAndFog(); // set defaults setMatColor(0.5, 0.5, 0.5); setLighting(true); setZEnable(true); setTransparent(false); // tell the app the draw the view m_theApp->drawView(); // set up for front plane rendering. screen coordinates. D3DXMATRIX identity; D3DXMatrixIdentity(&identity); mg_d3dDevice->SetTransform(D3DTS_PROJECTION, &identity); mg_d3dDevice->SetTransform(D3DTS_WORLD, &identity); D3DXMATRIX scaling; D3DXMatrixScaling(&scaling, 2.0f/(FLOAT) m_graphicsWidth, -2.0f/(FLOAT) m_graphicsHeight, 1.0f); D3DXMatrixTranslation(&translate, -0.5f * (FLOAT) m_graphicsWidth, -0.5f * (FLOAT) m_graphicsHeight, 0.0f); D3DXMatrixMultiply(&m_state->m_viewMatrix, &translate, &scaling); mg_d3dDevice->SetTransform(D3DTS_VIEW, &m_state->m_viewMatrix); // turn off quality texture filtering. for overlay, we want the actual pixels mg_d3dDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE); mg_d3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); mg_d3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT); // set defaults for overlay setMatColor(1.0, 1.0, 1.0); setLighting(false); setZEnable(false); // tell the app to draw its overlay m_theApp->drawOverlay(); // draw the cursor, if enabled if (m_cursorEnabled) drawCursor(); // turn texture filtering back on mg_d3dDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); mg_d3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC); mg_d3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC); mg_d3dDevice->SetSamplerState(0, D3DSAMP_MAXANISOTROPY, 2); // m_state->m_deviceCaps.MaxAnisotropy); mg_d3dDevice->EndScene(); }