//----------------------------------------------------------------------------- // Name: CTiny::Draw() // Desc: Renders this CTiny instace using the current animation frames. //----------------------------------------------------------------------------- HRESULT CTiny::Draw(D3DXMATRIXA16 *mxViewProj, bool bRenderShadow) { LPDIRECT3DDEVICE9 pDevice = this->m_pMA->GetDevice(); D3DLIGHT9 light; pDevice->GetLight(0, &light); // update the ViewProjection matric for the animation ID3DXEffect* pMAEffect = m_pMA->GetEffect(); if( pMAEffect ) { pMAEffect->SetMatrix( "g_mViewProj", mxViewProj ); pMAEffect->SetVector( "lhtDir", (D3DXVECTOR4 *)&(light.Direction)); } SAFE_RELEASE( pMAEffect ); SAFE_RELEASE( pDevice); if(bRenderShadow) { m_pMA->SetTechnique( "ShadowPass" ); } else { m_pMA->SetTechnique( "Skinning20" ); // translate player } return m_pAI->Draw(); }
bool Action(IDirect3DDevice9 *d3dev, IDirect3DTexture9 *src, IDirect3DTexture9 *dst, float w, float h, float power, dword color) { CUSTOMVERTEX vertices[] = { { 0.0f, 0.0f, 0.5f, 1.f, 0xffffffff, 0.f, 0.f}, { 320.0f, 0.0f, 0.5f, 1.f, 0xffffffff, 1.f, 0.f}, { 320.0f, 240.0f, 0.5f, 1.f, 0xffffffff, 1.f, 1.f}, { 0.0f, 0.0f, 0.5f, 1.f, 0xffffffff, 0.f, 0.f}, { 320.0f, 240.0f, 0.5f, 1.f, 0xffffffff, 1.f, 1.f}, { 0.0f, 240.0f, 0.5f, 1.f, 0xffffffff, 0.f, 1.f} }; HRESULT r; VOID *pVertices; int texType; float texCx,texCy; vertices[0].x=0; vertices[0].y=0; vertices[1].x=w; vertices[1].y=0; vertices[2].x=w; vertices[2].y=h; vertices[3].x=0; vertices[3].y=0; vertices[4].x=w; vertices[4].y=h; vertices[5].x=0; vertices[5].y=h; /* vertices[0].color=0xFFFFFFFF; vertices[1].color=0xFFFFFFFF; vertices[2].color=0xFFFFFFFF; vertices[3].color=0xFFFFFFFF; vertices[4].color=0xFFFFFFFF; vertices[5].color=0xFFFFFFFF; */ assert(VBUFSIZE==sizeof(vertices)); if(vb->Lock(0, VBUFSIZE, (void**)&pVertices, 0)==D3D_OK) { memcpy(pVertices, vertices, VBUFSIZE); vb->Unlock(); } IDirect3DSurface9 *renderO=null; IDirect3DSurface9 *renderS=null; d3dev->GetRenderTarget(0, &renderO); if(dst->GetSurfaceLevel(0, &renderS)==D3D_OK) { d3dev->BeginScene(); d3dev->SetRenderTarget(0, renderS); if(effect) { effect->SetTechnique("elektronika"); effect->SetTexture("texture0", src); if(hColor) { D3DXVECTOR4 v; byte rc,gc,bc; colorRGB(&rc,&gc, &bc, (dword)color); v.x=(float)rc/255.f; v.y=(float)gc/255.f; v.z=(float)bc/255.f; v.w=1.f; effect->SetVector(hColor, &v); } if(hPower) effect->SetFloat(hPower, (FLOAT)power); r=d3dev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE); r=d3dev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); r=d3dev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); r=d3dev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); r=d3dev->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); r=d3dev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); r=d3dev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ZERO); r=d3dev->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); { UINT uPasses; effect->Begin( &uPasses, 0 ); for( UINT uPass = 0; uPass < uPasses; ++uPass ) { effect->BeginPass( uPass ); r=d3dev->SetStreamSource(0, vb, 0, sizeof(CUSTOMVERTEX)); r=d3dev->SetFVF(D3DFVF_CUSTOMVERTEX); r=d3dev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2); effect->EndPass(); } effect->End(); } } d3dev->EndScene(); renderS->Release(); } d3dev->SetRenderTarget(0, renderO); return true; }
void CLcXSkinIns::Render() { HRESULT hr=-1; LPDIRECT3DDEVICE9 pDev = (LPDIRECT3DDEVICE9)LcDev_GetD3Device(); CLcXSkinSrc* pOrg = (CLcXSkinSrc*)m_pOrg; ID3DXEffect* pEft = pOrg->GetEffect(); // Setup the projection matrix D3DXMATRIX matProj; pDev->GetTransform(D3DTS_PROJECTION, &matProj); D3DLIGHT9 light; D3DXVECTOR3 vecLightDirUnnormalized(0.0f, -1.0f, 1.0f); ZeroMemory( &light, sizeof(D3DLIGHT9) ); light.Type = D3DLIGHT_DIRECTIONAL; light.Diffuse.r = 1.0f; light.Diffuse.g = 1.0f; light.Diffuse.b = 1.0f; D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecLightDirUnnormalized ); light.Position.x = 0.0f; light.Position.y = -1.0f; light.Position.z = 1.0f; light.Range = 1000.0f; pDev->SetLight(0, &light ); pDev->LightEnable(0, TRUE ); // Set Light for vertex shader D3DXVECTOR4 vLightDir( 0.0f, 1.0f, -1.0f, 0.0f ); D3DXVec4Normalize( &vLightDir, &vLightDir ); // for HLSL { pEft->SetMatrix( "mViewProj", &matProj); pEft->SetVector( "lhtDir", &vLightDir); } // for shader { // set the projection matrix for the vertex shader based skinning method D3DXMatrixTranspose(&matProj, &matProj); pDev->SetVertexShaderConstantF(2, (float*)&matProj, 4); pDev->SetVertexShaderConstantF(1, (float*)&vLightDir, 1); } if(m_pAC) m_pAC->AdvanceTime(m_fElapse, NULL); pOrg->UpdateFrameMatrices(m_pFrameOrg, &m_mtWld); pOrg->DrawFrame(m_pFrameOrg); static D3DXMATRIX mtI(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1); pDev->SetTransform(D3DTS_WORLD, &mtI); }
void TriPickDemo::drawScene() { HR(g_pDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0)); HR(g_pDevice->BeginScene()); //rendering characters { ID3DXEffect* pMAEffect = m_pCharacter->GetEffect(); if (pMAEffect) { pMAEffect->SetMatrix("g_mViewProj", &(g_Camera->viewProj())); } //set lighting D3DXVECTOR4 v(m_Light.dirW.x, m_Light.dirW.y, m_Light.dirW.z, 1.0f); if (pMAEffect) { pMAEffect->SetVector("lhtDir", &v); } SAFE_RELEASE(pMAEffect); /*/ compute reorientation matrix based on default orientation and bounding radius D3DXMATRIX mx, Orientation; //float fScale = 1.f / g_Character.GetBoundingRadius() / 7.f; //D3DXMatrixScaling(&mx, fScale, fScale, fScale); D3DXMatrixScaling(&mx, 1.0f, 1.0f, 1.0f); Orientation = mx; //D3DXMatrixRotationX(&mx, -D3DX_PI / 2.0f); D3DXMatrixRotationX(&mx, 0.0f); D3DXMatrixMultiply(&Orientation, &Orientation, &mx); //D3DXMatrixRotationY(&mx, D3DX_PI); D3DXMatrixRotationY(&mx, 0.0f); D3DXMatrixMultiply(&Orientation, &Orientation, &mx); D3DXMATRIX mxWorld; // compute world matrix based on pos/face D3DXMatrixRotationY(&mxWorld, 0.0f); D3DXMatrixTranslation(&mx, 0.0f, 0.0f, 0.0f); D3DXMatrixMultiply(&mxWorld, &mxWorld, &mx); D3DXMatrixMultiply(&mxWorld, &Orientation, &mxWorld);*/ m_pCharacter->SetPose(m_matWorld); //check seclection D3DXVECTOR3 mouseMV; if (gDInput->mouseButtonDown(0)) { if (L_Hand->isPick == false) L_Hand->isPick = checkBonePick(L_Hand->pCylinder, L_Hand->curWorld); if (R_Hand->isPick == false) R_Hand->isPick = checkBonePick(R_Hand->pCylinder, R_Hand->curWorld); if (L_Leg->isPick == false) L_Leg->isPick = checkBonePick(L_Leg->pCylinder, L_Leg->curWorld); if (R_Leg->isPick == false) R_Leg->isPick = checkBonePick(R_Leg->pCylinder, R_Leg->curWorld); //get move vector if (L_Hand->isPick) { mouseMV = getMouseMoveVector(1.0f); m_pIK->addLHMove(mouseMV); } else if (R_Hand->isPick) { mouseMV = getMouseMoveVector(1.0f); m_pIK->addRHMove(mouseMV); } else if (L_Leg->isPick) { mouseMV = getMouseMoveVector(1.0f); m_pIK->addLLMove(mouseMV); } else if (R_Leg->isPick) { mouseMV = getMouseMoveVector(1.0f); m_pIK->addRLMove(mouseMV); } } else { L_Hand->isPick = false; R_Hand->isPick = false; L_Leg->isPick = false; R_Leg->isPick = false; } // wireframe //g_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); //Update IK if (m_pIK) { m_pIK->UpdateHeadIK(); m_pIK->UpdateIK(); } //m_pCharacter->DrawBoneCylinder(m_pCharacter->getPBone(), NULL, m_matWorld); m_pCharacter->Render(NULL); } HR(g_pDevice->EndScene()); HR(g_pDevice->Present(0, 0, 0, 0)); }
//----------------------------------------------------------------------------- // Name: Render() // Desc: Called once per frame, the call is the entry point for 3d // rendering. This function sets up render states, clears the // viewport, and renders the scene. //----------------------------------------------------------------------------- HRESULT CMyD3DApplication::Render() { // Begin the scene if( SUCCEEDED( m_pd3dDevice->BeginScene() ) ) { // Render the Skybox { D3DXMATRIX matWorld; D3DXMatrixScaling( &matWorld, 10.0f, 10.0f, 10.0f ); D3DXMATRIX matView(m_matView); matView._41 = matView._42 = matView._43 = 0.0f; m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld ); m_pd3dDevice->SetTransform( D3DTS_VIEW, &matView ); m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &m_matProject ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ADDRESSU, D3DTADDRESS_MIRROR ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ADDRESSV, D3DTADDRESS_MIRROR ); // Always pass Z-test, so we can avoid clearing color and depth buffers m_pd3dDevice->SetRenderState( D3DRS_ZFUNC, D3DCMP_ALWAYS ); m_pSkyBox->Render( m_pd3dDevice ); m_pd3dDevice->SetRenderState( D3DRS_ZFUNC, D3DCMP_LESSEQUAL ); } // Render the environment-mapped ShinyTeapot { // Set transform state D3DXMATRIX matViewProject; D3DXMatrixMultiply( &matViewProject, &m_matView, &m_matProject ); D3DXMATRIX matViewInv; D3DXMatrixInverse( &matViewInv, NULL, &m_matView ); D3DXVECTOR4 vecPosition( matViewInv._41, matViewInv._42, matViewInv._43, 1.0f ); m_pEffect->SetMatrix( "matWorld", &m_matWorld ); m_pEffect->SetMatrix( "matViewProject", &matViewProject ); m_pEffect->SetVector( "vecPosition", &vecPosition ); // Draw teapot LPDIRECT3DVERTEXBUFFER8 pVB; LPDIRECT3DINDEXBUFFER8 pIB; m_pShinyTeapot->m_pLocalMesh->GetVertexBuffer( &pVB ); m_pShinyTeapot->m_pLocalMesh->GetIndexBuffer( &pIB ); m_pd3dDevice->SetStreamSource( 0, pVB, sizeof(ENVMAPPEDVERTEX) ); m_pd3dDevice->SetIndices( pIB, 0 ); UINT uPasses; m_pEffect->Begin( &uPasses, 0 ); for( UINT iPass = 0; iPass < uPasses; iPass++ ) { m_pEffect->Pass( iPass ); m_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, m_pShinyTeapot->m_pLocalMesh->GetNumVertices(), 0, m_pShinyTeapot->m_pLocalMesh->GetNumFaces() ); } m_pEffect->End(); SAFE_RELEASE( pVB ); SAFE_RELEASE( pIB ); } // Output statistics m_pFont->DrawText( 2, 0, D3DCOLOR_ARGB(255,255,255,0), m_strFrameStats ); m_pFont->DrawText( 2, 20, D3DCOLOR_ARGB(255,255,255,0), m_strDeviceStats ); // End the scene. m_pd3dDevice->EndScene(); } return S_OK; }