void MatrixSet() { D3DXMATRIX matWorld; D3DXMatrixIdentity(&matWorld); gPD3DDevice->SetTransform(D3DTS_WORLD, &matWorld); D3DXMATRIX matView; D3DXVECTOR3 vEye(0.0f, 0.0f, -50.0f); D3DXVECTOR3 vAt(0.0f, 0.0f, 0.0f); D3DXVECTOR3 vUp(0.f, 1.f, 0.f); D3DXMatrixLookAtLH(&matView, &vEye, &vAt, &vUp); gPD3DDevice->SetTransform(D3DTS_VIEW, &matView); D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI / 6.0f, 1.0f, 1.0f, 1000.0f); gPD3DDevice->SetTransform(D3DTS_PROJECTION, &matProj); D3DVIEWPORT9 viewPort; viewPort.Width = WINDOW_WIDTH; viewPort.Height = WINDOW_HEIGHT; viewPort.X = 0; viewPort.Y = 0; viewPort.MinZ = 0.0f; viewPort.MaxZ = 1.0f; gPD3DDevice->SetViewport(&viewPort); }
//--------------------------------------- //NAME : SetTransform() //DESC : 坐标转换 //--------------------------------------- void SetTransform() { //设置世界变换矩阵 D3DXMATRIX matWorld,Rx,Ry,Rz; D3DXMatrixIdentity(&matWorld);//单位矩阵 D3DXMatrixRotationX(&Rx,::timeGetTime()/1000.f);//绕x轴旋转 D3DXMatrixRotationY(&Ry,::timeGetTime()/1000.f);//绕y轴旋转 D3DXMatrixRotationZ(&Rz,::timeGetTime()/1000.f);//绕z轴旋转 matWorld=Rx*Ry*Rz*matWorld; g_pd3dDevice->SetTransform(D3DTS_WORLD,&matWorld); //设置取景变换矩阵 D3DXMATRIX matView; D3DXVECTOR3 vEye(0.0f,0.0f,-30.0f); D3DXVECTOR3 vAt(0.0f,0.0f,0.0f); D3DXVECTOR3 vUp(0.0f,1.0f,0.0f); D3DXMatrixLookAtLH(&matView,&vEye,&vAt,&vUp); g_pd3dDevice->SetTransform(D3DTS_VIEW,&matView); //设置投影变换矩阵 D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH(&matProj,D3DX_PI/4.0f,1.0f,1.0f,1000.0f); g_pd3dDevice->SetTransform(D3DTS_PROJECTION,&matProj); }
void Camera::right(){ Vector3 vUp(up.x,up.y,up.z); Vector3 vEye(eye.x-look.x,eye.y-look.y,eye.z-look.z); Vector3 left(vUp.cross(vEye)); eye.x+=left.x*0.03; eye.y+=left.y*0.03; eye.z+=left.z*0.03; look.x+=left.x*0.03; look.y+=left.y*0.03; look.z+=left.z*0.03; }
/** * SetCamera() * カメラを設定する。 */ void Tank::SetCamera() { D3DXVECTOR3 vEye(0, 10.0f, -30.0f); D3DXVECTOR3 vAt(0, 10.0f, 10.0f); D3DXMATRIX m; D3DXMatrixRotationY(&m, rotBody); D3DXVec3TransformCoord(&vEye, &vEye, &m); D3DXVec3TransformCoord(&vAt, &vAt, &m); vEye += vPos; vAt += vPos; GameMain::GetInstance().SetCamera(vEye, vAt); }
void Game::Init() { m_pShaderProgram = new CShaderProgram; m_pSphere = new CSphere; m_pTimer = new CHighResolutionTimer; // This sets the position, viewpoint, and up vector of the synthetic camera glm::vec3 vEye(0, 0, 20); glm::vec3 vView(0, 0, 0); glm::vec3 vUp(0, 1, 0); glm::mat4 mViewMatrix = glm::lookAt(vEye, vView, vUp); // This creates a view frustum glm::mat4 mProjectionMatrix = glm::perspective(45.0f, 1.333f, 1.0f, 150.0f); // This sets the background colour glClearColor(0.5f, 0.5f, 0.5f, 1.0f); glClearDepth(1.0); // Load and compile shaders CShader shVertex, shFragment; shVertex.LoadShader("data\\shaders\\shader.vert", GL_VERTEX_SHADER); shFragment.LoadShader("data\\shaders\\shader.frag", GL_FRAGMENT_SHADER); // Create shader program and add shaders m_pShaderProgram->CreateProgram(); m_pShaderProgram->AddShaderToProgram(&shVertex); m_pShaderProgram->AddShaderToProgram(&shFragment); // Link and use the program m_pShaderProgram->LinkProgram(); m_pShaderProgram->UseProgram(); // Set the modeling, viewing, and projection matrices in the shader m_pShaderProgram->SetUniform("viewMatrix", mViewMatrix); m_pShaderProgram->SetUniform("projectionMatrix", mProjectionMatrix); m_pShaderProgram->SetUniform("vlightDirection", glm::normalize(glm::vec3(0.5f, 0.5f, 0.5f))); m_pShaderProgram->SetUniform("sampler0", 0); m_pSphere->Create("data\\textures\\", "dirtpile01.jpg", 25, 25); // Texture downloaded from http://www.psionicgames.com/?page_id=26 on 24 Jan 2013 m_pTimer->Start(); }
void App::LoadTessellatedTerrain() { //D3DXVECTOR3 vEye(786.1f, -86.5f, 62.2f); //D3DXVECTOR3 vAt(786.3f, -130.0f, 244.1f); D3DXVECTOR3 vEye(18595.1f, 200.4f, -16347.6f); D3DXVECTOR3 vAt(18596.1f, 200.315f, -16348.f); ActiveCam_->setFrom((float*)vEye); ActiveCam_->setTo((float*)vAt); ActiveCam_->setFOV(RAD2DEG(noMath::PI / 3)); ActiveCam_->setNear(CLIP_NEAR); ActiveCam_->setFar(CLIP_FAR); ActiveCam_->SetAspect(GetAspectRatio()); ActiveCam_->computeModelView(); ActiveCam_->ComputeProjection(); g_ResetTerrain = true; ReadStars(); CreateAmplifiedHeights(device); CreateShaders(device, context); CreateDeformEffect(device); // This array defines the outer width of each successive ring. int widths[] = { 0, 16, 16, 16, 16 }; g_nRings = sizeof(widths) / sizeof(widths[0]) - 1; // widths[0] doesn't define a ring hence -1 assert(g_nRings <= MAX_RINGS); float tileWidth = 0.125f; for (int i=0; i!=g_nRings && i!=MAX_RINGS; ++i) { g_pTileRings[i] = new TileRing(device, widths[i]/2, widths[i+1], tileWidth); tileWidth *= 2.0f; } CreateMeshes(device, context); OnSizeTerrain(); }
//----------------------------------------------------------------------------- // Name: RestoreDeviceObjects() // Desc: Initialize scene objects. //----------------------------------------------------------------------------- HRESULT CMyD3DApplication::RestoreDeviceObjects() { m_pFont->RestoreDeviceObjects(); // Set the matrices D3DXVECTOR3 vEye( 0.0f, 0.0f,-3.0f ); D3DXVECTOR3 vAt( 0.0f, 0.0f, 0.0f ); D3DXVECTOR3 vUp( 0.0f, 1.0f, 0.0f ); D3DXMATRIX matWorld, matView, matProj; D3DXMatrixIdentity( &matWorld ); D3DXMatrixLookAtLH( &matView, &vEye,&vAt, &vUp ); FLOAT fAspect = m_d3dsdBackBuffer.Width / (FLOAT)m_d3dsdBackBuffer.Height; D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, fAspect, 1.0f, 100.0f ); m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld ); m_pd3dDevice->SetTransform( D3DTS_VIEW, &matView ); m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ); // Set state m_pd3dDevice->SetRenderState( D3DRS_DITHERENABLE, FALSE ); m_pd3dDevice->SetRenderState( D3DRS_CLIPPING, FALSE ); m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); m_pd3dDevice->SetRenderState( D3DRS_CLIPPING, FALSE ); m_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE ); m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, FALSE ); m_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR ); return S_OK; }
//-----------------------------------【Matrix_Set( )函数】-------------------------------------- // 描述:封装了Direct3D四大变换的函数,即世界变换,取景变换,投影变换,视口变换的设置 //-------------------------------------------------------------------------------------------------- void Matrix_Set() { //-------------------------------------------------------------------------------------- //【四大变换之一】:世界变换矩阵的设置 //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- //【四大变换之二】:取景变换矩阵的设置 //-------------------------------------------------------------------------------------- D3DXMATRIX matView; //定义一个矩阵 D3DXVECTOR3 vEye(0.0f, 0.0f, -50.0f); //摄像机的位置 D3DXVECTOR3 vAt(0.0f, 0.0f, 0.0f); //观察点的位置 D3DXVECTOR3 vUp(0.0f, 1.0f, 0.0f);//向上的向量 D3DXMatrixLookAtLH(&matView, &vEye, &vAt, &vUp); //计算出取景变换矩阵 g_pd3dDevice->SetTransform(D3DTS_VIEW, &matView); //应用取景变换矩阵 //-------------------------------------------------------------------------------------- //【四大变换之三】:投影变换矩阵的设置 //-------------------------------------------------------------------------------------- D3DXMATRIX matProj; //定义一个矩阵 D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI / 4.0f, (float)((double)WINDOW_WIDTH / WINDOW_HEIGHT), 1.0f, 1000.0f); //计算投影变换矩阵 g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj); //设置投影变换矩阵 //-------------------------------------------------------------------------------------- //【四大变换之四】:视口变换的设置 //-------------------------------------------------------------------------------------- D3DVIEWPORT9 vp; //实例化一个D3DVIEWPORT9结构体,然后做填空题给各个参数赋值就可以了 vp.X = 0; //表示视口相对于窗口的X坐标 vp.Y = 0; //视口相对对窗口的Y坐标 vp.Width = WINDOW_WIDTH; //视口的宽度 vp.Height = WINDOW_HEIGHT; //视口的高度 vp.MinZ = 0.0f; //视口在深度缓存中的最小深度值 vp.MaxZ = 1.0f; //视口在深度缓存中的最大深度值 g_pd3dDevice->SetViewport(&vp); //视口的设置 }
void Matrix_Set() { D3DXMATRIX matView; D3DXVECTOR3 vEye(0.0f, 100.0f, -200.0f); D3DXVECTOR3 vAt(0.0f, 30.0f, 0.0f); D3DXVECTOR3 vUp(0.0f, 1.0f, 0.0f); D3DXMatrixLookAtLH(&matView, &vEye, &vAt, &vUp); g_pd3dDevice->SetTransform(D3DTS_VIEW, &matView); D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI / 4.0f, (float)WINDOW_WIDTH / (float)WINDOW_HEIGHT, 1.0f, 10000.0f); g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj); D3DVIEWPORT9 vp; vp.X = 0; vp.Y = 0; vp.Width = WINDOW_WIDTH; vp.Height = WINDOW_HEIGHT; vp.MinZ = 0.0f; vp.MaxZ = 1.0f; g_pd3dDevice->SetViewport(&vp); }
/*! MyApp::DrawFrame() */ void MyApp::DrawFrame() { //// シーンアップデート // シーンクリア _device.GetInterface()->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,80), 1.0f, 0); // シーン描画開始 HRESULT hr = _device.GetInterface()->BeginScene(); if (SUCCEEDED(hr)) { //// シーン描画 // ビュー変換 D3DXMATRIX mView; D3DXVECTOR3 vEye(0.0f, 2.0f, -5.0f); D3DXVECTOR3 vAt(0.0f, 0.0f ,0.0f); D3DXVECTOR3 vUp(0.0f, 1.0f, 0.0f); D3DXMatrixLookAtLH(&mView, &vEye, &vAt, &vUp); _device.GetInterface()->SetTransform(D3DTS_VIEW, &mView); // 射影変換 D3DXMATRIX mProj; D3DXMatrixPerspectiveFovLH(&mProj, FOV_ANGLE, (float)SCREEN_W/(float)SCREEN_H, NEAR_Z, FAR_Z); _device.GetInterface()->SetTransform(D3DTS_PROJECTION, &mProj); // ワールド変換 D3DXMATRIX mWorld, mRot, mKuti; D3DXMatrixIdentity(&mWorld); mWorld *= *D3DXMatrixRotationY(&mKuti, D3DXToRadian(-90)); // 口の向きを(1,0,0)にしたいので-90度回転 mWorld *= *D3DXPlus::MatrixRotationVector(&mRot, &_vRotation); _device.GetInterface()->SetTransform(D3DTS_WORLD, &mWorld); // メッシュ描画 _mesh.Render(_device); // 向き描画 D3DXPlus::DrawLine(_device.GetInterface(), D3DXVECTOR3(0,0,0), _vRotation * 2.0f, D3DCOLOR_XRGB(0xff, 0x00, 0xff), D3DCOLOR_XRGB(0x00, 0xff, 0xff)); if (_bTurning) { D3DXPlus::DrawLine(_device.GetInterface(), D3DXVECTOR3(0,0,0), _vTurn * 2.0f, D3DCOLOR_XRGB(0xff, 0x00, 0xff), D3DCOLOR_XRGB(0xff, 0xff, 0x00)); } // シーン描画終了 _device.GetInterface()->EndScene(); } // シーンの表示 hr = _device.GetInterface()->Present(NULL, NULL, NULL, NULL); if (hr == D3DERR_DEVICELOST) ; }
void DCRenderer::Draw(f32 fDeltaTime) { // For our world matrix, we will just rotate the object about the y-axis. D3DXMATRIXA16 mxView, mxProj; D3DXVECTOR3 vEye(0.0f, 5.0f,-5.0f); D3DXVECTOR3 vAt(0.0f,0.0f,1.0f); D3DXVECTOR3 vUp(0.0f,1.0f,0.0f); float fAspectRatio = m_pRenderWidget->width() / (FLOAT)m_pRenderWidget->height(); D3DXMatrixLookAtLH(&mxView, &vEye, &vAt, &vUp); D3DXMatrixPerspectiveFovLH(&mxProj, D3DX_PI/3, fAspectRatio, 0.001f, 100.0f); //models // For our world matrix, we will just rotate the object about the y-axis. D3DXMATRIXA16 mxWorld, mxViewProj; D3DXMatrixIdentity(&mxViewProj); BM_AssertHr(DEVICEPTR->BeginScene()); { BeginRender(); DEVICEPTR->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,D3DCOLOR_COLORVALUE(85.0f/255.0f,101.0f/255.0f,215.0f/255.0f,1.0f), 1.0f, 0 ); BM_AssertHr(DEVICEPTR->EndScene()); //models const std::vector<BatchNode>& nodes = BatchNodes; const u32 nodeNum = nodes.size(); for(u32 nodeIdx = 0; nodeIdx<nodeNum; nodeIdx++) { BM_AssertHr(DEVICEPTR->BeginScene()); const BatchNode& nodePtrRef = nodes[nodeIdx]; const XMFLOAT3& translation = nodePtrRef.translation; D3DXMatrixTranslation(&mxWorld, translation.x, translation.y, translation.z); mxViewProj = mxView * mxProj; DEVICEPTR->SetVertexShaderConstantF(0,(float*)&(mxWorld),4); DEVICEPTR->SetVertexShaderConstantF(4,(float*)mViewProjMatrix,4); DEVICEPTR->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); DEVICEPTR->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); nodePtrRef.model->Draw(0); BM_AssertHr(DEVICEPTR->EndScene()); } BM_AssertHr(DEVICEPTR->BeginScene()); //terrain if(TerrainPtr) { TerrainPtr->Draw(&mxWorld, (D3DXMATRIXA16*)mViewMatrix, (D3DXMATRIXA16*)mProjMatrix); } BMPostFXRenderer::GetInstance()->Render(); EndRender(); BM_AssertHr(DEVICEPTR->EndScene()); } BatchNodes.clear(); }
//-------------------------------------------------------------------------------------- // Create any D3D10 resources that aren't dependant on the back buffer //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D10CreateDevice( ID3D10Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { HRESULT hr; V_RETURN( g_DialogResourceManager.OnD3D10CreateDevice( pd3dDevice ) ); V_RETURN( g_D3DSettingsDlg.OnD3D10CreateDevice( pd3dDevice ) ); V_RETURN( D3DX10CreateFont( pd3dDevice, 15, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Arial", &g_pFont10 ) ); V_RETURN( D3DX10CreateSprite( pd3dDevice, 512, &g_pSprite10 ) ); g_pTxtHelper = new CDXUTTextHelper( NULL, NULL, g_pFont10, g_pSprite10, 15 ); V_RETURN( CDXUTDirectionWidget::StaticOnD3D10CreateDevice( pd3dDevice ) ); // Read the D3DX effect file WCHAR str[MAX_PATH]; V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"MotionBlur10.fx" ) ); DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS; #if defined( DEBUG ) || defined( _DEBUG ) // Set the D3D10_SHADER_DEBUG flag to embed debug information in the shaders. // Setting this flag improves the shader debugging experience, but still allows // the shaders to be optimized and to run exactly the way they will run in // the release configuration of this program. dwShaderFlags |= D3D10_SHADER_DEBUG; #endif V_RETURN( D3DX10CreateEffectFromFile( str, NULL, NULL, "fx_4_0", dwShaderFlags, 0, pd3dDevice, NULL, NULL, &g_pEffect, NULL, NULL ) ); // Obtain the technique handles g_pRenderScene = g_pEffect->GetTechniqueByName( "RenderScene" ); g_pRenderSkinnedScene = g_pEffect->GetTechniqueByName( "RenderSkinnedScene" ); g_pRenderMotionBlur = g_pEffect->GetTechniqueByName( "RenderMotionBlur" ); g_pRenderSkinnedMotionBlur = g_pEffect->GetTechniqueByName( "RenderSkinnedMotionBlur" ); // Obtain the parameter handles g_pmWorldViewProj = g_pEffect->GetVariableByName( "g_mWorldViewProj" )->AsMatrix(); g_pmViewProj = g_pEffect->GetVariableByName( "g_mViewProj" )->AsMatrix(); g_pmWorldView = g_pEffect->GetVariableByName( "g_mWorldView" )->AsMatrix(); g_pmBlurViewProj = g_pEffect->GetVariableByName( "g_mBlurViewProj" )->AsMatrix(); g_pmBlurWorld = g_pEffect->GetVariableByName( "g_mBlurWorld" )->AsMatrix(); g_pmBoneWorld = g_pEffect->GetVariableByName( "g_mBoneWorld" )->AsMatrix(); g_ptxDiffuse = g_pEffect->GetVariableByName( "g_txDiffuse" )->AsShaderResource(); g_pfFrameTime = g_pEffect->GetVariableByName( "g_fFrameTime" )->AsScalar(); g_piNumSteps = g_pEffect->GetVariableByName( "g_iNumSteps" )->AsScalar(); g_pfFadeDist = g_pEffect->GetVariableByName( "g_fFadeDist" )->AsScalar(); // Define our vertex data layout const D3D10_INPUT_ELEMENT_DESC staticlayout[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 }, { "TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 32, D3D10_INPUT_PER_VERTEX_DATA, 0 }, }; D3D10_PASS_DESC PassDesc; g_pRenderScene->GetPassByIndex( 0 )->GetDesc( &PassDesc ); V_RETURN( pd3dDevice->CreateInputLayout( staticlayout, 4, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &g_pStaticVertexLayout ) ); //Create the scene meshes g_SceneMesh.Create( pd3dDevice, L"motionblur\\WindMillStage.sdkmesh" ); g_FanMesh.Create( pd3dDevice, L"motionblur\\Fan.sdkmesh" ); D3DXMatrixTranslation( &g_mFanWorld, 0.0f, 3.62f, 2.012f ); //Create the Linked Meshes g_pLinkedMeshes = new CDXUTSDKMesh[ g_NumLinkedMeshes ]; if( !g_pLinkedMeshes ) return E_OUTOFMEMORY; for( UINT iMesh = 0; iMesh < g_NumLinkedMeshes; iMesh++ ) { g_pLinkedMeshes[iMesh].Create( pd3dDevice, g_MeshLinkages[iMesh].szMeshName ); } const D3D10_INPUT_ELEMENT_DESC skinnedlayout[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 }, { "TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 32, D3D10_INPUT_PER_VERTEX_DATA, 0 }, { "BONES", 0, DXGI_FORMAT_R32G32B32A32_UINT, 0, 44, D3D10_INPUT_PER_VERTEX_DATA, 0 }, { "WEIGHTS", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 60, D3D10_INPUT_PER_VERTEX_DATA, 0 }, }; g_pRenderSkinnedScene->GetPassByIndex( 0 )->GetDesc( &PassDesc ); V_RETURN( pd3dDevice->CreateInputLayout( skinnedlayout, 6, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &g_pSkinnedVertexLayout ) ); g_AnimMesh.Create( pd3dDevice, L"motionblur\\Warrior.sdkmesh" ); g_AnimMesh.LoadAnimation( L"motionblur\\Warrior.sdkmesh_anim" ); //camera D3DXVECTOR3 vEye( 2.0f, 1.3f, -4.0f ); D3DXVECTOR3 vAt( 0.0f, 1.0f, -1.11f ); g_Camera.SetViewParams( &vEye, &vAt ); return S_OK; }
HRESULT DXSourceWindow::Render(BufferQueue* pSyncBuffer,unsigned int uiTransferId) { DXcopyApp::FrameData* pFrame = NULL; unsigned int uiBufferIdx = pSyncBuffer->getBufferForWriting((void*&)pFrame); //change the fill color float clearColorSource[4] = { m_clearColorR, m_clearColorG, m_clearColorB, 1.0f }; //red,green,blue,alpha //fill the backbuffer of the Source with 'clearColorR' m_pImmediateContext->ClearRenderTargetView( m_pBackBuffer_RTV, clearColorSource ); m_pImmediateContext->ClearDepthStencilView( m_pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 ); D3DXMATRIX mWorldViewProjection; D3DXMATRIX mWorldView; D3DXMATRIX mWorld; D3DXMATRIX mView; D3DXMATRIX mProj; // Set the per object constant data D3DXMatrixRotationAxis( &mWorld, &D3DXVECTOR3(1,1,1), m_Cube_angle ); m_Cube_angle += 0.04f * 0.01745f; if (m_Cube_angle >= 2.0f*3.1415926f) { m_Cube_angle = 0.0f; } D3DXVECTOR3 vEye( 0.0f, 0.0f, 2.0f ); D3DXVECTOR3 vLook( 0.0f,0.0f,0.0f ); D3DXVECTOR3 vUp( 0.0f,1.0f,0.0f ); D3DXMatrixLookAtLH( &mView, &vEye, &vLook, &vUp ); D3DXMatrixPerspectiveFovLH(&mProj, 3.1415926f/4.0f, (float)DXwindow::m_width/(float)DXwindow::m_height, 0.1f, 10.0f); mWorldViewProjection = mWorld * mView * mProj; mWorldView = mWorld * mView; D3D11_MAPPED_SUBRESOURCE MappedResource; m_pImmediateContext->Map( m_Cube_pcb, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource ); CUBE_CB* pCB = ( CUBE_CB* )MappedResource.pData; D3DXMatrixTranspose( &pCB->f4x4WorldViewProjection, &mWorldViewProjection ); D3DXMatrixTranspose( &pCB->f4x4WorldView, &mWorldView ); m_pImmediateContext->Unmap( m_Cube_pcb, 0 ); m_pImmediateContext->VSSetConstantBuffers( 0, 1, &m_Cube_pcb ); m_pImmediateContext->PSSetConstantBuffers( 0, 1, &m_Cube_pcb ); m_pImmediateContext->VSSetShader( m_Cube_pVertexShader, NULL, 0 ); m_pImmediateContext->PSSetShader( m_Cube_pPixelShader, NULL, 0 ); m_pImmediateContext->IASetInputLayout( m_Cube_pVertexLayout11 ); m_pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); UINT Stride = sizeof( CUBE_Vertex1 ); UINT Offset = 0; m_pImmediateContext->IASetVertexBuffers( 0, 1, &m_Cube_pVertexBuffer, &Stride, &Offset ); m_pImmediateContext->IASetIndexBuffer( m_Cube_pIndexBuffer, DXGI_FORMAT_R32_UINT, 0 ); m_pImmediateContext->PSSetShaderResources( 0, 1, &m_Cube_pTextureRV ); m_pImmediateContext->PSSetSamplers( 0, 1, &m_Cube_pSamplerLinear ); m_pImmediateContext->DrawIndexed( 36, 0, 0 ); // update frame data pFrame->uiTransferId = uiTransferId; m_pImmediateContext->CopyResource(m_source_SDItexture[uiBufferIdx], m_pBackBuffer ); AmdDxMarkerInfo m_pInfo; m_pInfo.markerValue = pFrame->uiTransferId; m_pInfo.markerOffset = pFrame->ullMarkerBusAddress & 0xfff; BOOL WriteMarkerSuccess = m_pSDI->WriteMarker11(m_source_SDItexture[uiBufferIdx], &m_pInfo); if ( !WriteMarkerSuccess ) { PASS_TEST(E_FAIL) } // This Flush() call is not necessary but with this one, the performance will be much better. m_pImmediateContext->Flush(); pSyncBuffer->releaseWriteBuffer(); m_pSwapChain->Present(0,0); return S_OK; }