Esempio n. 1
0
void Application::Render() {
    if (!m_deviceLost) {
        try {
            //Create Matrices
            D3DXMATRIX identity, world, view, proj;
            D3DXMatrixIdentity(&identity);
            D3DXMatrixLookAtLH(&view, &D3DXVECTOR3(0.0f, 1.5f, -3.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
            D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI / 4.0f, (float)WINDOW_WIDTH / (float)WINDOW_HEIGHT, 1.0f, 1000.0f);
            D3DXVECTOR4 lightPos(-50.0f, 75.0f, -150.0f, 0.0f);

            g_pDevice->SetTransform(D3DTS_WORLD, &identity);
            g_pDevice->SetTransform(D3DTS_VIEW, &view);
            g_pDevice->SetTransform(D3DTS_PROJECTION, &proj);

            // Clear the viewport
            g_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0L);

            // Begin the scene
            if (SUCCEEDED(g_pDevice->BeginScene())) {
                //Render Drone
                {
                    g_pEffect->SetMatrix("matW", &identity);
                    g_pEffect->SetMatrix("matVP", &(view * proj));
                    g_pEffect->SetVector("lightPos", &lightPos);

                    //Update skeletal animation
                    m_drone.SetPose(identity);

                    //Update IK
                    if (m_pIK) {
                        m_pIK->UpdateHeadIK();
                        m_pIK->UpdateArmIK();
                    }

                    m_drone.Render(NULL);
                }

                // End the scene.
                g_pDevice->EndScene();
                g_pDevice->Present(0, 0, 0, 0);
            }
        }
        catch(...) {
            g_debug << "Error in Application::Render() \n";
        }
    }
}
Esempio 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));
}