本文整理汇总了C++中CModelViewerCamera::GetWorldMatrix方法的典型用法代码示例。如果您正苦于以下问题:C++ CModelViewerCamera::GetWorldMatrix方法的具体用法?C++ CModelViewerCamera::GetWorldMatrix怎么用?C++ CModelViewerCamera::GetWorldMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CModelViewerCamera
的用法示例。
在下文中一共展示了CModelViewerCamera::GetWorldMatrix方法的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;
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() );
}
}
示例2: OnFrameRender
//--------------------------------------------------------------------------------------
// Render the scene using the D3D9 device
//--------------------------------------------------------------------------------------
void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
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, 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_mView;
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_pEffect->SetMatrix( "g_mWorldViewProjection", &mWorldViewProjection ) );
V( g_pEffect->SetMatrix( "g_mWorld", &mWorld ) );
V( g_pEffect->SetFloat( "g_fTime", ( float )fTime ) );
g_pEffect->SetTechnique( "RenderScene" );
UINT cPasses;
g_pEffect->Begin( &cPasses, 0 );
ID3DXMesh* pMesh = g_Mesh.GetMesh();
for( UINT p = 0; p < cPasses; ++p )
{
g_pEffect->BeginPass( p );
for( UINT m = 0; m < g_Mesh.m_dwNumMaterials; ++m )
{
g_pEffect->SetTexture( "g_txScene", g_Mesh.m_pTextures[m] );
g_pEffect->CommitChanges();
pMesh->DrawSubset( m );
}
g_pEffect->EndPass();
}
g_pEffect->End();
RenderText();
V( g_HUD.OnRender( fElapsedTime ) );
V( g_SampleUI.OnRender( fElapsedTime ) );
V( pd3dDevice->EndScene() );
}
}
示例3: 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 );
}
}
示例4: OnFrameMove
//--------------------------------------------------------------------------------------
// This callback function will be called once at the beginning of every frame. This is the
// best location for your application to handle updates to the scene, but is not
// intended to contain actual rendering calls, which should instead be placed in the
// OnFrameRender callback.
//--------------------------------------------------------------------------------------
void CALLBACK OnFrameMove( double fTime, float fElapsedTime, void* pUserContext )
{
// Update the camera's position based on user input
g_Camera.FrameMove( fElapsedTime );
UpdateLightingEnvironment();
if( g_pAnimController != NULL )
{
g_pAnimController->SetTrackSpeed( 0, g_SampleUI.GetSlider( IDC_ANIMATION_SPEED )->GetValue() / 1000.0f );
g_pAnimController->AdvanceTime( fElapsedTime, NULL );
}
UpdateFrameMatrices( g_pFrameRoot, g_Camera.GetWorldMatrix() );
}
示例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);
}
示例6: DrawBoundingBox
//--------------------------------------------------------------------------------------
// Draw the edges of the bounding box [-0.5;0.5]³ rotated with the cameras model tranformation.
// (Drawn as line primitives using a DirectXTK primitive batch)
//--------------------------------------------------------------------------------------
void DrawBoundingBox(ID3D11DeviceContext* pd3dImmediateContext)
{
// Setup position/color effect
XMMATRIX worldMatrix = g_camera.GetWorldMatrix();
XMVECTOR red = Colors::Red, green = Colors::Green, blue = Colors::Blue;
#if (defined RIGIDBODYCOLLISIONS)
if (!SCM.showAdditionalProperties || !SCM.showUnitBox) { return; }
worldMatrix = XMMatrixScaling(SCM.sceneScale, SCM.sceneScale, SCM.sceneScale) * worldMatrix;
#endif
g_pEffectPositionColor->SetWorld(worldMatrix);
g_pEffectPositionColor->Apply(pd3dImmediateContext);
pd3dImmediateContext->IASetInputLayout(g_pInputLayoutPositionColor);
// Draw
g_pPrimitiveBatchPositionColor->Begin();
// Lines in x direction (red color)
for (int i=0; i<4; i++)
{
g_pPrimitiveBatchPositionColor->DrawLine(
VertexPositionColor(XMVectorSet(-0.5f, (float)(i%2)-0.5f, (float)(i/2)-0.5f, 1), red),
VertexPositionColor(XMVectorSet( 0.5f, (float)(i%2)-0.5f, (float)(i/2)-0.5f, 1), red)
);
}
// Lines in y direction
for (int i=0; i<4; i++)
{
g_pPrimitiveBatchPositionColor->DrawLine(
VertexPositionColor(XMVectorSet((float)(i%2)-0.5f, -0.5f, (float)(i/2)-0.5f, 1), green),
VertexPositionColor(XMVectorSet((float)(i%2)-0.5f, 0.5f, (float)(i/2)-0.5f, 1), green)
);
}
// Lines in z direction
for (int i=0; i<4; i++)
{
g_pPrimitiveBatchPositionColor->DrawLine(
VertexPositionColor(XMVectorSet((float)(i%2)-0.5f, (float)(i/2)-0.5f, -0.5f, 1), blue),
VertexPositionColor(XMVectorSet((float)(i%2)-0.5f, (float)(i/2)-0.5f, 0.5f, 1), blue)
);
}
g_pPrimitiveBatchPositionColor->End();
}
示例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();
}
}
示例8: 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() );
}
}
示例9: 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();
}
示例10: 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 );
}
示例11: 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() );
}
}
示例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();
}
}
示例13: DrawSomeRandomObjects
// Draw several objects randomly positioned in [-0.5f;0.5]³ using DirectXTK geometric primitives.
void DrawSomeRandomObjects(ID3D11DeviceContext* pd3dImmediateContext)
{
// Setup position/normal effect (constant variables)
g_pEffectPositionNormal->SetEmissiveColor(Colors::Black);
g_pEffectPositionNormal->SetSpecularColor(0.4f * Colors::White);
g_pEffectPositionNormal->SetSpecularPower(100);
std::mt19937 eng;
std::uniform_real_distribution<float> randCol( 0.0f, 1.0f);
std::uniform_real_distribution<float> randPos(-0.5f, 0.5f);
for (int i=0; i<g_iNumSpheres; i++)
{
// Setup position/normal effect (per object variables)
g_pEffectPositionNormal->SetDiffuseColor(0.6f * XMColorHSVToRGB(XMVectorSet(randCol(eng), 1, 1, 0)));
XMMATRIX scale = XMMatrixScaling(g_fSphereSize, g_fSphereSize, g_fSphereSize);
XMMATRIX trans = XMMatrixTranslation(randPos(eng),randPos(eng),randPos(eng));
g_pEffectPositionNormal->SetWorld(scale * trans * g_camera.GetWorldMatrix());
// Draw
// NOTE: The following generates one draw call per object, so performance will be bad for n>>1000 or so
g_pSphere->Draw(g_pEffectPositionNormal, g_pInputLayoutPositionNormal);
}
}
示例14: 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 );
}
}
}
示例15: V
//--------------------------------------------------------------------------------------
// Render the scene using the D3D10 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D10FrameRender( ID3D10Device* 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;
}
//
// Clear the back buffer
//
float ClearColor[4] = { 0.3f, 0.3f, 0.3f, 1.0f } ; // red, green, blue, alpha
ID3D10RenderTargetView* pRTV = DXUTGetD3D10RenderTargetView();
pd3dDevice->ClearRenderTargetView( pRTV, ClearColor );
//
// Clear the depth stencil
//
ID3D10DepthStencilView* pDSV = DXUTGetD3D10DepthStencilView();
pd3dDevice->ClearDepthStencilView( pDSV, D3D10_CLEAR_DEPTH, 1.0, 0 );
HRESULT hr;
D3DXMATRIXA16 mWorld;
D3DXMATRIXA16 mView;
D3DXMATRIXA16 mProj;
D3DXMATRIXA16 mWorldViewProjection;
// 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_pWorldViewProjection->SetMatrix( (float*)&mWorldViewProjection ) );
V( g_pWorld->SetMatrix( (float*)&mWorld ) );
V( g_pTime->SetFloat( (float)fTime ) );
V( g_pCameraPosition->SetFloatVector( (float*)g_Camera.GetEyePt() ) );
//
// Set the Vertex Layout
//
pd3dDevice->IASetInputLayout( g_pVertexLayout );
UINT iCurSubset = ( UINT )( INT_PTR )g_SampleUI.GetComboBox( IDC_SUBSET )->GetSelectedData();
//
// Render the mesh
//
if ( iCurSubset == -1 )
{
for ( UINT iSubset = 0; iSubset < g_MeshLoader.GetNumSubsets(); ++iSubset )
{
RenderSubset( iSubset );
}
} else
{
RenderSubset( iCurSubset );
}
DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" );
RenderText();
g_HUD.OnRender( fElapsedTime );
g_SampleUI.OnRender( fElapsedTime );
DXUT_EndPerfEvent();
}