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


C++ Drawable::get3D方法代码示例

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


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

示例1: getInfo

void Engine::Graphics::render(Drawable object, Camera *cam)
{
	D3DXMATRIX transMat, scaleMat, rotMat, worldMat;

	D3DXMatrixIdentity(&transMat);
	D3DXMatrixIdentity(&scaleMat);
	D3DXMatrixIdentity(&rotMat);
	D3DXMatrixIdentity(&worldMat);


	if(!object.get3D())
	{
		D3DXMatrixScaling(&scaleMat, object.getScale().x, object.getScale().y, object.getScale().z);
		D3DXMatrixTranslation(&transMat, object.getTranslate().x, object.getTranslate().y, object.getTranslate().z);
		D3DXMatrixRotationYawPitchRoll(&rotMat, D3DXToRadian(object.getRotate().y),D3DXToRadian(object.getRotate().x), D3DXToRadian(object.getRotate().z));
		D3DXMatrixMultiply(&scaleMat, &scaleMat, &rotMat);
		D3DXMatrixMultiply(&worldMat, &scaleMat, &transMat);

		Engine::DX::instance()->getSprite()->SetTransform(&worldMat);

		Engine::DX::instance()->getSprite()->Draw(
			getTexture(object.getHandle()),
			object.getIsSpriteSheet() ? &object.getRect() : 0,
			object.getIsSpriteSheet() ? &dVec3(object.getWidth() * 0.5f, object.getHeight() * 0.5f, 0.0f) : &dVec3(getInfo(object.getHandle()).Width *0.5f, getInfo(object.getHandle()).Height *0.5f, 0.0f),
			0,
			object.getColor());
	}

	if(object.get3D())
	{
		//camera.setLookAt(object.getTranslate().x, object.getTranslate().y, object.getTranslate().z);
		//camera.setProj(800,600);

		D3DXMATRIX WIT;		

		UINT numPasses = 0;
		m_Effect->Begin(&numPasses, 0);

		Mesh *tempMesh = getMesh(object.getHandle());
		 

		for(UINT i = 0; i < numPasses; i++)
		{
			m_Effect->BeginPass(i);

			D3DXMatrixScaling(&scaleMat, object.getScale().x, object.getScale().y, object.getScale().z);
			D3DXMatrixTranslation(&transMat, object.getTranslate().x, object.getTranslate().y, object.getTranslate().z);
			D3DXMatrixRotationYawPitchRoll(&rotMat, D3DXToRadian(object.getRotate().y),D3DXToRadian(object.getRotate().x), D3DXToRadian(object.getRotate().z));
			D3DXMatrixMultiply(&scaleMat, &scaleMat, &rotMat);
			D3DXMatrixMultiply(&worldMat, &scaleMat, &transMat);

			D3DXMatrixInverse(&WIT, 0, &worldMat);
			D3DXMatrixTranspose(&WIT, &WIT);
			m_Effect->SetMatrix("worldViewProjMat", &(worldMat * cam->getView() * cam->getProjection()));
			m_Effect->SetMatrix("worldInverseTransposeMat", &WIT);
			m_Effect->SetMatrix("worldMat", &worldMat);

			for(DWORD i = 0; i < tempMesh->getNumMaterials(); i++)
			{
				m_Effect->SetValue("ambientMaterial", &tempMesh->getMeshMaterial()[i].Ambient, sizeof(D3DXCOLOR));
				m_Effect->SetValue("diffuseMaterial", &tempMesh->getMeshMaterial()[i].Diffuse, sizeof(D3DXCOLOR));
				m_Effect->SetValue("specularMaterial", &tempMesh->getMeshMaterial()[i].Specular, sizeof(D3DXCOLOR));
				m_Effect->SetFloat("specularPower", tempMesh->getMeshMaterial()[i].Power);
				
				if(object.getHasTexture())
				{
					m_Effect->SetTexture("tex", tempMesh->getMeshTexture()[i]);
					m_Effect->SetBool("isTex", true);
				}else
					m_Effect->SetBool("isTex", false);

				m_Effect->CommitChanges();
				tempMesh->getMesh()->DrawSubset(i);
			}

			m_Effect->EndPass();

			//tempMesh = nullptr;
		}
		m_Effect->End();
	}
}
开发者ID:s-chang,项目名称:Final,代码行数:82,代码来源:Graphics.cpp


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