示例#1
0
void RenderArrows(float fElapsedTime)
{
    WCHAR strWhite[MAX_PATH] = {26};
    WCHAR strBlack[MAX_PATH] = {27};
    CDXUTStatic* pStatic = NULL;

    pStatic = g_WhiteArrowDialog.GetStatic(IDC_WHITESCORE);
    if(pStatic != NULL)
    {
        pStatic->SetText(strWhite);
    }

    pStatic = g_BlackArrowDialog.GetStatic(IDC_BLACKSCORE);
    if(pStatic != NULL)
    {
        pStatic->SetText(strBlack);
    }

	if(!g_Board.pRenjuGame->bGameIsFinished)
	{
		if(g_Board.pRenjuGame->activeColor == White)
		{
			g_WhiteArrowDialog.OnRender(fElapsedTime);
		}
		if(g_Board.pRenjuGame->activeColor == Black)
		{
			g_BlackArrowDialog.OnRender(fElapsedTime);
		}
	}
}
示例#2
0
void RenderWinner(float fElapsedTime)
{
	if(g_Board.pRenjuGame->winner == Black)
	{
		WCHAR strMessage[MAX_PATH] = L"The Black have won!";
		CDXUTStatic* pStatic = NULL;
		CDXUTElement* pElement = NULL;

		pStatic = g_TheBlackWinnerDialog.GetStatic(IDC_THE_BLACK_WINNER_DIALOG);
		if(pStatic != NULL)
		{
			pStatic->SetText(strMessage);
		}
	        
		pElement = g_TheBlackWinnerDialog.GetDefaultElement(DXUT_CONTROL_STATIC, 0);
		pElement->FontColor.Init(D3DCOLOR_ARGB(255, 255, 255, 255));
		
		g_TheBlackWinnerDialog.OnRender(fElapsedTime);
	}
	else
	{
		if(g_Board.pRenjuGame->winner == White)
		{
			WCHAR strMessage[MAX_PATH] = L"The White have won!";
			CDXUTStatic* pStatic = NULL;
			CDXUTElement* pElement = NULL;

			pStatic = g_TheWhiteWinnerDialog.GetStatic(IDC_THE_WHITE_WINNER_DIALOG);
			if(pStatic != NULL)
			{
				pStatic->SetText(strMessage);
			}
		        
			pElement = g_TheWhiteWinnerDialog.GetDefaultElement(DXUT_CONTROL_STATIC, 0);
			pElement->FontColor.Init(D3DCOLOR_ARGB(255, 0, 0, 0));
			
			g_TheWhiteWinnerDialog.OnRender(fElapsedTime);
		}
	}
}
//--------------------------------------------------------------------------------------
// Handles the GUI events
//--------------------------------------------------------------------------------------
void CALLBACK OnGUIEvent(UINT nEvent, INT nControlID, CDXUTControl* /*pControl*/, void* /*pUserContext*/)
{
    switch (nControlID)
    {
    case IDC_TOGGLEFULLSCREEN:
        DXUTToggleFullScreen(); break;
    case IDC_TOGGLEWARP:
        DXUTToggleWARP(); break;
    case IDC_CHANGEDEVICE:
        g_D3DSettingsDlg.SetActive(!g_D3DSettingsDlg.IsActive()); break;
        break;
        break;
    case IDC_FIT_TO_CASCADE:
        g_CascadedShadow.m_eSelectedCascadesFit =
            (FIT_PROJECTION_TO_CASCADES)PtrToUlong(g_FitToCascadesCombo->GetSelectedData());
        break;
    case IDC_FIT_TO_NEARFAR:
    {
        g_CascadedShadow.m_eSelectedNearFarFit =
            (FIT_TO_NEAR_FAR)PtrToUlong(g_FitToNearFarCombo->GetSelectedData());
        if (g_CascadedShadow.m_eSelectedNearFarFit == FIT_NEARFAR_PANCAKING)
        {
            g_CascadedShadow.m_eSelectedCascadeSelection = CASCADE_SELECTION_INTERVAL;
            g_CascadeSelectionCombo->SetSelectedByData(ULongToPtr(CASCADE_SELECTION_INTERVAL));
        }
    }
    break;
    case IDC_CASCADE_SELECT:
    {
        static int iSaveLastCascadeValue = 100;
        if ((CASCADE_SELECTION)PtrToUlong(g_CascadeSelectionCombo->GetSelectedData()) == CASCADE_SELECTION_MAP)
        {
            if ((FIT_TO_NEAR_FAR)PtrToUlong(g_FitToNearFarCombo->GetSelectedData()) == FIT_NEARFAR_PANCAKING)
            {
                g_FitToNearFarCombo->SetSelectedByData(ULongToPtr(FIT_NEARFAR_SCENE_AABB));
                g_CascadedShadow.m_eSelectedNearFarFit = FIT_NEARFAR_SCENE_AABB;
            }
            g_CascadedShadow.m_iCascadePartitionsZeroToOne[g_CascadeConfig.m_nCascadeLevels - 1] = iSaveLastCascadeValue;
        }
        else
        {
            iSaveLastCascadeValue = g_CascadedShadow.m_iCascadePartitionsZeroToOne[g_CascadeConfig.m_nCascadeLevels - 1];
            g_CascadedShadow.m_iCascadePartitionsZeroToOne[g_CascadeConfig.m_nCascadeLevels - 1] = 100;
        }
        g_CascadedShadow.m_eSelectedCascadeSelection =
            (CASCADE_SELECTION)PtrToUlong(g_CascadeSelectionCombo->GetSelectedData());

        g_HUD.GetSlider(IDC_CASCADELEVEL1 + g_CascadeConfig.m_nCascadeLevels - 1)->SetValue(
            g_CascadedShadow.m_iCascadePartitionsZeroToOne[g_CascadeConfig.m_nCascadeLevels - 1]);
        WCHAR label[16];
        swprintf_s(label, L"L%d: %d", g_CascadeConfig.m_nCascadeLevels,
            g_CascadedShadow.m_iCascadePartitionsZeroToOne[g_CascadeConfig.m_nCascadeLevels - 1]);
        g_HUD.GetStatic(IDC_CASCADELEVEL1TEXT + g_CascadeConfig.m_nCascadeLevels - 1)->SetText(label);

    }
    break;
    case IDC_MOVE_LIGHT_IN_TEXEL_INC:
        g_bMoveLightTexelSize = !g_bMoveLightTexelSize;
        g_CascadedShadow.m_bMoveLightTexelSize = g_bMoveLightTexelSize;
        break;

    case IDC_TOGGLEVISUALIZECASCADES:
        g_bVisualizeCascades = !g_bVisualizeCascades;
        break;

    case IDC_PCF_SIZE:
    {
        INT PCFSize = g_HUD.GetSlider(IDC_PCF_SIZE)->GetValue();
        PCFSize *= 2;
        PCFSize -= 1;
        WCHAR desc[256];
        swprintf_s(desc, L"PCF Blur: %d ", PCFSize);
        g_HUD.GetStatic(IDC_PCF_SIZETEXT)->SetText(desc);
        g_CascadedShadow.m_iPCFBlurSize = PCFSize;
    }
    break;
    case IDC_PCF_OFFSET_SIZE:
    {
        INT offset = g_HUD.GetSlider(IDC_PCF_OFFSET_SIZE)->GetValue();
        FLOAT useoffset = (FLOAT)offset * 0.001f;
        WCHAR desc[256];
        swprintf_s(desc, L" Offset: %0.03f", useoffset);
        g_HUD.GetStatic(IDC_PCF_OFFSET_SIZETEXT)->SetText(desc);
        g_CascadedShadow.m_fPCFOffset = useoffset;
    }
    break;

    case IDC_BLEND_BETWEEN_MAPS_CHECK:
        if (g_HUD.GetCheckBox(IDC_BLEND_BETWEEN_MAPS_CHECK)->GetChecked())
            g_CascadedShadow.m_iBlurBetweenCascades = 1;
        else
            g_CascadedShadow.m_iBlurBetweenCascades = 0;
        break;

    case IDC_BLEND_MAPS_SLIDER:
    {
        INT val = g_HUD.GetSlider(IDC_BLEND_MAPS_SLIDER)->GetValue();
        g_CascadedShadow.m_fBlurBetweenCascadesAmount = (float)val * 0.005f;
        WCHAR dta[256];
        swprintf_s(dta, L"Cascade Blur %0.03f", g_CascadedShadow.m_fBlurBetweenCascadesAmount);
        g_HUD.GetCheckBox(IDC_BLEND_BETWEEN_MAPS_CHECK)->SetText(dta);
    }
    break;

    case IDC_TOGGLE_DERIVATIVE_OFFSET:
    {
        if (g_CascadedShadow.m_iDerivativeBasedOffset == 0)
            g_CascadedShadow.m_iDerivativeBasedOffset = 1;
        else
            g_CascadedShadow.m_iDerivativeBasedOffset = 0;

    }
    break;
    case IDC_BUFFER_SIZE:
    {
        INT value = 32 * g_HUD.GetSlider(IDC_BUFFER_SIZE)->GetValue();
        INT max = 8192 / g_CascadeConfig.m_nCascadeLevels;
        if (value > max)
        {
            value = max;
            g_HUD.GetSlider(IDC_BUFFER_SIZE)->SetValue(value / 32);
        }
        WCHAR desc[256];
        swprintf_s(desc, L"Texture Size: %d ", value);
        g_HUD.GetStatic(IDC_BUFFER_SIZETEXT)->SetText(desc);

        //Only tell the app to recreate buffers once the user is through moving the slider. 
        if (nEvent == EVENT_SLIDER_VALUE_CHANGED_UP)
        {
            g_CascadeConfig.m_iBufferSize = value;
        }
    }
    break;
    case IDC_SELECTED_SCENE:
    {
        SCENE_SELECTION ss = (SCENE_SELECTION)PtrToUlong(g_SceneSelectCombo->GetSelectedData());
        if (ss == POWER_PLANT_SCENE)
        {
            g_pSelectedMesh = &g_MeshPowerPlant;
        }
        else if (ss == TEST_SCENE)
        {
            g_pSelectedMesh = &g_MeshTestScene;
        }
        DestroyD3DComponents();
        CreateD3DComponents(DXUTGetD3D11Device());
        UpdateViewerCameraNearFar();
    }
    case IDC_SELECTED_CAMERA:
    {
        g_CascadedShadow.m_eSelectedCamera = (CAMERA_SELECTION)
            (g_CameraSelectCombo->GetSelectedIndex());

        if (g_CascadedShadow.m_eSelectedCamera < 1)
        {
            g_pActiveCamera = &g_ViewerCamera;
        }
        else
        {
            g_pActiveCamera = &g_LightCamera;
        }
    }
    break;
    case IDC_CASCADELEVELS:
    {
        INT ind = 1 + g_CascadeLevelsCombo->GetSelectedIndex();
        g_CascadeConfig.m_nCascadeLevels = ind;
        for (INT index = 0; index < ind; ++index)
        {
            g_HUD.GetStatic(IDC_CASCADELEVEL1TEXT + index)->SetVisible(true);
            g_HUD.GetSlider(IDC_CASCADELEVEL1 + index)->SetVisible(true);
        }
        for (int index = ind; index < MAX_CASCADES; ++index)
        {
            g_HUD.GetStatic(IDC_CASCADELEVEL1TEXT + index)->SetVisible(false);
            g_HUD.GetSlider(IDC_CASCADELEVEL1 + index)->SetVisible(false);
        }
        INT value = 32 * g_HUD.GetSlider(IDC_BUFFER_SIZE)->GetValue();
        INT max = 8192 / g_CascadeConfig.m_nCascadeLevels;
        if (value > max)
        {
            WCHAR desc[256];
            value = max;

            swprintf_s(desc, L"Texture Size: %d ", value);
            g_HUD.GetStatic(IDC_BUFFER_SIZETEXT)->SetText(desc);
            g_HUD.GetSlider(IDC_BUFFER_SIZE)->SetValue(value / 32);
            g_CascadeConfig.m_iBufferSize = value;
        }

        // update the selected camera based on these changes.
        INT selected = g_CameraSelectCombo->GetSelectedIndex();
        WCHAR dta[60];
        g_CameraSelectCombo->RemoveAllItems();
        swprintf_s(dta, L"Eye Camera %ld", EYE_CAMERA + 1);
        g_CameraSelectCombo->AddItem(dta, ULongToPtr(EYE_CAMERA));
        swprintf_s(dta, L"Light Camera %ld", LIGHT_CAMERA + 1);
        g_CameraSelectCombo->AddItem(dta, ULongToPtr(LIGHT_CAMERA));
        for (int index = 0; index < g_CascadeConfig.m_nCascadeLevels; ++index)
        {
            swprintf_s(dta, L"Cascade Cam %d", index + 1);
            g_CameraSelectCombo->AddItem(dta, ULongToPtr(ORTHO_CAMERA1 + index));
        }
        if (selected - 1 >= ind)
        {
            selected = ind + 1;
        }
        g_CameraSelectCombo->SetSelectedByIndex(selected);

        g_CascadedShadow.m_eSelectedCamera = (CAMERA_SELECTION)
            (g_CameraSelectCombo->GetSelectedIndex());

        if (g_CascadedShadow.m_eSelectedCamera < 1)
        {
            g_pActiveCamera = &g_ViewerCamera;
        }
        else
        {
            g_pActiveCamera = &g_LightCamera;
        }
    }
    break;
    case IDC_DEPTHBUFFERFORMAT:
    {
        SHADOW_TEXTURE_FORMAT sbt = (SHADOW_TEXTURE_FORMAT)PtrToUlong(g_DepthBufferFormatCombo->GetSelectedData());
        g_CascadeConfig.m_ShadowBufferFormat = sbt;
    }
    break;
    case IDC_CASCADELEVEL1:
    case IDC_CASCADELEVEL2:
    case IDC_CASCADELEVEL3:
    case IDC_CASCADELEVEL4:
    case IDC_CASCADELEVEL5:
    case IDC_CASCADELEVEL6:
    case IDC_CASCADELEVEL7:
    case IDC_CASCADELEVEL8:
    {
        INT ind = nControlID - IDC_CASCADELEVEL1;
        INT move = g_HUD.GetSlider(nControlID)->GetValue();
        CDXUTSlider* selecteSlider;
        CDXUTStatic* selectedStatic;
        WCHAR label[16];
        for (int index = 0; index < ind; ++index)
        {
            selecteSlider = g_HUD.GetSlider(IDC_CASCADELEVEL1 + index);
            INT sVal = selecteSlider->GetValue();
            if (move < sVal)
            {
                selecteSlider->SetValue(move);
                selectedStatic = g_HUD.GetStatic(IDC_CASCADELEVEL1TEXT + index);
                swprintf_s(label, L"L%d: %d", index + 1, move);
                selectedStatic->SetText(label);
                g_CascadedShadow.m_iCascadePartitionsZeroToOne[index] = move;
            }
        }
        for (int index = ind; index < MAX_CASCADES; ++index)
        {
            selecteSlider = g_HUD.GetSlider(IDC_CASCADELEVEL1 + index);
            INT sVal = selecteSlider->GetValue();
            if (move >= sVal)
            {
                selecteSlider->SetValue(move);
                selectedStatic = g_HUD.GetStatic(IDC_CASCADELEVEL1TEXT + index);
                swprintf_s(label, L"L%d: %d", index + 1, move);
                selectedStatic->SetText(label);
                g_CascadedShadow.m_iCascadePartitionsZeroToOne[index] = move;
            }
        }


    }
    break;
    }

}