Exemplo n.º 1
0
void MirrorDemo::drawRoom()
{
	HR(mFX->SetMatrix(mhWVP, &(mRoomWorld*mView*mProj)));
	D3DXMATRIX worldInvTrans;
	D3DXMatrixInverse(&worldInvTrans, 0, &mRoomWorld);
	D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans);
	HR(mFX->SetMatrix(mhWorldInvTrans, &worldInvTrans));
	HR(mFX->SetMatrix(mhWorld, &mRoomWorld));

	HR(gd3dDevice->SetVertexDeclaration(VertexPNT::Decl));
	HR(gd3dDevice->SetStreamSource(0, mRoomVB, 0, sizeof(VertexPNT)));

	// Begin passes.
	UINT numPasses = 0;
	HR(mFX->Begin(&numPasses, 0));
	for(UINT i = 0; i < numPasses; ++i)
	{
		HR(mFX->BeginPass(i));

		// draw the floor
		HR(mFX->SetTexture(mhTex, mFloorTex));
		HR(mFX->CommitChanges());
		HR(gd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2));

		// draw the walls
		HR(mFX->SetTexture(mhTex, mWallTex));
		HR(mFX->CommitChanges());
		HR(gd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 6, 4));

		HR(mFX->EndPass());
	}
	HR(mFX->End());
}
Exemplo n.º 2
0
void SpotlightDemo::drawSpheres()
{
	D3DXMATRIX W, WIT;

	HR(mFX->SetValue(mhAmbientMtrl, &mSphereMtrl.ambient, sizeof(D3DXCOLOR)));
	HR(mFX->SetValue(mhDiffuseMtrl, &mSphereMtrl.diffuse, sizeof(D3DXCOLOR)));
	HR(mFX->SetValue(mhSpecMtrl, &mSphereMtrl.spec, sizeof(D3DXCOLOR)));
	HR(mFX->SetFloat(mhSpecPower, mSphereMtrl.specPower));
	for(int z = -30; z <= 30; z+= 10)
	{
		D3DXMatrixTranslation(&W, -10.0f, 7.5f, (float)z);
		D3DXMatrixInverse(&WIT, 0, &W);
		D3DXMatrixTranspose(&WIT, &WIT);

		HR(mFX->SetMatrix(mhWVP, &(W*mView*mProj)));
		HR(mFX->SetMatrix(mhWorld, &W));
		HR(mFX->SetMatrix(mhWorldInvTrans, &WIT));
		HR(mFX->CommitChanges());
		HR(mSphere->DrawSubset(0));

		D3DXMatrixTranslation(&W, 10.0f, 7.5f, (float)z);
		D3DXMatrixInverse(&WIT, 0, &W);
		D3DXMatrixTranspose(&WIT, &WIT);

		HR(mFX->SetMatrix(mhWVP, &(W*mView*mProj)));
		HR(mFX->SetMatrix(mhWorld, &W));
		HR(mFX->SetMatrix(mhWorldInvTrans, &WIT));
		HR(mFX->CommitChanges());
		HR(mSphere->DrawSubset(0));
	}
}
Exemplo n.º 3
0
void SpotlightDemo::drawCylinders()
{
	D3DXMATRIX T, R, W, WIT;

	D3DXMatrixRotationX(&R, D3DX_PI*0.5f);

	HR(mFX->SetValue(mhAmbientMtrl, &mCylinderMtrl.ambient, sizeof(D3DXCOLOR)));
	HR(mFX->SetValue(mhDiffuseMtrl, &mCylinderMtrl.diffuse, sizeof(D3DXCOLOR)));
	HR(mFX->SetValue(mhSpecMtrl, &mCylinderMtrl.spec, sizeof(D3DXCOLOR)));
	HR(mFX->SetFloat(mhSpecPower, mCylinderMtrl.specPower));
	for(int z = -30; z <= 30; z+= 10)
	{
		D3DXMatrixTranslation(&T, -10.0f, 3.0f, (float)z);
		W = R*T;
		D3DXMatrixInverse(&WIT, 0, &W);
		D3DXMatrixTranspose(&WIT, &WIT);

		HR(mFX->SetMatrix(mhWVP, &(W*mView*mProj)));
		HR(mFX->SetMatrix(mhWorld, &W));
		HR(mFX->SetMatrix(mhWorldInvTrans, &WIT));
		HR(mFX->CommitChanges());
		HR(mCylinder->DrawSubset(0));

		D3DXMatrixTranslation(&T, 10.0f, 3.0f, (float)z);
		W = R*T;
		D3DXMatrixInverse(&WIT, 0, &W);
		D3DXMatrixTranspose(&WIT, &WIT);

		HR(mFX->SetMatrix(mhWVP, &(W*mView*mProj)));
		HR(mFX->SetMatrix(mhWorld, &W));
		HR(mFX->SetMatrix(mhWorldInvTrans, &WIT));
		HR(mFX->CommitChanges());
		HR(mCylinder->DrawSubset(0));
	}
}
Exemplo n.º 4
0
void SphereCylDemo::drawCylinders()
{
	HR(gd3dDevice->SetRenderState(D3DRS_WRAP0, D3DWRAP_U));

	D3DXMATRIX T, R, W, WIT;

	D3DXMatrixRotationX(&R, -D3DX_PI*0.5f);

	HR(mFX->SetValue(mhAmbientMtrl, &mCylinderMtrl.ambient, sizeof(D3DXCOLOR)));
	HR(mFX->SetValue(mhDiffuseMtrl, &mCylinderMtrl.diffuse, sizeof(D3DXCOLOR)));
	HR(mFX->SetValue(mhSpecMtrl, &mCylinderMtrl.spec, sizeof(D3DXCOLOR)));
	HR(mFX->SetFloat(mhSpecPower, mCylinderMtrl.specPower));

	HR(mFX->SetTexture(mhTex, mCylTex));
	for(int z = -30; z <= 30; z+= 10)
	{
		D3DXMatrixTranslation(&T, -10.0f, 3.0f, (float)z);
		W = R*T;
		D3DXMatrixInverse(&WIT, 0, &W);
		D3DXMatrixTranspose(&WIT, &WIT);

		HR(mFX->SetMatrix(mhWVP, &(W*mView*mProj)));
		HR(mFX->SetMatrix(mhWorld, &W));
		HR(mFX->SetMatrix(mhWorldInvTrans, &WIT));
		HR(mFX->CommitChanges());
		HR(mCylinder->DrawSubset(0));

		D3DXMatrixTranslation(&T, 10.0f, 3.0f, (float)z);
		W = R*T;
		D3DXMatrixInverse(&WIT, 0, &W);
		D3DXMatrixTranspose(&WIT, &WIT);

		HR(mFX->SetMatrix(mhWVP, &(W*mView*mProj)));
		HR(mFX->SetMatrix(mhWorld, &W));
		HR(mFX->SetMatrix(mhWorldInvTrans, &WIT));
		HR(mFX->CommitChanges());
		HR(mCylinder->DrawSubset(0));
	}
	// Disable.
	HR(gd3dDevice->SetRenderState(D3DRS_WRAP0, 0));
}
Exemplo n.º 5
0
void SolarSysDemo::drawScene()
{
	// Clear the backbuffer and depth buffer.
	HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff000000, 1.0f, 0));

	HR(gd3dDevice->BeginScene());

	HR(mFX->SetValue(mhLight, &mLight, sizeof(DirLight)));

	HR(mFX->SetTechnique(mhTech));
	UINT numPasses = 0;
	HR(mFX->Begin(&numPasses, 0));
	HR(mFX->BeginPass(0));

	// Wrap the texture coordinates that get assigned to TEXCOORD2 in the pixel shader.
	HR(gd3dDevice->SetRenderState(D3DRS_WRAP2, D3DWRAP_U));

	// Build the world transforms for each frame, then render them.
	buildObjectWorldTransforms();
	D3DXMATRIX S;
	for(int i = 0; i < NUM_OBJECTS; ++i)
	{
		float s = mObject[i].size;
		D3DXMatrixScaling(&S, s, s, s);

		// Prefix the frame matrix with a scaling transformation to
		// size it relative to the world.
		mWorld = S * mObject[i].toWorldXForm;
		HR(mFX->SetMatrix(mhWVP, &(mWorld*mView*mProj)));
		D3DXMATRIX worldInvTrans;
		D3DXMatrixInverse(&worldInvTrans, 0, &mWorld);
		D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans);
		HR(mFX->SetMatrix(mhWorldInvTrans, &worldInvTrans));
		HR(mFX->SetMatrix(mhWorld, &mWorld));
		HR(mFX->SetValue(mhMtrl, &mWhiteMtrl, sizeof(Mtrl)));
		HR(mFX->SetTexture(mhTex, mObject[i].tex));	
		HR(mFX->CommitChanges());
		
		mSphere->DrawSubset(0);
	}
	HR(gd3dDevice->SetRenderState(D3DRS_WRAP2, 0));
	HR(mFX->EndPass());
	HR(mFX->End());
	
	mGfxStats->display();

	HR(gd3dDevice->EndScene());

	// Present the backbuffer.
	HR(gd3dDevice->Present(0, 0, 0, 0));
}
Exemplo n.º 6
0
void WaterDemo::drawScene()
{
    HR(gd3dDevice->BeginScene());

    mSky->draw();

    HR(mFX->SetValue(mhLight, &mLight, sizeof(DirLight)));
    HR(mFX->SetMatrix(mhWVP, &(mSceneWorld*gCamera->viewProj())));
    HR(mFX->SetValue(mhEyePosW, &gCamera->pos(), sizeof(D3DXVECTOR3)));

    UINT numPasses = 0;
    HR(mFX->Begin(&numPasses, 0));
    HR(mFX->BeginPass(0));

    for(UINT j = 0; j < mSceneMtrls.size(); ++j)
    {
        HR(mFX->SetValue(mhMtrl, &mSceneMtrls[j], sizeof(Mtrl)));

        // If there is a texture, then use.
        if(mSceneTextures[j] != 0)
        {
            HR(mFX->SetTexture(mhTex, mSceneTextures[j]));
        }

        // But if not, then set a pure white texture.  When the texture color
        // is multiplied by the color from lighting, it is like multiplying by
        // 1 and won't change the color from lighting.
        else
        {
            HR(mFX->SetTexture(mhTex, mWhiteTex));
        }

        HR(mFX->SetTexture(mhNormalMap, mSceneNormalMaps[j]));

        HR(mFX->CommitChanges());
        HR(mSceneMesh->DrawSubset(j));
    }
    HR(mFX->EndPass());
    HR(mFX->End());

    // Draw alpha blended object last.
    mWater->draw();

    mGfxStats->display();

    HR(gd3dDevice->EndScene());

    // Present the backbuffer.
    HR(gd3dDevice->Present(0, 0, 0, 0));
}
Exemplo n.º 7
0
void XFileDemo::drawScene()
{
	HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffeeeeee, 1.0f, 0));
	HR(gd3dDevice->BeginScene());

	HR(mFX->SetValue(mhLight, &mLight, sizeof(DirLight)));
	HR(mFX->SetMatrix(mhWVP, &(mWorld*mView*mProj)));

	D3DXMATRIX worldInvTrans;
	D3DXMatrixInverse(&worldInvTrans, 0, &mWorld);
	D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans);
	HR(mFX->SetMatrix(mhWorldInvTrans, &worldInvTrans));
	HR(mFX->SetMatrix(mhWorld, &mWorld));

	HR(mFX->SetTechnique(mhTech));
	UINT numPasses = 0;
	HR(mFX->Begin(&numPasses, 0));
	HR(mFX->BeginPass(0));

	for (int j = 0; j < mMtrl.size(); ++j)
	{
		HR(mFX->SetValue(mhMtrl, &mMtrl[j], sizeof(Material)));

		if (mTex[j] != 0)
		{
			HR(mFX->SetTexture(mhTex, mTex[j]));
		}
		else
		{
			HR(mFX->SetTexture(mhTex, mWhiteTex));
		}

		HR(mFX->CommitChanges());
		HR(mMesh->DrawSubset(j));
	}
	HR(mFX->EndPass());
	HR(mFX->End());

	mGfxStats->display(D3DCOLOR_XRGB(0,0,0));
	HR(gd3dDevice->EndScene());
	HR(gd3dDevice->Present(0, 0, 0, 0));
}
Exemplo n.º 8
0
void CExplodingBullet::Render()
{
	if(GetType() == SMASHBULLET)
		return;
	CAssetManager* pAM = CAssetManager::GetInstance();
	D3DXMATRIX ViewProj = CGameplayState::GetInstance()->GetCamera()->GetViewProjMatrix();
	CRenderer* pRenderer = CRenderer::GetInstance();
	IDirect3DDevice9* pD3D = pRenderer->GetDirect3DDevice();

	pD3D->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
	pD3D->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	pD3D->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

	pD3D->SetVertexDeclaration(pAM->GetVertexDeclaration(BASEOBJECTDECL));
	ID3DXEffect* pShader = pAM->GetShader(EFFECT_OBJ_SPHERE);
	unsigned passes(0);
	pShader->Begin(&passes,0);
	for(unsigned i(0);i < passes; i++)
	{
		pShader->BeginPass(i);

		pShader->SetTexture("gDiffuseTexture", pAM->GetTexture(EFFECT_OBJ_SPHERE));
		pShader->SetMatrix("gViewProjection", &(ViewProj));
		D3DXMATRIX scaleMat, worldMat;
		float scale = GetRadius();
		D3DXMatrixScaling(&scaleMat, scale, scale, scale);
		pShader->SetMatrix("gWorld",&(scaleMat*GetMatrix()));
		pShader->SetFloatArray("gColor", GetColor(), 4);
		pShader->CommitChanges();

		pD3D->SetVertexDeclaration(pAM->GetVertexDeclaration(BASEOBJECTDECL));
		pD3D->SetStreamSource(0, pAM->GetVertBuffer(EFFECT_OBJ_SPHERE), 0, sizeof(tVertex));
		pD3D->SetIndices(pAM->GetIndexBuffer(EFFECT_OBJ_SPHERE));
		pD3D->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, pAM->GetNumVerts(EFFECT_OBJ_SPHERE), 0, pAM->GetNumTriangles(EFFECT_OBJ_SPHERE));

		pShader->EndPass();
	}
	pShader->End();
	pD3D->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
}
Exemplo n.º 9
0
void PropsDemo::drawObject(Object3D& obj, const D3DXMATRIX& toWorld)
{
	// Transform AABB into the world space.

	AABB box;
	obj.box.xform(toWorld, box);

	// Only draw if AABB is visible.
	if( gCamera->isVisible( box ) )
	{
		HR(mFX->SetMatrix(mhWVP, &(toWorld*gCamera->viewProj())));
		D3DXMATRIX worldInvTrans;
		D3DXMatrixInverse(&worldInvTrans, 0, &toWorld);
		D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans);
		HR(mFX->SetMatrix(mhWorldInvTrans, &worldInvTrans));
		HR(mFX->SetMatrix(mhWorld, &toWorld));

		for(UINT j = 0; j < obj.mtrls.size(); ++j)
		{
			HR(mFX->SetValue(mhMtrl, &obj.mtrls[j], sizeof(Mtrl)));

			// If there is a texture, then use.
			if(obj.textures[j] != 0)
			{
				HR(mFX->SetTexture(mhTex, obj.textures[j]));
			}

			// But if not, then set a pure white texture.  When the texture color
			// is multiplied by the color from lighting, it is like multiplying by
			// 1 and won't change the color from lighting.
			else
			{
				HR(mFX->SetTexture(mhTex, mWhiteTex));
			}

			HR(mFX->CommitChanges());
			HR(obj.mesh->DrawSubset(j));
		}
	}
}
Exemplo n.º 10
0
void ProjTexDemo::drawScene()
{
	HR(gd3dDevice->BeginScene());

	// Draw sky first--this also replaces our gd3dDevice->Clear call.
	//mSky->draw();
	HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0));

	// Draw the scene mesh.
	HR(mFX->SetTechnique(mhTech));
	HR(mFX->SetMatrix(mhWorldInvTrans, &mSceneWorld));
	HR(mFX->SetMatrix(mhWorld, &mSceneWorld));
	HR(mFX->SetValue(mhLight, &mLight, sizeof(SpotLight)));
	HR(mFX->SetMatrix(mhWVP, &(mSceneWorld*gCamera->viewProj())));
	HR(mFX->SetValue(mhEyePosW, &gCamera->pos(), sizeof(D3DXVECTOR3)));
	HR(mFX->SetTexture(mhTex, mSkullTex));
	HR(mFX->SetMatrix(mhLightWVP, &mLightWVP));

	UINT numPasses = 0;
	HR(mFX->Begin(&numPasses, 0));
	HR(mFX->BeginPass(0));

	for(UINT j = 0; j < mSceneMtrls.size(); ++j)
	{
		HR(mFX->SetValue(mhMtrl, &mSceneMtrls[j], sizeof(Mtrl)));

		HR(mFX->CommitChanges());
		HR(mSceneMesh->DrawSubset(j));
	}

	HR(mFX->EndPass());
	HR(mFX->End());

	mGfxStats->display();

	HR(gd3dDevice->EndScene());

	// Present the backbuffer.
	HR(gd3dDevice->Present(0, 0, 0, 0));
}
Exemplo n.º 11
0
void SpotlightDemo::drawGrid()
{
	HR(gd3dDevice->SetStreamSource(0, mVB, 0, sizeof(VertexPN)));
	HR(gd3dDevice->SetIndices(mIB));
	HR(gd3dDevice->SetVertexDeclaration(VertexPN::Decl));

	D3DXMATRIX W, WIT;
	D3DXMatrixIdentity(&W);
	D3DXMatrixInverse(&WIT, 0, &W);
	D3DXMatrixTranspose(&WIT, &WIT);
	HR(mFX->SetMatrix(mhWorld, &W));
	HR(mFX->SetMatrix(mhWVP, &(W*mView*mProj)));
	HR(mFX->SetMatrix(mhWorldInvTrans, &WIT));

	HR(mFX->SetValue(mhAmbientMtrl, &mGridMtrl.ambient, sizeof(D3DXCOLOR)));
	HR(mFX->SetValue(mhDiffuseMtrl, &mGridMtrl.diffuse, sizeof(D3DXCOLOR)));
	HR(mFX->SetValue(mhSpecMtrl, &mGridMtrl.spec, sizeof(D3DXCOLOR)));
	HR(mFX->SetFloat(mhSpecPower, mGridMtrl.specPower));

	HR(mFX->CommitChanges());
	HR(gd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, mNumGridVertices, 0, mNumGridTriangles));
}
Exemplo n.º 12
0
// THIS Function should be removed when we go to the full render object implementation - it's
//	temporary on the path to full render objects. The D3D pipe render model path call this guy to do
//	the transform and lighting stuff.
void CD3DSkelMesh::Render(ModelInstance *pInstance, D3DMATRIX* pD3DTransforms, CD3DRenderStyle* pRenderStyle, uint32 iRenderPass)
{
	switch (m_eRenderMethod)
	{
		case eD3DRenderDirect :
		{	// We need to do the bone walk, but we can render direct (they've been pre-processed into triangle group/bone group order)...
			uint32 iCurrentPolyIndex = 0;
			int32 nNumActiveBones = -1;
			for( int32 iBoneSet = 0; (iBoneSet < (int32)m_iBoneSetCount) ; ++iBoneSet )
			{
				BoneSetListItem* pBoneSet = &m_pBoneSetArray[iBoneSet];
				nNumActiveBones = SetTransformsToBoneSet(pBoneSet,pD3DTransforms, nNumActiveBones);

				// Set the vertex shader constants.
				if (m_pVertexShader != NULL)
				{
					// Let the client set some constants.
					if (NULL != i_client_shell)
					{
						i_client_shell->OnVertexShaderSetConstants(m_pVertexShader, iRenderPass, pRenderStyle, pInstance,
																   LTShaderDeviceStateImp::GetSingleton());
					}

					// Send the constants to the video card.
					LTVertexShaderMgr::GetSingleton().SetVertexShaderConstants(m_pVertexShader);
				}

				// Set the pixel shader constants.
				if (m_pPixelShader != NULL)
				{
					// Let the client set some constants.
					if (NULL != i_client_shell)
					{
						i_client_shell->OnPixelShaderSetConstants(m_pPixelShader, iRenderPass, pRenderStyle, pInstance,
																  LTShaderDeviceStateImp::GetSingleton());
					}

					// Send the constants to the video card.
					LTPixelShaderMgr::GetSingleton().SetPixelShaderConstants(m_pPixelShader);
				}

				RSD3DOptions rsD3DOptions;
				pRenderStyle->GetDirect3D_Options(&rsD3DOptions);
				if(rsD3DOptions.bUseEffectShader)
				{
					LTEffectImpl* _pEffect = (LTEffectImpl*)LTEffectShaderMgr::GetSingleton().GetEffectShader(rsD3DOptions.EffectShaderID);
					ID3DXEffect* pEffect = _pEffect->GetEffect();
				
					if(pEffect)
					{
						i_client_shell->OnEffectShaderSetParams((LTEffectShader*)_pEffect, pRenderStyle, pInstance, LTShaderDeviceStateImp::GetSingleton());
						pEffect->SetInt("BoneCount", nNumActiveBones);
						pEffect->CommitChanges();
					}
				
				}

				m_VBController.Render(	pBoneSet->iFirstVertIndex,
										iCurrentPolyIndex,
										pBoneSet->iVertCount,
										(pBoneSet->iIndexIntoIndexBuff - iCurrentPolyIndex)/3);



				iCurrentPolyIndex = pBoneSet->iIndexIntoIndexBuff;

				IncFrameStat(eFS_ModelRender_NumSkeletalRenderObjects, 1);
			}

			break;
		}
		case eD3DRenderMatrixPalettes :
		{
			uint32 nNumActiveBones = SetMatrixPalette(m_iMinBone,m_iMaxBone,pD3DTransforms);

			// Set the vertex shader constants.
			if (m_pVertexShader != NULL)
			{
				// Let the client set some constants.
				if (NULL != i_client_shell)
				{
					i_client_shell->OnVertexShaderSetConstants(m_pVertexShader, iRenderPass, pRenderStyle, pInstance,
															   LTShaderDeviceStateImp::GetSingleton());
				}

				// Send the constants to the video card.
				LTVertexShaderMgr::GetSingleton().SetVertexShaderConstants(m_pVertexShader);
			}

			// Set the pixel shader constants.
			if (m_pPixelShader != NULL)
			{
				// Let the client set some constants.
				if (NULL != i_client_shell)
				{
					i_client_shell->OnPixelShaderSetConstants(m_pPixelShader, iRenderPass, pRenderStyle, pInstance,
															  LTShaderDeviceStateImp::GetSingleton());
				}

				// Send the constants to the video card.
				LTPixelShaderMgr::GetSingleton().SetPixelShaderConstants(m_pPixelShader);
			}

			RSD3DOptions rsD3DOptions;
			pRenderStyle->GetDirect3D_Options(&rsD3DOptions);
			if(rsD3DOptions.bUseEffectShader)
			{
				LTEffectImpl* _pEffect = (LTEffectImpl*)LTEffectShaderMgr::GetSingleton().GetEffectShader(rsD3DOptions.EffectShaderID);
				ID3DXEffect* pEffect = _pEffect->GetEffect();

				if(pEffect)
				{
					i_client_shell->OnEffectShaderSetParams((LTEffectShader*)_pEffect, pRenderStyle, pInstance, LTShaderDeviceStateImp::GetSingleton());
					pEffect->SetInt("BoneCount", nNumActiveBones);
					pEffect->CommitChanges();
				}

			}

			m_VBController.Render(0,0,m_iVertCount,m_iPolyCount);

			break;
		}
	}
}
Exemplo n.º 13
0
void Evolution::drawEggsFood()
{
    if (!mbEFStart)
    {
        mEFVB->Release();
        mEFIB->Release();
    }

    int Number = 0;
    int FNumber = 0;
    int ENumber = 0;

    const D3DXVECTOR3 baseV[4] = {D3DXVECTOR3(-1.00000f, -1.00000f, 0.0f),
                                  D3DXVECTOR3(-1.00000f,  1.00000f, 0.0f),
                                  D3DXVECTOR3( 1.00000f,  1.00000f, 0.0f),
                                  D3DXVECTOR3( 1.00000f, -1.00000f, 0.0f)
                                 };

    const D3DXVECTOR2 baseT[4] = {D3DXVECTOR2(0.0f, 1.0f),
                                  D3DXVECTOR2(0.0f, 0.0f),
                                  D3DXVECTOR2(1.0f, 0.0f),
                                  D3DXVECTOR2(1.0f, 1.0f)
                                 };


    HR(gd3dDevice->CreateVertexBuffer((foodList.size()+eggList.size()) *4* sizeof(VertexPTEF), D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &mEFVB, 0));
    VertexPTEF * efv = 0;
    HR(mEFVB->Lock(0, 0, (void**)&efv, 0));

    for (std::list<Food>::iterator it = foodList.begin(); it != foodList.end(); ++it)
    {
        D3DXVECTOR3 pos = it->getPosition();
        D3DXMATRIX T, S, F;
        D3DXVECTOR3 V[4];
        D3DXMatrixTranslation(&T, pos.x, pos.y, pos.z);
        D3DXMatrixScaling(&S, 2.0f, 2.0f, 0.0f);
        F = S*(T);

        for (int k=0; k<4; ++k)
            D3DXVec3TransformCoord(&V[k], &baseV[k], &F);

        for (int k=0; k<4; ++k)
            efv[Number+k]   = VertexPTEF( V[k], baseT[k]);

        //*v = iv;
        //++fv;
        Number+=4;
        ++FNumber;
    }

    /*if (eggList.size() != 0)
    {
    HR(gd3dDevice->CreateVertexBuffer(eggList.size() * sizeof(VertexPTEF), D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &mEVB, 0));
    VertexPTEF * ev = 0;
    HR(mEVB->Lock(0, 0, (void**)&ev, 0));*/

    ENumber=FNumber;
    for (std::list<Egg>::iterator it = eggList.begin(); it != eggList.end(); ++it)
    {
        D3DXVECTOR3 pos = it->getPosition();
        D3DXMATRIX T, S, F;
        D3DXVECTOR3 V[4];
        D3DXMatrixTranslation(&T, pos.x, pos.y, pos.z);
        D3DXMatrixScaling(&S, 2.0f, 2.0f, 0.0f);
        F = S*(T);

        for (int k=0; k<4; ++k)
            D3DXVec3TransformCoord(&V[k], &baseV[k], &F);

        for (int k=0; k<4; ++k)
            efv[Number+k]   = VertexPTEF( V[k], baseT[k]);

        //*v = iv;
        //++ev;
        Number+=4;
        ++ENumber;
    }

    HR(mEFVB->Unlock());

    Number = 0;

    HR(gd3dDevice->CreateIndexBuffer((foodList.size()+eggList.size()) *6* sizeof(WORD), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16,	D3DPOOL_MANAGED, &mEFIB, 0));

    WORD* find = 0;
    HR(mEFIB->Lock(0, 0, (void**)&find, 0));

    int k=0;
    int m=0;
    int g=0;
    while (m<FNumber)
    {
        find[k] = g;
        find[k+1] = g+1;
        find[k+2] = g+2;
        find[k+3] = g;
        find[k+4] = g+2;
        find[k+5] = g+3;
        k+=6;
        g+=4;
        ++m;
    }

    int j=k;
    int n=m;
    int h=g;
    while (n<ENumber)
    {
        find[j] = h;
        find[j+1] = h+1;
        find[j+2] = h+2;
        find[j+3] = h;
        find[j+4] = h+2;
        find[j+5] = h+3;
        j+=6;
        h+=4;
        ++n;
    }

    HR(mEFIB->Unlock());

    // Set up the geometry data stream

    HR(mFX->SetTechnique(mhEFTech));
    HR(mFX->SetTexture(mhTex,  mFoodTex));
    HR(gd3dDevice->SetStreamSource(0, mEFVB, 0, sizeof(VertexPTEF)));
    HR(gd3dDevice->SetIndices(mEFIB));
    HR(gd3dDevice->SetVertexDeclaration(VertexPTEF::Decl));

    HR(mFX->SetMatrix(mhWVP, &(mView*mProj)));

    UINT numPasses = 0;
    HR(mFX->Begin(&numPasses, 0));
    for (UINT i=0; i<numPasses; ++i)
    {
        HR(mFX->BeginPass(i));

        if (foodList.size() != 0)
            HR(gd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4*FNumber, 0, 2*FNumber));

        if (eggList.size() != 0)
        {
            HR(mFX->SetTexture(mhTex,  mEggTex));
            HR(mFX->CommitChanges());
            HR(gd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, FNumber*4, 4*(ENumber-FNumber), FNumber*6, 2*(ENumber-FNumber)));
        }
        HR(mFX->EndPass());
    }
    HR(mFX->End());

    if (mbEFStart)
        mbEFStart = false;
}
Exemplo n.º 14
0
void RobotArmDemo::drawScene()
{
	// Clear the backbuffer and depth buffer.
	HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0));

	HR(gd3dDevice->BeginScene());

	HR(mFX->SetValue(mhLight, &mLight, sizeof(DirLight)));
	
	HR(mFX->SetTechnique(mhTech));
	UINT numPasses = 0;
	HR(mFX->Begin(&numPasses, 0));
	HR(mFX->BeginPass(0));

	// Build the world transforms for each bone, then render them.
	buildBoneWorldTransforms();
	D3DXMATRIX T;
	D3DXMatrixTranslation(&T, -NUM_BONES, 0.0f, 0.0f);
	for(int i = 0; i < NUM_BONES; ++i)
	{
		// Append the transformation with a slight translation to better
		// center the skeleton at the center of the scene.
		mWorld = mBones[i].toWorldXForm * T;
		HR(mFX->SetMatrix(mhWVP, &(mWorld*mView*mProj)));
		D3DXMATRIX worldInvTrans;
		D3DXMatrixInverse(&worldInvTrans, 0, &mWorld);
		D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans);
		HR(mFX->SetMatrix(mhWorldInvTrans, &worldInvTrans));
		HR(mFX->SetMatrix(mhWorld, &mWorld));
		for(int j = 0; j < mMtrl.size(); ++j)
		{
			HR(mFX->SetValue(mhMtrl, &mMtrl[j], sizeof(Mtrl)));
		
			// If there is a texture, then use.
			if(mTex[j] != 0)
			{
				HR(mFX->SetTexture(mhTex, mTex[j]));
			}

			// But if not, then set a pure white texture.  When the texture color
			// is multiplied by the color from lighting, it is like multiplying by
			// 1 and won't change the color from lighting.
			else
			{
				HR(mFX->SetTexture(mhTex, mWhiteTex));
			}
		
			HR(mFX->CommitChanges());
			HR(mBoneMesh->DrawSubset(j));
		}
	}

	HR(mFX->EndPass());
	HR(mFX->End());
	
	mGfxStats->display();

	HR(gd3dDevice->EndScene());

	// Present the backbuffer.
	HR(gd3dDevice->Present(0, 0, 0, 0));
}
Exemplo n.º 15
0
void CD3DVAMesh::Render(ModelInstance *pInstance, D3DMATRIX& WorldTransform, CD3DRenderStyle* pRenderStyle, uint32 iRenderPass)
{
	RSD3DOptions rsD3DOptions;
	pRenderStyle->GetDirect3D_Options(&rsD3DOptions);

	// If this pass has a vertex shader, use it.
	RSD3DRenderPass *pPass = pRenderStyle->GetRenderPass_D3DOptions(iRenderPass);
	if (NULL != pPass &&
	    pPass->bUseVertexShader &&
		pPass->VertexShaderID != LTVertexShader::VERTEXSHADER_INVALID)
	{
		if ( m_bSWVSBuffers && !m_bSWVertProcessing )
		{
			m_bSWVertProcessing = true;
			FreeDeviceObjects();
			ReCreateObject();
		}

		// Store the pointer to the actual shader during rendering.
		m_pVertexShader = LTVertexShaderMgr::GetSingleton().GetVertexShader(pPass->VertexShaderID);
		if (m_pVertexShader != NULL)
		{
			// Install the shader.
			if (!LTVertexShaderMgr::GetSingleton().InstallVertexShader(m_pVertexShader))
			{
				m_pVertexShader = NULL;
				return;
			}
		}
	}
	else if (!rsD3DOptions.bUseEffectShader)		
	{
		if (!m_VBController.getVertexFormat(0) || m_bNonFixPipeData)
		{
			// This is a non fixed function pipe VB - bail out...
			return;
		}
		else if(FAILED(g_RenderStateMgr.SetVertexShader(m_VBController.getVertexFormat(0))))
		{
			return;
		}
	}

	// If this pass has a pixel shader, use it.
	if (NULL != pPass &&
	    pPass->bUsePixelShader &&
		pPass->PixelShaderID != LTPixelShader::PIXELSHADER_INVALID)
	{
		// Store the pointer to the actual shader during rendering.
		m_pPixelShader = LTPixelShaderMgr::GetSingleton().GetPixelShader(pPass->PixelShaderID);
		if (m_pPixelShader != NULL)
		{
			// Install the shader.
			if (!LTPixelShaderMgr::GetSingleton().InstallPixelShader(m_pPixelShader))
			{
				m_pPixelShader = NULL;
				return;
			}
		}
	}

	// We need software processing 
	if(m_bSWVertProcessing)
	{
		PD3DDEVICE->SetSoftwareVertexProcessing(TRUE);
	}


	g_RenderStateMgr.SetTransform(D3DTS_WORLDMATRIX(0), &WorldTransform);



	m_VBController.SetStreamSources();

	// Set the vertex shader constants.
	if (m_pVertexShader != NULL)
	{
		// Let the client set some constants.
		if (NULL != i_client_shell)
		{
			i_client_shell->OnVertexShaderSetConstants(m_pVertexShader, iRenderPass, pRenderStyle, pInstance,
													   LTShaderDeviceStateImp::GetSingleton());
		}

		// Send the constants to the video card.
		LTVertexShaderMgr::GetSingleton().SetVertexShaderConstants(m_pVertexShader);
	}

	// Set the pixel shader constants.
	if (m_pPixelShader != NULL)
	{
		// Let the client set some constants.
		if (NULL != i_client_shell)
		{
			i_client_shell->OnPixelShaderSetConstants(m_pPixelShader, iRenderPass, pRenderStyle, pInstance,
													  LTShaderDeviceStateImp::GetSingleton());
		}

		// Send the constants to the video card.
		LTPixelShaderMgr::GetSingleton().SetPixelShaderConstants(m_pPixelShader);
	}

	if(rsD3DOptions.bUseEffectShader)
	{
		LTEffectImpl* _pEffect = (LTEffectImpl*)LTEffectShaderMgr::GetSingleton().GetEffectShader(rsD3DOptions.EffectShaderID);
		ID3DXEffect* pEffect = _pEffect->GetEffect();

		if(pEffect)
		{
			i_client_shell->OnEffectShaderSetParams((LTEffectShader*)_pEffect, pRenderStyle, pInstance, LTShaderDeviceStateImp::GetSingleton());
			pEffect->CommitChanges();
		}
	}

	m_VBController.Render(0,0,m_iVertCount,m_iPolyCount);


	if ( m_bSWVertProcessing )
	{
		// If we are running with hardware then turn back on hardware processing
		if ( (g_Device.GetDeviceCaps()->DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) )
		{
		
			PD3DDEVICE->SetSoftwareVertexProcessing(FALSE);
		}
	}

	PD3DDEVICE->SetStreamSource(0, 0, 0, 0);
	PD3DDEVICE->SetIndices(0);

	// Uninstall the vertex shader.
	if (NULL != m_pVertexShader)
	{
		LTVertexShaderMgr::GetSingleton().UninstallVertexShader();
		m_pVertexShader = NULL;
	}

	// Uninstall the pixel shader.
	if (NULL != m_pPixelShader)
	{
		LTPixelShaderMgr::GetSingleton().UninstallPixelShader();
		m_pPixelShader = NULL;
	}
}