Exemplo n.º 1
0
void TriPickDemo::onResetDevice()
{
	HR(m_FX->OnResetDevice());
	HR(m_pCharacter->GetEffect()->OnResetDevice());
	//Aspect ratio rely on the size of back buffer 
	//Back buffer will change when user change window size, so we need to reset project matrix.
	float w = (float)md3dPP.BackBufferWidth;
	float h = (float)md3dPP.BackBufferHeight;

	g_Camera->setLens(D3DX_PI * 0.25f, w / h, 0.1f, 1000.0f);

}
Exemplo n.º 2
0
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));
}
Exemplo n.º 3
0
void TriPickDemo::onLostDevice()
{
	HR(m_FX->OnLostDevice());
	HR(m_pCharacter->GetEffect()->OnLostDevice());
}