예제 #1
0
void Application::Render() {
    if (!m_deviceLost) {
        try {
            //Create Matrices
            D3DXMATRIX identity, view, proj, shadow;
            D3DXMatrixIdentity(&identity);
            D3DXMatrixLookAtLH(&view, &D3DXVECTOR3(cos(m_time) * m_radius, m_height, sin(m_time) * m_radius), &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);
            D3DXPLANE ground(0.0f, 1.0f, 0.0f, 0.0f);
            D3DXVECTOR4 lightPos(-50.0f, 75.0f, -150.0f, 0.0f); // 点光源, 光照计算在 shader 中
            D3DXMatrixShadow(&shadow, &lightPos, &ground);

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

            // Clear the viewport
            g_pDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0xff, 0x40, 0x40, 0x40), 1.0f, 0);

            // 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);

                    m_drone.Render(NULL);
                }

                if (KeyDown(VK_SPACE)) {
                    g_pDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0xff, 0x40, 0x40, 0x40), 1.0f, 0);
                    m_drone.RenderSkeleton(NULL, NULL, identity);
                }

                RECT rc = {10, 10, 0, 0};
                g_pFont->DrawText(NULL, "Press Space to Toggle Skeleton", -1, &rc, DT_LEFT | DT_TOP | DT_NOCLIP, D3DCOLOR_ARGB(0xff, 0, 0x80, 0));

                // End the scene.
                g_pDevice->EndScene();
                g_pDevice->Present(0, 0, 0, 0);
            }
        }
        catch(...) {
            g_debug << "Error in Application::Render() \n";
        }
    }
}
예제 #2
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";
        }
    }
}
예제 #3
0
void Render( unsigned int _dt )
{
    //DebugPrintf("Frame count: %d\n", FrameCount);
    HRESULT hr = S_OK;

    //清除视区
    pGDevice->Clear();

    //开始场景
    pGDevice->BeginScene();

    //Render skinmesh
    skinMesh.Render(pGDevice->m_pD3DDevice, identity, view, proj, eyePoint);

    //Render cube
    {
        pGDevice->SetViewport(pGDevice->mCubeViewport);
        cube.SetConstants(pGDevice->m_pD3DDevice, identity, fixedView, pGDevice->m_matCubeProj);
        cube.Draw(pGDevice->m_pD3DDevice);
        if (hovering || moving)
        {
            //将cube所在的viewport的位置(top-left)处的屏幕坐标变换到(0,0)
            D3DXVECTOR2 tmp(currentCursorPos);
            tmp.x -= pGDevice->mCubeViewport.X;
            tmp.y -= pGDevice->mCubeViewport.Y;
            cube.DrawRay(tmp, identity, fixedView, pGDevice->m_matCubeProj);
        }
        pGDevice->ResetViewport();
    }

    //Render axis
    {
        pGDevice->SetViewport(pGDevice->mAxisViewport);
        axis.SetConstants(pGDevice->m_pD3DDevice, identity, fixedView, pGDevice->m_matAxisProj);
        axis.Draw(pGDevice->m_pD3DDevice);
        //axis.DrawXYZ();
        pGDevice->ResetViewport();
	}

    //结束场景
    pGDevice->EndScene();

    //显示场景
    pGDevice->Present();
}