// 绑定渲染目标(必须与 unbind 成对使用) Bool D3D9RenderTarget::bind(const Rect& rcDirty, Color cClear) { IDirect3DSurface9* pTexSuf = 0; _pTex->GetSurfaceLevel(0, &pTexSuf); _pDev->GetRenderTarget(0, &_pBackSuf); _pDev->SetRenderTarget(0, pTexSuf); CrabRelease(pTexSuf); _pDev->GetTransform(D3DTS_PROJECTION, (D3DXMATRIX*)_matProj); D3DXMATRIX mat; D3DXMatrixOrthoOffCenterLH(&mat, 0.0f, _ptSize.x, _ptSize.y, 0.0f, 0.0005f, 1000.0f); _pDev->SetTransform(D3DTS_PROJECTION, &mat); D3DRECT rc; rc.x1 = rcDirty.x1; rc.x2 = rcDirty.x2; rc.y1 = rcDirty.y1; rc.y2 = rcDirty.y2; HRESULT hr = _pDev->Clear(0, &rc, D3DCLEAR_TARGET, cClear, 1.0f, 0); return True; }
void IrisViewport::RenderSurface(){ if (!this->visible) return; IDirect3DSurface9 *oldSurface; IDirect3DSurface9 *eSurface; //Make Link this->renderTexture->GetSurfaceLevel(0, &(eSurface)); //Save old surface this->Device->GetRenderTarget(0, &oldSurface); //Set new render target this->Device->SetRenderTarget(0, eSurface); D3DXMATRIX proj; D3DXMatrixOrthoOffCenterLH(&proj, 0.0f, (float)this->GetWidth(), (float)this->GetHeight(), 0.0f, 0, 9999.0f); Device->SetTransform(D3DTS_PROJECTION, &proj); Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0); Device->BeginScene(); list<IIrisSprite*>::iterator it; for(it = this->sprites.begin(); it != this->sprites.end(); it++){ ((IrisSprite*)(*it))->Draw(); } Device->EndScene(); this->Device->SetRenderTarget(0, oldSurface); d3d::Release<IDirect3DSurface9*>(eSurface); }
//-------------------------------------------------------------------------------------- void CDXUTTextHelper::Begin() { if( m_pSprite9 ) m_pSprite9->Begin( D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_TEXTURE ); if( m_pSprite10 ) { D3D10_VIEWPORT VPs[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; UINT cVPs = 1; ID3D10Device* pd3dDevice = NULL; m_pSprite10->GetDevice( &pd3dDevice ); if( pd3dDevice ) { // Set projection pd3dDevice->RSGetViewports( &cVPs, VPs ); D3DXMATRIXA16 matProjection; D3DXMatrixOrthoOffCenterLH( &matProjection, ( FLOAT )VPs[0].TopLeftX, ( FLOAT ) ( VPs[0].TopLeftX + VPs[0].Width ), ( FLOAT )VPs[0].TopLeftY, ( FLOAT ) ( VPs[0].TopLeftY + VPs[0].Height ), 0.1f, 10 ); m_pSprite10->SetProjectionTransform( &matProjection ); m_pSprite10->Begin( D3DX10_SPRITE_SORT_TEXTURE ); SAFE_RELEASE( pd3dDevice ); } } }
void Font_bitmap::Begin() { tex.SetTexture(); pd->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); pd->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); pd->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_CURRENT ); pd->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE ); // pd->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); pd->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_CURRENT ); // texel*(1-pixel)+alpha*pixel pd->SetRenderState( D3DRS_ALPHABLENDENABLE, 1 ); // pd->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ZERO ); // pd->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE ); // pd->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); pd->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_INVDESTCOLOR); // pd->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ZERO ); // pd->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE ); // pd->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); pd->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_SRCALPHA ); pd->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE ); pd->GetTransform( D3DTS_PROJECTION, (D3DMATRIX*)(void*) &proj); pd->GetTransform( D3DTS_WORLD, (D3DMATRIX*)(void*) &model); D3DXMATRIX matProj; D3DXMatrixOrthoOffCenterLH( &matProj, 0, screen_x_font, 0, screen_y_font, -1, 1); pd->SetTransform( D3DTS_PROJECTION, &matProj); pd->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE ); pd->SetRenderState( D3DRS_LIGHTING, 1 ); }
void CDirect3D::SetViewport() { D3DXMATRIX matIdentity; D3DXMATRIX matProjection; D3DXMatrixOrthoOffCenterLH(&matProjection,0.0f,1.0f,0.0f,1.0f,0.0f,1.0f); D3DXMatrixIdentity(&matIdentity); pDevice->SetTransform(D3DTS_WORLD,&matIdentity); pDevice->SetTransform(D3DTS_VIEW,&matIdentity); pDevice->SetTransform(D3DTS_PROJECTION,&matProjection); SetShaderVars(true); RECT drawRect = CalculateDisplayRect(afterRenderWidth,afterRenderHeight,dPresentParams.BackBufferWidth,dPresentParams.BackBufferHeight); D3DVIEWPORT9 viewport; viewport.X = drawRect.left; viewport.Y = drawRect.top; viewport.Height = drawRect.bottom - drawRect.top; viewport.Width = drawRect.right - drawRect.left; viewport.MinZ = 0.0f; viewport.MaxZ = 1.0f; HRESULT hr = pDevice->SetViewport(&viewport); SetupVertices(); }
static void renderchain_set_mvp(void *data, unsigned vp_width, unsigned vp_height, unsigned rotation) { #if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_HLSL) video_shader_ctx_mvp_t mvp; #endif d3d_video_t *d3d = (d3d_video_t*)data; LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)d3d->dev; #if defined(_XBOX360) && defined(HAVE_HLSL) hlsl_set_proj_matrix(XMMatrixRotationZ(rotation * (M_PI / 2.0))); mvp.data = d3d; mvp.matrix = NULL; video_shader_driver_set_mvp(mvp); #elif defined(HAVE_D3D8) D3DXMATRIX p_out, p_rotate, mat; D3DXMatrixOrthoOffCenterLH(&mat, 0, vp_width, vp_height, 0, 0.0f, 1.0f); D3DXMatrixIdentity(&p_out); D3DXMatrixRotationZ(&p_rotate, rotation * (M_PI / 2.0)); d3d_set_transform(d3dr, D3DTS_WORLD, &p_rotate); d3d_set_transform(d3dr, D3DTS_VIEW, &p_out); d3d_set_transform(d3dr, D3DTS_PROJECTION, &p_out); #endif }
void d3d_set_projection_perspective(gs_scalar x, gs_scalar y, gs_scalar width, gs_scalar height, double angle) { D3DXMATRIX matRotZ, matTrans, matScale; // Calculate rotation matrix D3DXMatrixRotationZ( &matRotZ, angle ); // Roll // Calculate a translation matrix D3DXMatrixTranslation(&matTrans, -x, -y, 0); D3DXMatrixScaling(&matScale, 1, 1, 1); // Calculate our world matrix by multiplying the above (in the correct order) D3DXMATRIX matWorld=matRotZ*matTrans*matScale; D3DXMATRIX matProjection; // the projection transform matrix D3DXMatrixOrthoOffCenterLH(&matProjection, 0, (FLOAT)width, 0, (FLOAT)height, -32000.0f, // the near view-plane 32000.0f); // the far view-plane // Set the matrix to be applied to anything we render from now on d3dmgr->SetTransform( D3DTS_VIEW, &matProjection); D3DXMATRIX matProj; // the projection transform matrix D3DXMatrixPerspectiveFovLH(&matProj, D3DXToRadian(60), width/height, 0.1, 32000); // the far view-plane d3dmgr->SetTransform(D3DTS_PROJECTION, &matProj); // set the projection transform }
void DG_Ortho(float left, float top, float right, float bottom, float znear, float zfar) { D3DXMATRIX orthoMatrix; matStack[msIndex]->MultMatrixLocal(D3DXMatrixOrthoOffCenterLH( &orthoMatrix, left, right, bottom, top, znear, zfar)); UploadMatrix(); }
//Смена системы координат VOID Matrix() { //Мировая матрицы D3DXMATRIX MatrixWord; //Матрица вида D3DXMATRIX MatrixView; //Матрица проекции D3DXMATRIX MatrixProjection; /* Границы мировой системы координат 1. результат выполнения x = от -200 до 200 y = от -200 до 200 z = (глубина) -1, 1 */ D3DXMatrixOrthoOffCenterLH(&MatrixWord, -200, 200, -200, 200, -1, 1); /* Преобразуем мировую матрицу 1. Для мировой матрицы 2. указатель на метрицу */ g_pd3dDevice-> SetTransform(D3DTS_WORLD, &MatrixWord); /* Матрица вида - своего рода камера, показывающая, в каком месте располагаются наши глаза. То на что смотрим (серидина всей области просмотра) 1. результат выполнения 2. место где мы находимся 3. на что мысмотрим 4. то что мы видим */ D3DXMatrixLookAtLH(&MatrixView, &D3DXVECTOR3(0.0f,0.0f, -8.0f), &D3DXVECTOR3(0.0f,0.0f, 0.0f), &D3DXVECTOR3(0.0f,1.0f, 0.0f)); /* Преобразуем видовую матрицу 1. Для видовой матрцы 2. указатель на метрицу */ g_pd3dDevice-> SetTransform(D3DTS_VIEW, &MatrixView); /* Последний шаг установка матрицы проекции для отображения трехмерной сцены на двумерной плоскости монитора. 1. результат операции 2. определяет поле зрения в направлении оси Y, измеряется в радианах 3. коэффциент сжания, используемый для соотношения геометических размеров. Обычно равно единице 4. перений план осечения сцены 5. задний план отсечения сцены. За границей этих двух параметров ничего не рисуется */ D3DXMatrixPerspectiveFovLH(&MatrixProjection, D3DX_PI/4, 1.0f,1.0f,100.0f); /* Преобразуем проекционную матрицу 1. Для проекцонной матрицы 2. указатель на метрицу */ g_pd3dDevice -> SetTransform(D3DTS_PROJECTION, &MatrixProjection); }
void GnDirectx9Renderer::SetCamera(GnCamera* cam) { D3DXMATRIXA16 matOrtho; D3DXMATRIXA16 matView; D3DXMatrixIdentity( &matView ); D3DXMatrixOrthoOffCenterLH( &matOrtho, -0.5f, 0.5f, -0.5f, 0.5f, 0.0f, 1.0f ); mpDevice->SetTransform( D3DTS_VIEW, &matView ); mpDevice->SetTransform( D3DTS_PROJECTION, &matOrtho ); }
bool IrisApp::Setup(int Width, int Height){ // Initialization function calling ModuleIrisGraphics::SetWidth(Width); ModuleIrisGraphics::SetHeight(Height); ModuleIrisGraphics::SetDevice(this->Device); ModuleIrisInput::KeyBoardInputDevice = this->KeyBoardInputDevice; ModuleIrisInput::MouseInputDevice = this->MouseInputDevice; if (!ModuleIrisGraphics::Init()) return false; //-------------Projection Matrix Setting------------- D3DXMATRIX proj; D3DXMatrixOrthoOffCenterLH(&proj, 0, (float)Width, (float)Height, 0, 0.0f, 9999.0f); Device->SetTransform(D3DTS_PROJECTION, &proj); //-------------State Setting------------- Device->SetRenderState(D3DRS_AMBIENT, D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f)); Device->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE); //¿¹¾â³Ý Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); Device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT); /* persist to change*/ Device->SetRenderState(D3DRS_LIGHTING, true); D3DXVECTOR3 dir(0.0f, 0.0f, 1.0f); D3DXCOLOR c = d3d::WHITE; D3DLIGHT9 dirLight = d3d::InitDirectionalLight(&dir, &c); Device->SetLight(0, &dirLight); Device->LightEnable(0, true); //Device->SetRenderState(D3DRS_ZENABLE, TRUE); //Device->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS); Device->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); Device->SetRenderState(D3DRS_ALPHAREF, 0x00000000); Device->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER); Device->SetRenderState(D3DRS_NORMALIZENORMALS, true); Device->SetRenderState(D3DRS_SPECULARENABLE, true); // use alpha channel in texture for alpha Device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); Device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); // set blending factors so that alpha component determines transparency Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); // alpha enable Device->SetRenderState(D3DRS_ALPHABLENDENABLE, true); return true; }
void TwoDimensionalPlaneOperator::process(int tick) { D3DXMatrixIdentity(&identityMatrix); D3DXMatrixOrthoOffCenterLH(&projectionMatrix, 0.0f, 1.0f, 1.0f, 0.0f, -1.0f, 1.0f); }
HRESULT D3D9RenderImpl::SetupMatrices(int width, int height) { D3DXMATRIX matOrtho; D3DXMATRIX matIdentity; D3DXMatrixOrthoOffCenterLH(&matOrtho, 0, width, height, 0, 0.0f, 1.0f); D3DXMatrixIdentity(&matIdentity); HR(m_pDevice->SetTransform(D3DTS_PROJECTION, &matOrtho)); HR(m_pDevice->SetTransform(D3DTS_WORLD, &matIdentity)); return m_pDevice->SetTransform(D3DTS_VIEW, &matIdentity); }
//================================== // 函数:setupViewAndProjMat() // 目的:初始化View和ProjMat矩阵 // void setupViewAndProjMat() { // 设置观察矩阵 D3DXMATRIXA16 matView; D3DXMatrixIdentity( &matView ); g_pd3dD->SetTransform( D3DTS_VIEW, &matView ); //设置投影矩阵 D3DXMATRIXA16 matProj; D3DXMatrixOrthoOffCenterLH( &matProj, 0.0f, FLOAT(drect.right-drect.left), FLOAT(drect.bottom-drect.top), 0.0f, 0.0f, 1.0f ); g_pd3dD->SetTransform( D3DTS_PROJECTION, &matProj ); }
void GraphD3D9::update_viewport() { D3DVIEWPORT9 vp; vp.X = m_rect.left; vp.Y = m_rect.top; vp.MinZ = 0; vp.MaxZ = 1; vp.Width = std::max(LONG(1), std::min(LONG(2048),m_rect.right-m_rect.left) ); vp.Height = std::max(LONG(1), std::min(LONG(2048),m_rect.bottom-m_rect.top) ); check_result(m_device->SetViewport(&vp)); D3DXMATRIXA16 mat_tmp; D3DXMatrixIdentity(&m_transform); D3DXMatrixIdentity(&mat_tmp); D3DXMatrixScaling(&m_transform, 1.0f, -1.0f, 1.0f); D3DXMatrixTranslation(&mat_tmp, -0.5f, +0.5f, 0.0f); D3DXMatrixMultiply(&m_transform, &m_transform, &mat_tmp); float x1 = m_pos_x - m_zoom/2; float x2 = m_pos_x + m_zoom/2; float y1 = 0; float y2 = -g_thread_height*float(m_max_thread_idx+1); D3DXMatrixOrthoOffCenterLH(&mat_tmp, x1, x2, y2, y1, vp.MinZ, vp.MaxZ); D3DXMatrixMultiply(&m_transform, &m_transform, &mat_tmp); D3DXMatrixInverse(&m_transform_inverse, NULL, &m_transform); m_bg_vertices.reset(); float u = float(vp.Width)/6; float v = float(vp.Height)/6; float bx1 = -1 - 0.5f/u; float bx2 = 1 - 0.5f/u; float by1 = 1 + 0.5f/v; float by2 = -1 + 0.5f/v; DWORD bg_col = 0xFF808080; m_bg_vertices.push(Vertex(bx1, by1, 0.0f, 0, 0, bg_col)); m_bg_vertices.push(Vertex(bx2, by1, 0.0f, u, 0, bg_col)); m_bg_vertices.push(Vertex(bx2, by2, 0.0f, u, v, bg_col)); m_bg_vertices.push(Vertex(bx1, by1, 0.0f, 0, 0, bg_col)); m_bg_vertices.push(Vertex(bx2, by2, 0.0f, u, v, bg_col)); m_bg_vertices.push(Vertex(bx1, by2, 0.0f, 0, v, bg_col)); }
bool InitialiseDirectX() { g_pD3D = Direct3DCreate9(D3D_SDK_VERSION); if (g_pD3D == NULL) return false; D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; if (FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, (HWND) Shell::GetWindowHandle(), D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice))) { return false; } // Set up an orthographic projection. D3DXMATRIX projection; D3DXMatrixOrthoOffCenterLH(&projection, 0, 1024, 768, 0, -1, 1); g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &projection); // Switch to clockwise culling instead of counter-clockwise culling; Rocket generates counter-clockwise geometry, // so you can either reverse the culling mode when Rocket is rendering, or reverse the indices in the render // interface. g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); // Enable alpha-blending for Rocket. g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); // Set up the texture stage states for the diffuse texture. g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); // Disable lighting for Rocket. g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE); return true; }
void CALL HGE_Impl::Gfx_SetClipping(int x, int y, int w, int h) { D3DVIEWPORT8 vp; int scr_width, scr_height; if(!pCurTarget) { scr_width=pHGE->System_GetStateInt(HGE_SCREENWIDTH); scr_height=pHGE->System_GetStateInt(HGE_SCREENHEIGHT); } else { scr_width=Texture_GetWidth((HTEXTURE)pCurTarget->pTex); scr_height=Texture_GetHeight((HTEXTURE)pCurTarget->pTex); } if(!w) { vp.X=0; vp.Y=0; vp.Width=scr_width; vp.Height=scr_height; } else { if(x<0) { w+=x; x=0; } if(y<0) { h+=y; y=0; } if(x+w > scr_width) w=scr_width-x; if(y+h > scr_height) h=scr_height-y; vp.X=x; vp.Y=y; vp.Width=w; vp.Height=h; } vp.MinZ=0.0f; vp.MaxZ=1.0f; _render_batch(); pD3DDevice->SetViewport(&vp); D3DXMATRIX tmp; D3DXMatrixScaling(&matProj, 1.0f, -1.0f, 1.0f); D3DXMatrixTranslation(&tmp, -0.5f, +0.5f, 0.0f); D3DXMatrixMultiply(&matProj, &matProj, &tmp); D3DXMatrixOrthoOffCenterLH(&tmp, (float)vp.X, (float)(vp.X+vp.Width), -((float)(vp.Y+vp.Height)), -((float)vp.Y), vp.MinZ, vp.MaxZ); D3DXMatrixMultiply(&matProj, &matProj, &tmp); #ifdef UNDER_CE pD3DDevice->SetTransform(D3DTS_PROJECTION, (D3DMMATRIX*)&matProj, D3DMFMT_D3DMVALUE_FLOAT); #else pD3DDevice->SetTransform(D3DTS_PROJECTION, &matProj); #endif }
void Storm3D_Camera::ForceOrthogonalProjection (bool force, float minX, float maxX, float minY, float maxY) { if(force) { D3DXMatrixIdentity ( &matProj ); //D3DXMatrixOrthoLH ( &matProj , width, height, 0.1f, 1000.0f ); D3DXMatrixOrthoOffCenterLH ( &matProj, minX, maxX, minY, maxY, 0.1f, 1000.0f ); matForcedOrtho = matProj; forcedOrthogonalProjection = true; } else forcedOrthogonalProjection = false; }
//================================== // 函数:setupViewAndProjMat() // 目的:初始化View和ProjMat矩阵 // void setupViewAndProjMat() { //设置观察矩阵 D3DXMATRIXA16 matView; D3DXMatrixIdentity( &matView ); g_pd3dD->SetTransform( D3DTS_VIEW, &matView ); //RECT WindowRect; //GetClientRect(hwnd, &WindowRect); //设置投影矩阵 D3DXMATRIXA16 matProj; D3DXMatrixOrthoOffCenterLH( &matProj, 0.0f, 800.0f, 600.0f, 0.0f, 0.0f, 1.0f ); g_pd3dD->SetTransform( D3DTS_PROJECTION, &matProj ); }
void SceneBase::ClearFor2DDraw(){ //深度のクリア pDevice->Clear( 0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 40, 40, 80 ), 1.0f, 0 ); pDevice->SetRenderState( D3DRS_LIGHTING, FALSE); //2D用のビュー行列、射影行列の設定 D3DXMATRIX matView, matProj; D3DXMatrixIdentity(&matView); D3DXMatrixIdentity(&matProj); pDevice->SetTransform(D3DTS_VIEW, &matView); D3DXMatrixOrthoOffCenterLH( &matProj, 0,BASE_WIDTH,0, BASE_HEIGHT, 0.0f, 1.0f ); pDevice->SetTransform(D3DTS_PROJECTION, &matProj); SetRenderStateFor2D(); }
Matrix3& Matrix3::Orthographic( const Real l, const Real r, const Real b, const Real t, const Real zn, const Real zf ) { #ifdef __USE_D3DX__ D3DXMatrixOrthoOffCenterLH( (D3DXMATRIX*)this, l, r, b, t, zn, zf ); #else Identity(); Real d = zf - zn; e[0] = 2.0f / ( r - l ); e[5] = 2.0f / ( t - b ); e[10] = 1.0f / d; e[14] = -zn / d; #endif return *this; }
void renderchain_set_mvp(void *data, CGprogram &vPrg, unsigned vp_width, unsigned vp_height, unsigned rotation) { renderchain_t *chain = (renderchain_t*)data; D3DXMATRIX proj, ortho, rot, tmp; D3DXMatrixOrthoOffCenterLH(&ortho, 0, vp_width, 0, vp_height, 0, 1); if (rotation) D3DXMatrixRotationZ(&rot, rotation * (M_PI / 2.0)); else D3DXMatrixIdentity(&rot); D3DXMatrixMultiply(&proj, &ortho, &rot); D3DXMatrixTranspose(&tmp, &proj); renderchain_set_shader_mvp(chain, vPrg, tmp); }
static void set_mvp(void *data, unsigned vp_width, unsigned vp_height, unsigned rotation) { d3d_video_t *d3d = (d3d_video_t*)data; LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)d3d->dev; #if defined(_XBOX360) && defined(HAVE_HLSL) hlsl_set_proj_matrix(XMMatrixRotationZ(rotation * (M_PI / 2.0))); if (d3d->shader && d3d->shader->set_mvp) d3d->shader->set_mvp(d3d, NULL); #elif defined(_XBOX1) D3DXMATRIX p_out, p_rotate, mat; D3DXMatrixOrthoOffCenterLH(&mat, 0, vp_width, vp_height, 0, 0.0f, 1.0f); D3DXMatrixIdentity(&p_out); D3DXMatrixRotationZ(&p_rotate, rotation * (M_PI / 2.0)); RD3DDevice_SetTransform(d3dr, D3DTS_WORLD, &p_rotate); RD3DDevice_SetTransform(d3dr, D3DTS_VIEW, &p_out); RD3DDevice_SetTransform(d3dr, D3DTS_PROJECTION, &p_out); #endif }
void Render2DDeviceImpl::buildProjectionMatrix(u32 width, u32 height, D3DXMATRIX &matrix) { /*float m[16] = { 2.f / width, 0, 0, 0, 0, -2.f / height, 0, 0, 0, 0, 0, 0, -1, 1, 0, 1 };*/ //m_projectionMatrix = (D3DXMATRIX)m; D3DXMATRIX tmp, proj; D3DXMatrixScaling(&proj, 1.0, -1.0f, 1.0f); D3DXMatrixTranslation(&tmp, -0.5f, (f32)height + 0.5f, 0.0f); D3DXMatrixMultiply(&proj, &proj, &tmp); D3DXMatrixOrthoOffCenterLH(&tmp, 0.0f, (f32)width, 0.0f, (f32)height, 0, 1); D3DXMatrixMultiply(&matrix, &proj, &tmp); m_vsConstants->SetMatrix(m_device, m_hProjMat, (D3DXMATRIX*)&matrix); }
r_aabb_ssa r_pixel_calculator::calculate (dxRender_Visual* V) { r_aabb_ssa result = {0}; float area = float(_sqr(rt_dimensions)); // u32 id [6] ; for (u32 face=0; face<6; face++) { // setup matrices Fmatrix mProject,mView ; Fvector vFrom ; Fbox aabb ; // camera - left-to-right mView.build_camera_dir (vFrom.invert(cmDir[face]).mul(100.f), cmDir[face], cmNorm[face]) ; aabb.xform (V->vis.box,mView); D3DXMatrixOrthoOffCenterLH ( (D3DXMATRIX*)&mProject, aabb.min.x, aabb.max.x, aabb.min.y, aabb.max.y, aabb.min.z, aabb.max.z ); RCache.set_xform_world (Fidentity); RCache.set_xform_view (mView); RCache.set_xform_project (mProject); // render-0 Device.Clear (); // clear-ZB RCache.set_Shader (V->shader); V->Render (1.f); // render-1 RImplementation.HWOCC.occq_begin (id[face]); V->Render (1.f); RImplementation.HWOCC.occq_end (id[face]); } // for (u32 it=0; it<6; it++) { float pixels = (float)RImplementation.HWOCC.occq_get (id[it]); float coeff = clampr(pixels/area,float(0),float(1)); Msg ("[%d]ssa_c: %1.3f,%f/%f",it,coeff,pixels,area); result.ssa [it]= (u8)clampr(iFloor(coeff*255.f+0.5f),int(0),int(255)); } return result ; }
static void *menu_display_d3d_get_default_mvp(void) { #ifndef _XBOX static math_matrix_4x4 default_mvp; D3DXMATRIX ortho, mvp; #endif d3d_video_t *d3d = (d3d_video_t*)video_driver_get_ptr(false); if (!d3d) return NULL; #ifdef _XBOX return NULL; /* TODO/FIXME */ #else D3DXMatrixOrthoOffCenterLH(&ortho, 0, d3d->final_viewport.Width, 0, d3d->final_viewport.Height, 0, 1); D3DXMatrixTranspose(&mvp, &ortho); memcpy(default_mvp.data, (FLOAT*)mvp, sizeof(default_mvp.data)); return &default_mvp; #endif }
/** * * \param width * \param height */ void D3D9RenderSystem::setMatrix2D( const float w, const float h ) { D3DXMATRIX project; D3DXMatrixScaling(&project, 1, -1, 0); D3DXMATRIX m; D3DXMatrixTranslation(&m, 0, h, 0); D3DXMatrixMultiply(&project, &project, &m); D3DXMatrixOrthoOffCenterLH(&m, 0, w, 0, h, 0, 1000); D3DXMatrixMultiply(&project, &project, &m); D3DXMATRIX view; D3DXMatrixIdentity(&view); m_pd3dDevice->SetTransform(D3DTS_VIEW, &view); m_pd3dDevice->SetTransform(D3DTS_PROJECTION, &project); }
static void renderchain_set_mvp( cg_renderchain_t *chain, void *vertex_program, unsigned vp_width, unsigned vp_height, unsigned rotation) { D3DXMATRIX proj, ortho, rot, tmp; CGprogram vPrg = (CGprogram)vertex_program; if (!chain) return; D3DXMatrixOrthoOffCenterLH(&ortho, 0, vp_width, 0, vp_height, 0, 1); D3DXMatrixIdentity(&rot); D3DXMatrixRotationZ(&rot, rotation * (M_PI / 2.0)); D3DXMatrixMultiply(&proj, &ortho, &rot); D3DXMatrixTranspose(&tmp, &proj); renderchain_set_shader_mvp(chain, &vPrg, &tmp); }
void RenderChain::set_cg_mvp(CGprogram &vPrg, unsigned vp_width, unsigned vp_height, unsigned rotation) { D3DXMATRIX proj, ortho, rot, tmp; D3DXMatrixOrthoOffCenterLH(&ortho, 0, vp_width, 0, vp_height, 0, 1); if (rotation) D3DXMatrixRotationZ(&rot, rotation * (M_PI / 2.0)); else D3DXMatrixIdentity(&rot); D3DXMatrixMultiply(&proj, &ortho, &rot); D3DXMatrixTranspose(&tmp, &proj); #ifdef HAVE_CG CGparameter cgpModelViewProj = cgGetNamedParameter(vPrg, "modelViewProj"); if (cgpModelViewProj) cgD3D9SetUniformMatrix(cgpModelViewProj, &tmp); #endif }
void cCamera::Begin2D() { g_pEngine->core->lpd3dd9->SetRenderState( D3DRS_FOGENABLE, FALSE ); g_pEngine->core->lpd3dd9->SetRenderState( D3DRS_MULTISAMPLEANTIALIAS, false ); g_pEngine->core->lpd3dd9->SetRenderState( D3DRS_LIGHTING, FALSE ); g_pEngine->core->lpd3dd9->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE ); g_pEngine->core->lpd3dd9->GetTransform( D3DTS_WORLD, &m_lastMatrixWorld ); g_pEngine->core->lpd3dd9->GetTransform( D3DTS_VIEW, &m_lastMatrixView ); g_pEngine->core->lpd3dd9->GetTransform( D3DTS_PROJECTION, &m_lastMatrixProjection ); D3DXMATRIX identity, proj; D3DXMatrixIdentity( &identity ); g_pEngine->core->lpd3dd9->SetTransform( D3DTS_VIEW, &identity ); HWND hWnd = FindWindow( "Main", nullptr ); ::RECT clientRect; GetClientRect( hWnd, &clientRect ); D3DXMatrixOrthoOffCenterLH( &proj, 0, static_cast< float >( clientRect.right ), static_cast< float >( clientRect.bottom ), 0, 0, 1 ); g_pEngine->core->lpd3dd9->SetTransform( D3DTS_PROJECTION, &proj ); }