当前位置: 首页>>代码示例>>C++>>正文


C++ CModelViewerCamera::GetViewMatrix方法代码示例

本文整理汇总了C++中CModelViewerCamera::GetViewMatrix方法的典型用法代码示例。如果您正苦于以下问题:C++ CModelViewerCamera::GetViewMatrix方法的具体用法?C++ CModelViewerCamera::GetViewMatrix怎么用?C++ CModelViewerCamera::GetViewMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CModelViewerCamera的用法示例。


在下文中一共展示了CModelViewerCamera::GetViewMatrix方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: OnFrameRender

//--------------------------------------------------------------------------------------
// This callback function will be called at the end of every frame to perform all the 
// rendering calls for the scene, and it will also be called if the window needs to be 
// repainted. After this function has returned, DXUT will call 
// IDirect3DDevice9::Present to display the contents of the next buffer in the swap chain
//--------------------------------------------------------------------------------------
void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
    // If the settings dialog is being shown, then
    // render it instead of rendering the app's scene
    if( g_SettingsDlg.IsActive() )
    {
        g_SettingsDlg.OnRender( fElapsedTime );
        return;
    }

    HRESULT hr;

    // Clear the render target and the zbuffer 
    V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 50, 50, 50 ), 1.0f, 0 ) );

    // Render the scene
    if( SUCCEEDED( pd3dDevice->BeginScene() ) )
    {
        // Get the projection & view matrix from the camera class
        D3DXMATRIXA16 mViewProjection = ( *g_Camera.GetViewMatrix() ) * ( *g_Camera.GetProjMatrix() );

        g_Skybox.SetDrawSH( false );
        g_Skybox.Render( &mViewProjection, 1.0f, 1.0f );

        V( g_pEffect->SetMatrix( "g_mViewProjection", &mViewProjection ) );
        V( g_pEffect->SetFloat( "g_fTime", ( float )fTime ) );

        // Set the amount of transmitted light per color channel
        D3DXVECTOR3 vColorTransmit;
        vColorTransmit.x = g_SampleUI.GetSlider( IDC_RED_TRANSMIT_SLIDER )->GetValue() / 1000.0f;
        vColorTransmit.y = g_SampleUI.GetSlider( IDC_GREEN_TRANSMIT_SLIDER )->GetValue() / 1000.0f;
        vColorTransmit.z = g_SampleUI.GetSlider( IDC_BLUE_TRANSMIT_SLIDER )->GetValue() / 1000.0f;
        V( g_pEffect->SetFloatArray( "g_vColorTransmit", vColorTransmit, 3 ) );

        // for Cubic degree rendering
        V( g_pEffect->SetFloat( "g_fLightIntensity", g_fLightIntensity ) );
        V( g_pEffect->SetFloatArray( "g_vLightDirection", g_vLightDirection, 3 * sizeof( float ) ) );
        V( g_pEffect->SetFloatArray( "g_vLightCoeffsR", m_fRLC, 4 * sizeof( float ) ) );
        V( g_pEffect->SetFloatArray( "g_vLightCoeffsG", m_fGLC, 4 * sizeof( float ) ) );
        V( g_pEffect->SetFloatArray( "g_vLightCoeffsB", m_fBLC, 4 * sizeof( float ) ) );

        pd3dDevice->SetRenderState( D3DRS_FILLMODE, g_bWireFrame ? D3DFILL_WIREFRAME : D3DFILL_SOLID );

        DrawFrame( pd3dDevice, g_pFrameRoot );

        DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" ); // These events are to help PIX identify what the code is doing
        RenderText();
        V( g_HUD.OnRender( fElapsedTime ) );
        V( g_SampleUI.OnRender( fElapsedTime ) );
        V( g_LightControl.OnRender9( D3DXCOLOR( 1, 1, 1, 1 ), ( D3DXMATRIX* )g_Camera.GetViewMatrix(),
                                     ( D3DXMATRIX* )g_Camera.GetProjMatrix(), g_Camera.GetEyePt() ) );
        DXUT_EndPerfEvent();

        V( pd3dDevice->EndScene() );
    }
}
开发者ID:KNeal,项目名称:Oculus,代码行数:62,代码来源:LocalDeformablePRT.cpp

示例2: XMMatrixTranspose

//--------------------------------------------------------------------------------------
// Render the scene using the D3D11 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext,
                                  double fTime, float fElapsedTime, void* pUserContext )
{
	pd3dImmediateContext->ClearRenderTargetView(DXUTGetD3D11RenderTargetView(), Colors::MidnightBlue);
	pd3dImmediateContext->ClearDepthStencilView(DXUTGetD3D11DepthStencilView(), D3D11_CLEAR_DEPTH, 1.0, 0);
	
	XMMATRIX mview = g_camera.GetViewMatrix();
	XMMATRIX mproj = g_camera.GetProjMatrix();
	XMFLOAT4 LitDir = XMFLOAT4(-0.577f, 0.577f, -0.577f, 1.0f);
	XMFLOAT4 LitCol = XMFLOAT4(0.9f, 0.2f, 0.3f, 1.0f);

	/*
		SHADER CONSTANT BUFFER
	*/
	ConstantBuffer cb;
	XMStoreFloat4x4(&(cb.world), XMMatrixTranspose(g_mesh.World()));
	XMStoreFloat4x4(&(cb.view), XMMatrixTranspose(mview));
	XMStoreFloat4x4(&(cb.projection), XMMatrixTranspose(mproj));
	cb.litDir = LitDir;
	cb.litCol = LitCol;

	g_shader->RenderPrepare(&cb);

	g_mesh.Render();
}
开发者ID:contacoonta,项目名称:sgap-direct3d,代码行数:28,代码来源:DXUTMain.cpp

示例3: OnFrameRender

//--------------------------------------------------------------------------------------
// This callback function will be called at the end of every frame to perform all the 
// rendering calls for the scene, and it will also be called if the window needs to be 
// repainted. After this function has returned, DXUT will call 
// IDirect3DDevice9::Present to display the contents of the next buffer in the swap chain
//--------------------------------------------------------------------------------------
void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
    // If the settings dialog is being shown, then
    // render it instead of rendering the app's scene
    if( g_SettingsDlg.IsActive() )
    {
        g_SettingsDlg.OnRender( fElapsedTime );
        return;
    }

    HRESULT hr;
    D3DXMATRIXA16 mWorld;
    D3DXMATRIXA16 mView;
    D3DXMATRIXA16 mProj;
    D3DXMATRIXA16 mWorldViewProjection;


    // Clear the render target and the zbuffer 
    V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 141, 153, 191 ), 1.0f, 0 ) );

    // Render the scene
    if( SUCCEEDED( pd3dDevice->BeginScene() ) )
    {
        // Get the projection & view matrix from the camera class
        mWorld = *g_Camera.GetWorldMatrix();
        mView = *g_Camera.GetViewMatrix();
        mProj = *g_Camera.GetProjMatrix();

        mWorldViewProjection = mWorld * mView * mProj;

        // Update the effect's variables. 
        V( g_pEffect->SetMatrix( g_hWorldViewProjection, &mWorldViewProjection ) );
        V( g_pEffect->SetMatrix( g_hWorld, &mWorld ) );
        V( g_pEffect->SetFloat( g_hTime, ( float )fTime ) );
        V( g_pEffect->SetValue( g_hCameraPosition, g_Camera.GetEyePt(), sizeof( D3DXVECTOR3 ) ) );

        UINT iCurSubset = ( UINT )( INT_PTR )g_SampleUI.GetComboBox( IDC_SUBSET )->GetSelectedData();

        // A subset of -1 was arbitrarily chosen to represent all subsets
        if( iCurSubset == -1 )
        {
            // Iterate through subsets, changing material properties for each
            for( UINT iSubset = 0; iSubset < g_MeshLoader.GetNumMaterials(); iSubset++ )
            {
                RenderSubset( iSubset );
            }
        }
        else
        {
            RenderSubset( iCurSubset );
        }

        RenderText();
        V( g_HUD.OnRender( fElapsedTime ) );
        V( g_SampleUI.OnRender( fElapsedTime ) );

        V( pd3dDevice->EndScene() );
    }
}
开发者ID:KNeal,项目名称:Oculus,代码行数:65,代码来源:MeshFromObj.cpp

示例4: lightDir

//--------------------------------------------------------------------------------------
// Render the scene using the D3D10 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D10FrameRender( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
    // Clear the render target
    float ClearColor[4] = { 0.9569f, 0.9569f, 1.0f, 0.0f };
    ID3D10RenderTargetView* pRTV = DXUTGetD3D10RenderTargetView();
    pd3dDevice->ClearRenderTargetView( pRTV, ClearColor );
    ID3D10DepthStencilView* pDSV = DXUTGetD3D10DepthStencilView();
    pd3dDevice->ClearDepthStencilView( pDSV, D3D10_CLEAR_DEPTH, 1.0, 0 );

    // Render the result
    D3DXMATRIX mWorld;
    D3DXMATRIX mView;
    D3DXMATRIX mProj;
    D3DXMATRIX mWorldView;
    D3DXMATRIX mWorldViewProj;
    mWorld = *g_Camera.GetWorldMatrix();
    mProj = *g_Camera.GetProjMatrix();
    mView = *g_Camera.GetViewMatrix();
    mWorldView = mWorld * mView;
    mWorldViewProj = mWorldView * mProj;

    // Set variables
    g_pmWorldViewProj->SetMatrix( ( float* )&mWorldViewProj );
    g_pmWorldView->SetMatrix( ( float* )&mWorldView );
    g_pmWorld->SetMatrix( ( float* )&mWorld );
    g_pmView->SetMatrix( ( float* )&mView );
    g_pmProj->SetMatrix( ( float* )&mProj );
    g_pDiffuseTex->SetResource( g_pMeshTexRV );
    D3DXVECTOR3 lightDir( -1,1,-1 );
    D3DXVECTOR3 viewLightDir;
    D3DXVec3TransformNormal( &viewLightDir, &lightDir, &mView );
    D3DXVec3Normalize( &viewLightDir, &viewLightDir );
    g_pViewSpaceLightDir->SetFloatVector( ( float* )&viewLightDir );

    // Set Input Assembler params
    UINT stride = g_VertStride;
    UINT offset = 0;
    pd3dDevice->IASetInputLayout( g_pVertexLayout );
    pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
    pd3dDevice->IASetIndexBuffer( g_pIB, DXGI_FORMAT_R32_UINT, 0 );
    pd3dDevice->IASetVertexBuffers( 0, 1, &g_pVB, &stride, &offset );

    // Render using the technique g_pRenderTextured
    D3D10_TECHNIQUE_DESC techDesc;
    g_pRenderTextured->GetDesc( &techDesc );
    for( UINT p = 0; p < techDesc.Passes; p++ )
    {
        g_pRenderTextured->GetPassByIndex( p )->Apply( 0 );
        pd3dDevice->DrawIndexed( g_NumIndices, 0, 0 );
    }
}
开发者ID:KNeal,项目名称:Oculus,代码行数:54,代码来源:Exercise04.cpp

示例5: DrawTriangle

// Draw a simple triangle using custom shaders (g_pEffect)
void DrawTriangle(ID3D11DeviceContext* pd3dImmediateContext)
{
	XMMATRIX world = g_camera.GetWorldMatrix();
	XMMATRIX view  = g_camera.GetViewMatrix();
	XMMATRIX proj  = g_camera.GetProjMatrix();
	XMFLOAT4X4 mViewProj;
	XMStoreFloat4x4(&mViewProj, world * view * proj);
	g_pEffect->GetVariableByName("g_worldViewProj")->AsMatrix()->SetMatrix((float*)mViewProj.m);
	g_pEffect->GetTechniqueByIndex(0)->GetPassByIndex(0)->Apply(0, pd3dImmediateContext);
    
	pd3dImmediateContext->IASetVertexBuffers(0, 0, nullptr, nullptr, nullptr);
	pd3dImmediateContext->IASetIndexBuffer(nullptr, DXGI_FORMAT_R16_UINT, 0);
	pd3dImmediateContext->IASetInputLayout(nullptr);
	pd3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	pd3dImmediateContext->Draw(3, 0);
}
开发者ID:thatPowderGuy,项目名称:GP_Exercises,代码行数:17,代码来源:main.cpp

示例6: V

//--------------------------------------------------------------------------------------
// Render the scene using the D3D9 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D9FrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
    HRESULT hr;
    D3DXMATRIXA16 mWorld;
    D3DXMATRIXA16 mView;
    D3DXMATRIXA16 mProj;
    D3DXMATRIXA16 mWorldViewProjection;

    // If the settings dialog is being shown, then render it instead of rendering the app's scene
    if( g_SettingsDlg.IsActive() )
    {
        g_SettingsDlg.OnRender( fElapsedTime );
        return;
    }

    // Clear the render target and the zbuffer 
    V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 45, 50, 170 ), 1.0f, 0 ) );

    // Render the scene
    if( SUCCEEDED( pd3dDevice->BeginScene() ) )
    {
        // Get the projection & view matrix from the camera class
        mWorld = *g_Camera.GetWorldMatrix();
        mProj = *g_Camera.GetProjMatrix();
        mView = *g_Camera.GetViewMatrix();

        mWorldViewProjection = mWorld * mView * mProj;

        // Update the effect's variables.  Instead of using strings, it would 
        // be more efficient to cache a handle to the parameter by calling 
        // ID3DXEffect::GetParameterByName
        V( g_pEffect9->SetMatrix( g_hmWorldViewProjection, &mWorldViewProjection ) );
        V( g_pEffect9->SetMatrix( g_hmWorld, &mWorld ) );
        V( g_pEffect9->SetFloat( g_hfTime, ( float )fTime ) );

        DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" ); // These events are to help PIX identify what the code is doing
        RenderText();
        V( g_HUD.OnRender( fElapsedTime ) );
        V( g_SampleUI.OnRender( fElapsedTime ) );
        DXUT_EndPerfEvent();

        V( pd3dDevice->EndScene() );
    }
}
开发者ID:capturePointer,项目名称:DllLoader,代码行数:47,代码来源:SimpleSample.cpp

示例7: RenderObjects

//--------------------------------------------------------------------------------------
// Render the scene using the D3D11 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime,
                                 float fElapsedTime, void* pUserContext )
{
    // If the settings dialog is being shown, then render it instead of rendering the app's scene
    if( g_SettingsDlg.IsActive() )
    {
        g_SettingsDlg.OnRender( fElapsedTime );
        return;
    }       

    auto pRTV = DXUTGetD3D11RenderTargetView();
    pd3dImmediateContext->ClearRenderTargetView( pRTV, Colors::MidnightBlue );

    // Clear the depth stencil
    auto pDSV = DXUTGetD3D11DepthStencilView();
    pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 );

    // Get the projection & view matrix from the camera class
    XMMATRIX mWorld = g_Camera.GetWorldMatrix();
    XMMATRIX mView = g_Camera.GetViewMatrix();
    XMMATRIX mProj = g_Camera.GetProjMatrix();

    g_BatchEffect->SetWorld( mWorld );
    g_BatchEffect->SetView( mView );
    g_BatchEffect->SetProjection( mProj );

    // Draw objects
    RenderObjects();

    // Render HUD
    DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" );
    g_HUD.OnRender( fElapsedTime );
    g_SampleUI.OnRender( fElapsedTime );
    RenderText();
    DXUT_EndPerfEvent();

    static ULONGLONG timefirst = GetTickCount64();
    if ( GetTickCount64() - timefirst > 5000 )
    {    
        OutputDebugString( DXUTGetFrameStats( DXUTIsVsyncEnabled() ) );
        OutputDebugString( L"\n" );
        timefirst = GetTickCount64();
    }
}
开发者ID:AndreAhmed,项目名称:directx-sdk-samples,代码行数:47,代码来源:Collision.cpp

示例8: sizeof

void CALLBACK OnD3D11FrameRender(ID3D11Device* pd3dDevice,
				ID3D11DeviceContext* pd3dImmediateContext,
				double fTime, float fElapsedTime, void* pUserContext)
{
	pd3dImmediateContext->ClearRenderTargetView(DXUTGetD3D11RenderTargetView(), Colors::DeepSkyBlue);
	pd3dImmediateContext->ClearDepthStencilView(DXUTGetD3D11DepthStencilView(), D3D11_CLEAR_DEPTH, 1.0f, 0);

	
	CONSTANTBUFFER cb;
	ZeroMemory(&cb, sizeof(CONSTANTBUFFER));
	XMMATRIX mat = XMLoadFloat4x4(&(g_mesh->getWorld()));	
	XMStoreFloat4x4(&cb.world, XMMatrixTranspose(mat));

	//cb.world =  g_mesh->getWorld();
	XMStoreFloat4x4(&cb.view, XMMatrixTranspose(g_camera.GetViewMatrix()));
	XMStoreFloat4x4(&cb.projection, XMMatrixTranspose(g_camera.GetProjMatrix()));

	/*
		1 0 0 0	Side (Right)
		0 1 0 0	Up
		0 0 1 0 Foward
		x y z 1 Position
	*/


	//1. XMMATRIX -> FLOAT4X4 
	XMVECTOR v = XMVectorSet(1.0f, 1.0f, 1.0f, 1.0f);
	XMVECTOR litpos = XMVector4Transform(v, g_matLight);
	litpos = XMVector4Normalize(litpos);
	XMStoreFloat4(&cb.litDir, litpos);
	cb.litCol = XMFLOAT4(0.7f, 0.7f, 0.6f, 1.0f);

	g_shader->RenderPrepare(&cb);
	g_mesh->Render();


	//
	mat = XMLoadFloat4x4(&(g_meshLight->getWorld()));
	XMStoreFloat4x4(&cb.world, XMMatrixTranspose(mat));
	g_shader->RenderPrepare(&cb);
	g_meshLight->Render();
	
}
开发者ID:contacoonta,项目名称:sgap-direct3d,代码行数:43,代码来源:DXUTMain.cpp

示例9: V

//--------------------------------------------------------------------------------------
// Render the scene using the D3D9 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D9FrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
    HRESULT hr = S_OK;

    // If the settings dialog is being shown, then render it instead of rendering the app's scene
    if( g_SettingsDlg.IsActive() )
    {
        g_SettingsDlg.OnRender( fElapsedTime );
        return;
    }

    D3DXMATRIX mWorld = *g_Camera.GetWorldMatrix();
    D3DXMATRIX mView = *g_Camera.GetViewMatrix();
    D3DXMATRIX mProj = *g_Camera.GetProjMatrix();
    D3DXMATRIX mWorldViewProjection = mWorld * mView * mProj;

    // Clear the render target and the zbuffer 
    V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 160, 160, 250 ), 1.0f, 0 ) );

    // Render the scene
    if( SUCCEEDED( pd3dDevice->BeginScene() ) )
    {
        g_pEffect9->SetMatrix( g_hmWorld, &mWorld );
        g_pEffect9->SetMatrix( g_hmWorldViewProjection, &mWorldViewProjection );
        g_pEffect9->SetTexture( g_htxDiffuse, g_pTexture9 );

        pd3dDevice->SetVertexDeclaration( g_pDecl9 );

        g_Mesh.Render( pd3dDevice, g_pEffect9, g_hRenderScene );

        DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" ); // These events are to help PIX identify what the code is doing
        RenderText();
        V( g_HUD.OnRender( fElapsedTime ) );
        V( g_SampleUI.OnRender( fElapsedTime ) );
        DXUT_EndPerfEvent();

        V( pd3dDevice->EndScene() );
    }
}
开发者ID:KNeal,项目名称:Oculus,代码行数:42,代码来源:DDSWithoutD3DX9.cpp

示例10: RenderText

//--------------------------------------------------------------------------------------
// Render the scene using the D3D11 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D11FrameRender(ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double /*fTime*/,
    float fElapsedTime, void* /*pUserContext*/)
{
    // If the settings dialog is being shown, then render it instead of rendering the app's scene
    if (g_D3DSettingsDlg.IsActive())
    {
        g_D3DSettingsDlg.OnRender(fElapsedTime);
        return;
    }

    // Get the projection & view matrix from the camera class
    XMMATRIX mWorld;
    XMMATRIX mView;
    XMMATRIX mProj;
    XMMATRIX mWorldViewProjection;
    mWorld = g_Camera.GetWorldMatrix();
    mView = g_Camera.GetViewMatrix();
    mProj = g_Camera.GetProjMatrix();
    mWorldViewProjection = mWorld * mView * mProj;

    // Store off original render target and depth/stencil
    ID3D11RenderTargetView* pOrigRTV = NULL;
    ID3D11DepthStencilView* pOrigDSV = NULL;
    pd3dImmediateContext->OMGetRenderTargets(1, &pOrigRTV, &pOrigDSV);

    g_OIT.Render(pd3dImmediateContext, pd3dDevice, &g_Scene, mWorldViewProjection, pOrigRTV, pOrigDSV);

    pd3dImmediateContext->OMSetRenderTargets(1, &pOrigRTV, pOrigDSV);

    // Restore original render targets, and then draw UI
    SAFE_RELEASE(pOrigRTV);
    SAFE_RELEASE(pOrigDSV);

    DXUT_BeginPerfEvent(DXUT_PERFEVENTCOLOR, L"HUD / Stats");
    g_HUD.OnRender(fElapsedTime);
    g_SampleUI.OnRender(fElapsedTime);
    RenderText();
    DXUT_EndPerfEvent();
}
开发者ID:marselas,项目名称:Zombie-Direct3D-Samples,代码行数:42,代码来源:main.cpp

示例11: OnFrameMove

//--------------------------------------------------------------------------------------
// Handle updates to the scene.  This is called regardless of which D3D API is used
//--------------------------------------------------------------------------------------
void CALLBACK OnFrameMove( double fTime, float fElapsedTime, void* pUserContext )
{
    D3DXMATRIXA16 mWorld;
    D3DXMATRIXA16 mView;
    D3DXMATRIXA16 mProj;
    D3DXMATRIXA16 mWorldViewProjection;

    // Update the camera's position based on user input 
    g_Camera.FrameMove( fElapsedTime );

    // Get the projection & view matrix from the camera class
    mWorld = g_mCenterWorld * *g_Camera.GetWorldMatrix();
    mProj = *g_Camera.GetProjMatrix();
    mView = *g_Camera.GetViewMatrix();

    mWorldViewProjection = mWorld * mView * mProj;

    // Update the effect's variables 
    g_pEffect->SetMatrix( g_hWorldViewProjection, &mWorldViewProjection );
    g_pEffect->SetMatrix( g_hWorld, &mWorld );
    g_pEffect->SetFloat( g_hTime, ( float )fTime );
}
开发者ID:KNeal,项目名称:Oculus,代码行数:25,代码来源:CompiledEffect.cpp

示例12: DrawAllRigidBoxes

//--------------------------------------------------------------------------------------
// Draw all boxes in the scene
//--------------------------------------------------------------------------------------
void DrawAllRigidBoxes(ID3D11DeviceContext* pd3dImmediateContext)
{
	XMMATRIX scaling = XMMatrixScaling(SCM.sceneScale, SCM.sceneScale, SCM.sceneScale);
	XMMATRIX objToWorld;
	XMMATRIX screenToObj;
	
	for (int i = SCM.sceneObjects.size() -1; i >= 0; i--)
	{
		Box* box = &SCM.sceneObjects[i];

		objToWorld = box->getObjToWorldMatrix(SCM.getStepCount());
		screenToObj = XMMatrixInverse(nullptr, objToWorld * g_camera.GetViewMatrix());
		objToWorld *= scaling * g_camera.GetWorldMatrix();
		
		// Setup position/normal/color effect
		g_pEffectPositionNormalColor->SetWorld(objToWorld);
		g_pEffectPositionNormalColor->SetEmissiveColor(Colors::Black);
		g_pEffectPositionNormalColor->SetDiffuseColor(0.8f * Colors::White);
		g_pEffectPositionNormalColor->SetSpecularColor(0.4f * Colors::White);
		g_pEffectPositionNormalColor->SetSpecularPower(1000);

		g_pEffectPositionNormalColor->Apply(pd3dImmediateContext);
		pd3dImmediateContext->IASetInputLayout(g_pInputLayoutPositionNormalColor);
	
		g_pPrimitiveBatchPositionNormalColor->Begin();
		{	
			DrawRigidBoxSolid(pd3dImmediateContext, box, objToWorld, screenToObj);
			if (SCM.enableInteraction && i == SCM.selectedBoxIndex)
			{
				DrawRigidBoxWireFrame(pd3dImmediateContext, box, objToWorld, screenToObj);
			}
			if (SCM.showMasses)
			{
			}
		}
		g_pPrimitiveBatchPositionNormalColor->End();
	}
}
开发者ID:thatPowderGuy,项目名称:GP_Exercises,代码行数:41,代码来源:main.cpp

示例13: OnFrameRender

//--------------------------------------------------------------------------------------
//실제 render가 발생하는 함수
//fTime, fElapsedTime은 윈도우 콜백이 알아서 만들어서 인자 전달
//--------------------------------------------------------------------------------------
void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{

	//렌더 필요 변수
    HRESULT hr;
    D3DXMATRIXA16 mWorldViewProjection;
    D3DXVECTOR3 vLightDir[MAX_LIGHTS];
    D3DXCOLOR vLightDiffuse[MAX_LIGHTS];
    UINT iPass, cPasses;
    D3DXMATRIXA16 mWorld;
    D3DXMATRIXA16 mView;
    D3DXMATRIXA16 mProj;

    //디바이스 초기화
    V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DXCOLOR( 0.0f, 0.25f, 0.25f, 0.55f ), 1.0f,
                          0 ) );

    //씬 그리기 시작
    if( SUCCEEDED( pd3dDevice->BeginScene() ) )
    {
        //카메라의 현재 매트릭스 값을 받아서 월드 매트릭스에 곱한 결과 값
        mWorld = g_mCenterWorld * (*g_Camera.GetWorldMatrix());
		//프로젝션 매트릭스 설정
        mProj = *g_Camera.GetProjMatrix();
		//뷰 매트릭스 설정
        mView = *g_Camera.GetViewMatrix();

		//월드 매트릭스에 *뷰 * 프로젝션 매트릭스 적용
        mWorldViewProjection = mWorld * mView * mProj;

        //라이트 적용
        for( int i = 0; i < g_nNumActiveLights; i++ )
        {
            vLightDir[i] = g_LightControl[i].GetLightDirection();
            vLightDiffuse[i] = g_fLightScale * D3DXCOLOR( 1, 1, 1, 1 );
        }


		//shader에 조명 관련 정보 binding
        V( g_pEffect->SetValue( "g_LightDir", vLightDir, sizeof( D3DXVECTOR3 ) * MAX_LIGHTS ) );
        V( g_pEffect->SetValue( "g_LightDiffuse", vLightDiffuse, sizeof( D3DXVECTOR4 ) * MAX_LIGHTS ) );


		//shader에 매트릭스 관련 정보 binding
        V( g_pEffect->SetMatrix( "g_mWorldViewProjection", &mWorldViewProjection ) );
        V( g_pEffect->SetMatrix( "g_mWorld", &mWorld ) );

		//shader에 재질 속성 값 관련 정보 binding
        D3DXCOLOR vWhite = D3DXCOLOR( 1, 1, 1, 1 );
        V( g_pEffect->SetValue( "g_MaterialDiffuseColor", &vWhite, sizeof( D3DXCOLOR ) ) );
        
		//shader에 time 값 전달
		V( g_pEffect->SetFloat( "g_fTime", ( float )fTime ) );

		//shader에 활성 조명 값
        V( g_pEffect->SetInt( "g_nNumLights", g_nNumActiveLights ) );

			
        switch( g_nNumActiveLights )
        {
            case 1:
                V( g_pEffect->SetTechnique( "RenderSceneWithTexture1Light" ) ); break;
            case 2:
                V( g_pEffect->SetTechnique( "RenderSceneWithTexture2Light" ) ); break;
            case 3:
                V( g_pEffect->SetTechnique( "RenderSceneWithTexture3Light" ) ); break;
        }


        //shader 시작
        V( g_pEffect->Begin( &cPasses, 0 ) );
		
		//pass는 그리는 개수를 의미
		//그리는 개수 만큼 pass 순환
        for( iPass = 0; iPass < cPasses; iPass++ )
        {
            V( g_pEffect->BeginPass( iPass ) );

            // Render the mesh with the applied technique
            V( g_pMesh->DrawSubset( 0 ) );

            V( g_pEffect->EndPass() );
        }
        V( g_pEffect->End() );

		//씬 그리기 종료
        V( pd3dDevice->EndScene() );
    }
}
开发者ID:trizdreaming,项目名称:windowsGameProg_DirectXTutorial,代码行数:93,代码来源:BasicHLSL.cpp

示例14: if

//--------------------------------------------------------------------------------------
// Render the scene using the D3D11 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime,
                                  float fElapsedTime, void* pUserContext )
{
    // If the settings dialog is being shown, then render it instead of rendering the app's scene
    if( g_D3DSettingsDlg.IsActive() )
    {
        g_D3DSettingsDlg.OnRender( fElapsedTime );
        return;
    }

    // WVP
    XMMATRIX mProj = g_Camera.GetProjMatrix();
    XMMATRIX mView = g_Camera.GetViewMatrix();

    XMMATRIX mViewProjection = mView * mProj;

    // Update per-frame variables
    D3D11_MAPPED_SUBRESOURCE MappedResource;
    pd3dImmediateContext->Map( g_pcbPerFrame, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource );
    auto pData = reinterpret_cast<CB_PER_FRAME_CONSTANTS*>( MappedResource.pData );
    XMStoreFloat4x4( &pData->mViewProjection, XMMatrixTranspose( mViewProjection ) );
    XMStoreFloat3( &pData->vCameraPosWorld, g_Camera.GetEyePt() );
    pData->fTessellationFactor = (float)g_fSubdivs;

    pd3dImmediateContext->Unmap( g_pcbPerFrame, 0 );

    // Clear the render target and depth stencil
    auto pRTV = DXUTGetD3D11RenderTargetView();
    pd3dImmediateContext->ClearRenderTargetView( pRTV, Colors::Black );
    auto pDSV = DXUTGetD3D11DepthStencilView();
    pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 );

    // Set state for solid rendering
    pd3dImmediateContext->RSSetState( g_pRasterizerStateSolid );

    // Render the meshes
    // Bind all of the CBs
    pd3dImmediateContext->VSSetConstantBuffers( g_iBindPerFrame, 1, &g_pcbPerFrame );
    pd3dImmediateContext->HSSetConstantBuffers( g_iBindPerFrame, 1, &g_pcbPerFrame );
    pd3dImmediateContext->DSSetConstantBuffers( g_iBindPerFrame, 1, &g_pcbPerFrame );
    pd3dImmediateContext->PSSetConstantBuffers( g_iBindPerFrame, 1, &g_pcbPerFrame );

    // Set the shaders
    pd3dImmediateContext->VSSetShader( g_pVertexShader, nullptr, 0 );

    // For this sample, choose either the "integer", "fractional_even",
    // or "fractional_odd" hull shader
    if (g_iPartitionMode == PARTITION_INTEGER)
        pd3dImmediateContext->HSSetShader( g_pHullShaderInteger, nullptr, 0 );
    else if (g_iPartitionMode == PARTITION_FRACTIONAL_EVEN)
        pd3dImmediateContext->HSSetShader( g_pHullShaderFracEven, nullptr, 0 );
    else if (g_iPartitionMode == PARTITION_FRACTIONAL_ODD)
        pd3dImmediateContext->HSSetShader( g_pHullShaderFracOdd, nullptr, 0 );

    pd3dImmediateContext->DSSetShader( g_pDomainShader, nullptr, 0 );
    pd3dImmediateContext->GSSetShader( nullptr, nullptr, 0 );
    pd3dImmediateContext->PSSetShader( g_pPixelShader, nullptr, 0 );

    // Optionally draw the wireframe
    if( g_bDrawWires )
    {
        pd3dImmediateContext->PSSetShader( g_pSolidColorPS, nullptr, 0 );
        pd3dImmediateContext->RSSetState( g_pRasterizerStateWireframe ); 
    }

    // Set the input assembler
    // This sample uses patches with 16 control points each
    // Although the Mobius strip only needs to use a vertex buffer,
    // you can use an index buffer as well by calling IASetIndexBuffer().
    pd3dImmediateContext->IASetInputLayout( g_pPatchLayout );
    UINT Stride = sizeof( BEZIER_CONTROL_POINT );
    UINT Offset = 0;
    pd3dImmediateContext->IASetVertexBuffers( 0, 1, &g_pControlPointVB, &Stride, &Offset );
    pd3dImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_16_CONTROL_POINT_PATCHLIST );

    // Draw the mesh
    pd3dImmediateContext->Draw( ARRAYSIZE(g_MobiusStrip), 0 );

    pd3dImmediateContext->RSSetState( g_pRasterizerStateSolid );

    // Render the HUD
    DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" );
    g_HUD.OnRender( fElapsedTime );
    g_SampleUI.OnRender( fElapsedTime );
    RenderText();
    DXUT_EndPerfEvent();
}
开发者ID:AndreAhmed,项目名称:directx-sdk-samples,代码行数:90,代码来源:SimpleBezier11.cpp

示例15: lightDir

//--------------------------------------------------------------------------------------
// Render the scene using the D3D10 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D10FrameRender( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
    // Clear the render target
    float ClearColor[4] = { 0.9569f, 0.9569f, 1.0f, 0.0f };
    ID3D10RenderTargetView* pRTV = DXUTGetD3D10RenderTargetView();
    pd3dDevice->ClearRenderTargetView( pRTV, ClearColor );
    ID3D10DepthStencilView* pDSV = DXUTGetD3D10DepthStencilView();
    pd3dDevice->ClearDepthStencilView( pDSV, D3D10_CLEAR_DEPTH, 1.0, 0 );

    D3DXMATRIX mWorld;
    D3DXMATRIX mView;
    D3DXMATRIX mProj;
    D3DXMATRIX mWorldView;
    D3DXMATRIX mWorldViewProj;
    mWorld = *g_Camera.GetWorldMatrix();
    mProj = *g_Camera.GetProjMatrix();
    mView = *g_Camera.GetViewMatrix();
    mWorldView = mWorld * mView;
    mWorldViewProj = mWorldView * mProj;

    // Set variables
    g_pmWorldViewProj->SetMatrix( ( float* )&mWorldViewProj );
    g_pmWorldView->SetMatrix( ( float* )&mWorldView );
    g_pmWorld->SetMatrix( ( float* )&mWorld );
    g_pmProj->SetMatrix( ( float* )&mProj );
    g_pDiffuseTex->SetResource( g_pMeshTexRV );
    D3DXVECTOR3 lightDir( -1,1,-1 );
    D3DXVECTOR3 viewLightDir;
    D3DXVec3TransformNormal( &viewLightDir, &lightDir, &mView );
    D3DXVec3Normalize( &viewLightDir, &viewLightDir );
    g_pViewSpaceLightDir->SetFloatVector( ( float* )&viewLightDir );

    // Get VB and IB
    UINT offset = 0;
    UINT stride = g_Mesh.GetVertexStride( 0, 0 );
    ID3D10Buffer* pVB = g_Mesh.GetVB10( 0, 0 );
    ID3D10Buffer* pIB = g_Mesh.GetAdjIB10( 0 );

    // Set Input Assembler params
    pd3dDevice->IASetInputLayout( g_pVertexLayout );

    pd3dDevice->IASetIndexBuffer( pIB, g_Mesh.GetIBFormat10( 0 ), 0 );
    pd3dDevice->IASetVertexBuffers( 0, 1, &pVB, &stride, &offset );
    pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ );

    // Render using the technique g_pRenderTextured
    SDKMESH_SUBSET* pSubset = NULL;

    D3D10_TECHNIQUE_DESC techDesc;
    g_pRenderTextured->GetDesc( &techDesc );
    for( UINT p = 0; p < techDesc.Passes; p++ )
    {
        g_pRenderTextured->GetPassByIndex( p )->Apply( 0 );
        for( UINT subset = 0; subset < g_Mesh.GetNumSubsets( 0 ); subset++ )
        {
            pSubset = g_Mesh.GetSubset( 0, subset );

            pd3dDevice->DrawIndexed( ( UINT )pSubset->IndexCount * 2, ( UINT )pSubset->IndexStart,
                                     ( UINT )pSubset->VertexStart );
        }
    }

    // Render the chess piece just for show
    // Render using the technique g_pRenderPiece
    g_pRenderPiece->GetDesc( &techDesc );
    for( UINT p = 0; p < techDesc.Passes; p++ )
    {
        g_pRenderPiece->GetPassByIndex( p )->Apply( 0 );
        for( UINT subset = 0; subset < g_Mesh.GetNumSubsets( 0 ); subset++ )
        {
            pSubset = g_Mesh.GetSubset( 0, subset );

            pd3dDevice->DrawIndexed( ( UINT )pSubset->IndexCount * 2, ( UINT )pSubset->IndexStart,
                                     ( UINT )pSubset->VertexStart );
        }
    }
}
开发者ID:KNeal,项目名称:Oculus,代码行数:80,代码来源:Exercise03.cpp


注:本文中的CModelViewerCamera::GetViewMatrix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。