コード例 #1
0
ファイル: renderer.cpp プロジェクト: souxiaosou/TAA
D3DXMATRIX Renderer::screenProjMatrix()
{
	D3DXMATRIX mP, mT, mS;
	D3DXMatrixOrthoRH(&mP, (float)pBackBufferSurfaceDesc_.Width, (float)pBackBufferSurfaceDesc_.Height, 0, 1.0f);
	D3DXMatrixScaling(&mS, 1.0f, -1.0f, 1.0f);
	D3DXMatrixTranslation(&mT, -1.0f, +1.0f, 0.0f);

	return  mP * mS * mT;
}
コード例 #2
0
ファイル: omnimapd3d.cpp プロジェクト: elumenati/omnimap
void OmniMapD3D::LoadAndPush_ProjectiveTexturing_Matricies()
{
  D3DXMATRIX matView;
  D3DXVECTOR3 camPos( ProjectorPosition.pos.x, ProjectorPosition.pos.y, ProjectorPosition.pos.z ); // Camera position
  D3DXVECTOR3 camLookat( ProjectorPosition.lookAtpos.x, ProjectorPosition.lookAtpos.y, ProjectorPosition.lookAtpos.z );   // Look-at point
  D3DXVECTOR3 camUp( ProjectorPosition.headsUp.x, ProjectorPosition.headsUp.y, ProjectorPosition.headsUp.z ); // Up vector

  D3DXMatrixOrthoRH(&worldViewProjection, 2.0, 2.0, 0.0, 1.0f);
  D3DXMatrixLookAtRH( &worldView, &camPos, &camLookat, &camUp);
}
コード例 #3
0
ファイル: rendershadow.cpp プロジェクト: Petethegoat/MGE-XE
// renderShadowLayer - Calculates projection for, and renders, one shadow layer
void DistantLand::renderShadowLayer(int layer, float radius)
{
    DECLARE_MWBRIDGE
    D3DXVECTOR3 lookAt, nearPos;
    D3DXVECTOR3 up(0, 0, 1);
    D3DXMATRIX *view = &smView[layer], *proj = &smProj[layer], *viewproj = &smViewproj[layer];

    // Select light vector, sunPos during daytime, sunVec during night
    D3DXVECTOR4 lightVec = (sunPos.z > 0) ? -sunPos : sunVec;

    // Centre of projection is ahead of the player
    // Not as far in z direction as player is likely looking at the ground plane rather than below
    lookAt.x = eyePos.x + radius * eyeVec.x;
    lookAt.y = eyePos.y + radius * eyeVec.y;
    lookAt.z = eyePos.z + 0.5 * radius * eyeVec.z;

    // Quantize projection centre to reduce texture swimming
    lookAt.x = 16.0 * floor(lookAt.x / 16.0);
    lookAt.y = 16.0 * floor(lookAt.y / 16.0);
    lookAt.z = 16.0 * floor(lookAt.z / 16.0);

    // Create shadow frustum centred on lookAt, looking along lightVec
    const float zrange = 8192.0;
    nearPos.x = lookAt.x - zrange * lightVec.x;
    nearPos.y = lookAt.y - zrange * lightVec.y;
    nearPos.z = lookAt.z - zrange * lightVec.z;

    D3DXMatrixLookAtRH(view, &nearPos, &lookAt, &up);
    D3DXMatrixOrthoRH(proj, 2 * radius, (1 + fabs(lightVec.z)) * radius, 0, 2.0 * zrange);
    *viewproj = (*view) * (*proj);

    // Texel quantization produces hideous temporal aliasing
    //viewproj->_41 = floor(viewproj->_41 * 512.0) / 512.0;
    //viewproj->_42 = floor(viewproj->_42 * 512.0) / 512.0;

    effect->SetMatrixArray(ehShadowViewproj, viewproj, 1);
    effectShadow->CommitChanges();

    // Cull
    ViewFrustum range_frustum(viewproj);
    VisibleSet visible_set;

    currentWorldSpace->NearStatics->GetVisibleMeshesCoarse(range_frustum, visible_set);
    currentWorldSpace->FarStatics->GetVisibleMeshesCoarse(range_frustum, visible_set);
    currentWorldSpace->VeryFarStatics->GetVisibleMeshesCoarse(range_frustum, visible_set);

    // Render land and statics
    if(mwBridge->IsExterior())
        renderDistantLand(effectShadow, view, proj);

    device->SetVertexDeclaration(StaticDecl);
    visible_set.Render(device, effectShadow, effect, &ehTex0, &ehHasAlpha, &ehWorld, SIZEOFSTATICVERT);
}
コード例 #4
0
ファイル: omnimapd3d.cpp プロジェクト: elumenati/omnimap
void OmniMapD3D::LoadAndPush_HUD_Matricies()
{
  D3DXMATRIX projMat;

  D3DXMatrixOrthoRH(&projMat, 2.0f, 2.0f, -1.0f, 1.0f);
  d3dDevice->SetTransform( D3DTS_PROJECTION, &projMat );

  D3DXMATRIX matView;
  D3DXMatrixIdentity( &matView );

  // Identity for both world and view matrices
  d3dDevice->SetTransform( D3DTS_VIEW, &matView );
  d3dDevice->SetTransform( D3DTS_WORLD, &matView );
}
コード例 #5
0
ファイル: Graphics.cpp プロジェクト: Griffone/Everward
void renderFrame(void) {
	d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 162, 232), 1.0f, 0);	// use 0, 162, 232 for nice blue color

	d3ddev->BeginScene();    // begins the 3D scene

	// SET UP THE PIPELINE
	D3DXMATRIX matTranslate;

	Vector2 mousePos = worldCoord(mouseX, mouseY);

	D3DXMatrixTranslation(&matTranslate, mousePos.x, mousePos.y, 0);

	D3DXMATRIX matView;    // the view transform matrix

	D3DXMatrixLookAtRH(&matView,
		&D3DXVECTOR3(0.0f, 0.0f, 5.0f),    // the camera position
		&D3DXVECTOR3(0.0f, 0.0f, 0.0f),    // the look-at position
		&D3DXVECTOR3(0.0f, 1.0f, 0.0f));    // the up direction

	d3ddev->SetTransform(D3DTS_VIEW, &(matView));    // set the view transform to matView

	D3DXMATRIX matProjection;     // the projection transform matrix

	D3DXMatrixOrthoRH(&matProjection,
		viewWidth,	// the horizontal view volume
		viewWidth * currentRatio,	// the vertical view volume
		0.25f,    // the near view-plane
		15.0f);    // the far view-plane

	d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);    // set the projection

	d3ddev->SetTexture(0, tx);

	// select the vertex buffer to display
	d3ddev->SetStreamSource(0, vb, 0, sizeof(CUSTOMVERTEX));

	// copy the vertex buffer to the back buffer
	d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

	RECT rect;

	SetRect(&rect, 0, 0, wndWidth, wndHeight);

	font->DrawTextA(NULL, "Everward", 8, &rect, DT_CENTER | DT_VCENTER, 0xffffff00);

	d3ddev->EndScene();    // ends the 3D scene

	d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen
}
コード例 #6
0
ファイル: viewer.cpp プロジェクト: AAnguix/TTOD_Engine
void Viewer::renderCursor()
{
	D3DXMATRIX mat;
	D3DXMatrixOrthoRH(&mat,(float)m_width,(float)m_height,-1.0f,1.0f);
    g_pD3DDevice->SetTransform( D3DTS_PROJECTION, &mat );

	D3DXMatrixIdentity( &mat );
	g_pD3DDevice->SetTransform( D3DTS_VIEW, &mat);
	g_pD3DDevice->SetTransform( D3DTS_WORLD, &mat);

	VERTEX2 Vertex[3];
	
	Vertex[0].pos=D3DXVECTOR3((float)(m_mouseX-m_width/2),(float)(m_mouseY-m_height/2),0.0f);
	Vertex[0].d=0xFFFFFFFF;

	Vertex[2].pos=D3DXVECTOR3((float)(m_mouseX+16-m_width/2),(float)( m_mouseY-32-m_height/2),0.0f);
	Vertex[2].d=0x20FFFFFF;

	Vertex[1].pos=D3DXVECTOR3((float)(m_mouseX+32-m_width/2),(float)( m_mouseY-16-m_height/2),0.0f);
	Vertex[1].d=0x20FFFFFF;

    g_pD3DDevice->SetVertexShader(NULL);
	g_pD3DDevice->SetVertexDeclaration(NULL);
	g_pD3DDevice->SetFVF(D3DFVF_VERTEX2);

	g_pD3DDevice->SetTexture(0,NULL);
	g_pD3DDevice->SetTexture(1,NULL);

	g_pD3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE,TRUE);
	g_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
	
	g_pD3DDevice->SetRenderState(D3DRS_SRCBLEND ,D3DBLEND_SRCALPHA   );
	g_pD3DDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA );
    g_pD3DDevice->SetRenderState( D3DRS_LIGHTING, FALSE );

	g_pD3DDevice->DrawPrimitiveUP( D3DPT_TRIANGLELIST,1, (void*) Vertex,sizeof(VERTEX2));

	g_pD3DDevice->SetRenderState( D3DRS_LIGHTING, TRUE );

	g_pD3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE,FALSE);
	g_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);


  
}
コード例 #7
0
ファイル: V3dMath.cpp プロジェクト: Averroes/LevelEditor
 Matrix Matrix::CreateOrthographic(float width, float height, float zn, float zf)
 {
     D3DXMATRIX mat;                 
     D3DXMatrixOrthoRH(&mat,width, height, zn, zf);
     return Matrix( (float*)&mat._11);
 }
コード例 #8
0
bool CMapOutdoor::BeginRenderCharacterShadowToTexture()
{
    D3DXMATRIX matLightView, matLightProj;

    CCamera* pCurrentCamera = CCameraManager::Instance().GetCurrentCamera();

    if (!pCurrentCamera)
        return false;

    if (recreate)
    {
        CreateCharacterShadowTexture();
        recreate = false;
    }

    D3DXVECTOR3 v3Target = pCurrentCamera->GetTarget();

    D3DXVECTOR3 v3Eye(v3Target.x - 1.732f * 1250.0f,
                      v3Target.y - 1250.0f,
                      v3Target.z + 2.0f * 1.732f * 1250.0f);

    D3DXMatrixLookAtRH(&matLightView,
                       &v3Eye,
                       &v3Target,
                       &D3DXVECTOR3(0.0f, 0.0f, 1.0f));

    D3DXMatrixOrthoRH(&matLightProj, 2550.0f, 2550.0f, 1.0f, 15000.0f);

    STATEMANAGER.SaveTransform(D3DTS_VIEW, &matLightView);
    STATEMANAGER.SaveTransform(D3DTS_PROJECTION, &matLightProj);

    dwLightEnable = STATEMANAGER.GetRenderState(D3DRS_LIGHTING);
    STATEMANAGER.SetRenderState(D3DRS_LIGHTING, FALSE);

    STATEMANAGER.SaveRenderState(D3DRS_TEXTUREFACTOR, 0xFF808080);
    STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
    STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
    STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
    STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);

    bool bSuccess = true;

    // Backup Device Context
    if (FAILED(ms_lpd3dDevice->GetRenderTarget(&m_lpBackupRenderTargetSurface)))
    {
        TraceError("CMapOutdoor::BeginRenderCharacterShadowToTexture : Unable to Save Window Render Target\n");
        bSuccess = false;
    }

    if (FAILED(ms_lpd3dDevice->GetDepthStencilSurface(&m_lpBackupDepthSurface)))
    {
        TraceError("CMapOutdoor::BeginRenderCharacterShadowToTexture : Unable to Save Window Depth Surface\n");
        bSuccess = false;
    }

    if (FAILED(ms_lpd3dDevice->SetRenderTarget(m_lpCharacterShadowMapRenderTargetSurface, m_lpCharacterShadowMapDepthSurface)))
    {
        TraceError("CMapOutdoor::BeginRenderCharacterShadowToTexture : Unable to Set Shadow Map Render Target\n");
        bSuccess = false;
    }

    if (FAILED(ms_lpd3dDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0xFF, 0xFF, 0xFF), 1.0f, 0)))
    {
        TraceError("CMapOutdoor::BeginRenderCharacterShadowToTexture : Unable to Clear Render Target");
        bSuccess = false;
    }

    if (FAILED(ms_lpd3dDevice->GetViewport(&m_BackupViewport)))
    {
        TraceError("CMapOutdoor::BeginRenderCharacterShadowToTexture : Unable to Save Window Viewport\n");
        bSuccess = false;
    }

    if (FAILED(ms_lpd3dDevice->SetViewport(&m_ShadowMapViewport)))
    {
        TraceError("CMapOutdoor::BeginRenderCharacterShadowToTexture : Unable to Set Shadow Map viewport\n");
        bSuccess = false;
    }

    return bSuccess;
}
コード例 #9
0
ファイル: CWaterApp.cpp プロジェクト: grakidov/Render3D
//-----------------------------------------------------------------------------
// Name: FrameMove
// Desc:
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::FrameMove()
{
    HRESULT hr;

    //
    // Process keyboard input
    //

    D3DXVECTOR3 vecT(0.0f, 0.0f, 0.0f);
    D3DXVECTOR3 vecR(0.0f, 0.0f, 0.0f);

    if(m_bKey[VK_NUMPAD1] || m_bKey[VK_LEFT])  vecT.x -= 1.0f; // Slide Left
    if(m_bKey[VK_NUMPAD3] || m_bKey[VK_RIGHT]) vecT.x += 1.0f; // Slide Right
    if(m_bKey[VK_DOWN])                        vecT.y -= 1.0f; // Slide Down
    if(m_bKey[VK_UP])                          vecT.y += 1.0f; // Slide Up
    if(m_bKey['W'])                            vecT.z -= 2.0f; // Move Forward
    if(m_bKey['S'])                            vecT.z += 2.0f; // Move Backward
    if(m_bKey['A'] || m_bKey[VK_NUMPAD8])      vecR.x -= 1.0f; // Pitch Down
    if(m_bKey['Z'] || m_bKey[VK_NUMPAD2])      vecR.x += 1.0f; // Pitch Up
    if(m_bKey['E'] || m_bKey[VK_NUMPAD6])      vecR.y -= 1.0f; // Turn Right
    if(m_bKey['Q'] || m_bKey[VK_NUMPAD4])      vecR.y += 1.0f; // Turn Left
    if(m_bKey[VK_NUMPAD9])                     vecR.z -= 2.0f; // Roll CW
    if(m_bKey[VK_NUMPAD7])                     vecR.z += 2.0f; // Roll CCW

    m_vecVelocity = m_vecVelocity * 0.9f + vecT * 0.1f;
    m_vecAngularVelocity = m_vecAngularVelocity * 0.9f + vecR * 0.1f;



    //
    // Update position and view matricies
    //

    D3DXMATRIX matT, matR;
    D3DXQUATERNION qR;

    vecT = m_vecVelocity * m_fElapsedTime * m_fSpeed;
    vecR = m_vecAngularVelocity * m_fElapsedTime * m_fAngularSpeed;

    D3DXMatrixTranslation(&matT, vecT.x, vecT.y, vecT.z);
    D3DXMatrixMultiply(&m_matPosition, &matT, &m_matPosition);

    D3DXQuaternionRotationYawPitchRoll(&qR, vecR.y, vecR.x, vecR.z);
    D3DXMatrixRotationQuaternion(&matR, &qR);

    D3DXMatrixMultiply(&m_matPosition, &matR, &m_matPosition);
    D3DXMatrixInverse(&m_matView, NULL, &m_matPosition);


    //
    // Update simulation
    //

    if(!m_bPause && m_bDrawWater)
    {
        BOOL bCaustics = m_bDrawCaustics && m_pEffect->IsParameterUsed("tCAU");
        D3DXVECTOR3 vecPos(m_matPosition._41, m_matPosition._42, m_matPosition._43);
        D3DXVECTOR3 vecLight(0.0f, 1.0f, 0.0f);

        m_Water.Update(vecPos, vecLight, bCaustics);
        m_fTime += m_fSecsPerFrame;

        if(bCaustics)
        {
            if(SUCCEEDED(m_pRenderToSurface->BeginScene(m_pCausticSurf, NULL)))
            {
                D3DXMATRIX matProj;
                D3DXMATRIX matView;

                D3DXMatrixOrthoRH(&matProj, 63.0f, 63.0f, 1.0f, 100.0f);
                D3DXMatrixRotationX(&matView, 0.5f * D3DX_PI);
                matView._43 = -50.0f;

                m_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj);
                m_pd3dDevice->SetTransform(D3DTS_VIEW, &matView);

                m_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, 0xff000000, 0.0f, 0);

                m_pd3dDevice->SetRenderState(D3DRS_ZENABLE, FALSE);
                m_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
                m_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);

                m_Water.DrawCaustics();

                m_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
                m_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
                m_pd3dDevice->SetRenderState(D3DRS_ZENABLE, TRUE);

                m_pRenderToSurface->EndScene();
            }
            else
            {
                m_bDrawCaustics = FALSE;
                m_pEffect->SetTexture("tCAU", NULL);

                if(FAILED(hr = GetNextTechnique(0, FALSE)))
                    return hr;
            }
        }
    }

    return S_OK;
}