Example #1
0
//--------------------------------------------------------------------------------------
// Create any D3D9 resources that won't live through a device reset (D3DPOOL_DEFAULT) 
// or that are tied to the back buffer size 
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D9ResetDevice( IDirect3DDevice9* pd3dDevice,
                                    const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
{
    HRESULT hr;

    V_RETURN( g_DialogResourceManager.OnD3D9ResetDevice() );
    V_RETURN( g_SettingsDlg.OnD3D9ResetDevice() );


    // Setup the camera's projection parameters
	camera->OnResetDevice(pBackBufferSurfaceDesc);


    g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 350, 0 );
    g_HUD.SetSize( 360, 100 );
	g_HUD.GetEditBox(IDC_CMD)->SetLocation(5,pBackBufferSurfaceDesc->Height-30);
	g_HUD.GetStatic(IDC_STATIC7)->SetLocation(5,pBackBufferSurfaceDesc->Height-60);

    g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width - 350, 130 );
	g_SampleUI.SetSize( 350, pBackBufferSurfaceDesc->Height - 130 );

	//clear black part of screen
	clearRect.x1 = pBackBufferSurfaceDesc->Width - 360;
	clearRect.y1 = 0;
	clearRect.x2 = pBackBufferSurfaceDesc->Width;
	clearRect.y2 = pBackBufferSurfaceDesc->Height;

    return S_OK;
}
Example #2
0
//--------------------------------------------------------------------------------------
// Handles the GUI events
//--------------------------------------------------------------------------------------
void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext )
{
	float val;
	wchar_t str[512];
	FILE* file2;
	LPCWSTR ttext;

    switch( nControlID )
    {
		//main menu
        case IDC_TOGGLEFULLSCREEN:
            DXUTToggleFullScreen(); 
			break;
		
		case IDC_SAVEFILE_BTN:

			swprintf(str,L"./%s",g_HUD.GetEditBox( IDC_SAVEFILE )->GetText());
			manipulator->SaveConfig(str);

			break;

		case IDC_NEWFILE_BTN:

			swprintf(str,L"./%s",g_HUD.GetEditBox( IDC_NEWFILE )->GetText());

			file2 = _wfopen(str,L"w+");
			fclose(file2);

			IniWrite(str,L"manipulator",L"chainsize",L"1");

			IniWrite(str,L"chain_0",L"coefficient",L"0.8");
			IniWrite(str,L"chain_0",L"direction",L"1.00");
			IniWrite(str,L"chain_0",L"displace",L"-1.57");
			IniWrite(str,L"chain_0",L"length",L"90.00");
			IniWrite(str,L"chain_0",L"width",L"10.00");
			IniWrite(str,L"chain_0",L"initangle",L"0.00 0.00");
			IniWrite(str,L"chain_0",L"angle_restrict_phi",L"-3.14 3.14");
			IniWrite(str,L"chain_0",L"angle_restrict_theta",L"-3.14 3.14");
			IniWrite(str,L"chain_0",L"parent_index",L"-1");
			IniWrite(str,L"chain_0",L"model",L"");
			IniWrite(str,L"chain_0",L"offset",L"0 0 0");
			IniWrite(str,L"chain_0",L"mass",L"100.00");
			IniWrite(str,L"chain_0",L"tilt",L"0");
			IniWrite(str,L"chain_0",L"pressure",L"0");
			IniWrite(str,L"chain_0",L"laser",L"0");

			manipulator->Release();
			manipulator->Create(DXUTGetD3D9Device(), str);

			MessageBox(0,L"Создана новая конфигурация манипулятора",L"",0);

			OnChainSelect(-1);
			break;

		case IDC_LOADFILE_BTN:

			manipulator->Release();

			swprintf(str,L"./%s",g_HUD.GetEditBox( IDC_LOADFILE )->GetText());
			manipulator->Create(DXUTGetD3D9Device(), str);

			MessageBox(0,L"Манипулятор загружен из файла",L"",0);
			OnChainSelect(-1);
			break;

			
		//dialog menu
		case IDC_ADDCHAIN:
			manipulator->AddChain(DXUTGetD3D9Device());
			break;

		case IDC_REMOVECHAIN:
			manipulator->RemoveChain();
			break;

		case IDC_WIDTH:
			switch( nEvent )
            {
				case EVENT_EDITBOX_STRING:
                {
					float fWidth;
					LPCWSTR text = (( CDXUTEditBox* )pControl )->GetText();
					swscanf(text, L"%f", &fWidth);

					g_SampleUI.GetSlider(IDC_WIDTH_SLIDER)->SetValue(fWidth);

					manipulator->cube[manipulator->selectedChain]->SetWidth(fWidth);
					break;
				}
			}
			break;

		case IDC_WIDTH_SLIDER:

			val = (float)( ( CDXUTSlider* )pControl )->GetValue();
            manipulator->cube[manipulator->selectedChain]->SetWidth(val);

			swprintf(str,L"%.2f",val);
			g_SampleUI.GetEditBox( IDC_WIDTH )->SetText(str);

            break;

		case IDC_LENGTH:
			switch( nEvent )
            {
				case EVENT_EDITBOX_STRING:
                {
					float fLength;
					LPCWSTR text = (( CDXUTEditBox* )pControl )->GetText();
					swscanf(text, L"%f", &fLength);

					g_SampleUI.GetSlider(IDC_LENGTH_SLIDER)->SetValue(fLength);

					manipulator->cube[manipulator->selectedChain]->SetLength(fLength);
					break;
				}
			}
			break;

		case IDC_LENGTH_SLIDER:

			val = (float)( ( CDXUTSlider* )pControl )->GetValue();
            manipulator->cube[manipulator->selectedChain]->SetLength(val);

			swprintf(str,L"%.2f",val);
			g_SampleUI.GetEditBox( IDC_LENGTH )->SetText(str);

            break;

		case IDC_ANGLE_RESTRICT_XL:
		case IDC_ANGLE_RESTRICT_XU:
		case IDC_ANGLE_RESTRICT_YL:
		case IDC_ANGLE_RESTRICT_YU:
		switch( nEvent )
        {
			case EVENT_EDITBOX_STRING:
            {
				LPCWSTR text = (( CDXUTEditBox* )pControl )->GetText();
				swscanf(text, L"%f", &val);

				if(pControl->GetID() == IDC_ANGLE_RESTRICT_XL)
						manipulator->cube[manipulator->selectedChain]->restrictAngleX.x = val;
				else if(pControl->GetID() == IDC_ANGLE_RESTRICT_XU)
						manipulator->cube[manipulator->selectedChain]->restrictAngleX.y = val;
				else if(pControl->GetID() == IDC_ANGLE_RESTRICT_YL)
						manipulator->cube[manipulator->selectedChain]->restrictAngleY.x = val;
				else if(pControl->GetID() == IDC_ANGLE_RESTRICT_YU)
						manipulator->cube[manipulator->selectedChain]->restrictAngleY.y = val;
				break;
			}
		}
		break;

		case IDC_ANGLE_RESTRICT_XL_BTN:
			swprintf(str,L"%.2f", manipulator->cube[manipulator->selectedChain]->vAngle.x);	
			g_SampleUI.GetEditBox( IDC_ANGLE_RESTRICT_XL )->SetText(str);
			manipulator->cube[manipulator->selectedChain]->restrictAngleX.x = manipulator->cube[manipulator->selectedChain]->vAngle.x;
			break;
		case IDC_ANGLE_RESTRICT_XU_BTN:
			swprintf(str,L"%.2f", manipulator->cube[manipulator->selectedChain]->vAngle.x);	
			g_SampleUI.GetEditBox( IDC_ANGLE_RESTRICT_XU )->SetText(str);
			manipulator->cube[manipulator->selectedChain]->restrictAngleX.y = manipulator->cube[manipulator->selectedChain]->vAngle.x;
			break;
		case IDC_ANGLE_RESTRICT_YL_BTN:
			swprintf(str,L"%.2f", manipulator->cube[manipulator->selectedChain]->vAngle.y);	
			g_SampleUI.GetEditBox( IDC_ANGLE_RESTRICT_YL )->SetText(str);
			manipulator->cube[manipulator->selectedChain]->restrictAngleY.x = manipulator->cube[manipulator->selectedChain]->vAngle.y;
			break;
		case IDC_ANGLE_RESTRICT_YU_BTN:
			swprintf(str,L"%.2f", manipulator->cube[manipulator->selectedChain]->vAngle.y);	
			g_SampleUI.GetEditBox( IDC_ANGLE_RESTRICT_YU )->SetText(str);
			manipulator->cube[manipulator->selectedChain]->restrictAngleY.y = manipulator->cube[manipulator->selectedChain]->vAngle.y;
			break;


		case IDC_OFFSET_X:
		case IDC_OFFSET_Y:
		case IDC_OFFSET_Z:
			switch( nEvent )
            {
				case EVENT_EDITBOX_STRING:
                {
					LPCWSTR text = (( CDXUTEditBox* )pControl )->GetText();
					swscanf(text, L"%f", &val);

					if(pControl->GetID() == IDC_OFFSET_X)
						manipulator->cube[manipulator->selectedChain]->vOffset.x = val;
					else if(pControl->GetID() == IDC_OFFSET_Y)
							manipulator->cube[manipulator->selectedChain]->vOffset.y = val;
					else if(pControl->GetID() == IDC_OFFSET_Z)
							manipulator->cube[manipulator->selectedChain]->vOffset.z = val;

					break;
				}
			}
			break;


		case IDC_DISPLACE:
			ttext = (( CDXUTEditBox* )pControl )->GetText();
			swscanf(ttext, L"%f", &val);
			manipulator->cube[manipulator->selectedChain]->fDisplace = val;
			break;

		case IDC_DIRECTION:
			ttext = (( CDXUTEditBox* )pControl )->GetText();
			swscanf(ttext, L"%f", &val);
			manipulator->cube[manipulator->selectedChain]->fDirection = val;
			break;

		case IDC_COEFFICIENT:
			ttext = (( CDXUTEditBox* )pControl )->GetText();
			swscanf(ttext, L"%f", &val);
			manipulator->cube[manipulator->selectedChain]->fCoefficient = val;
			break;

		case IDC_MASS:
			ttext = (( CDXUTEditBox* )pControl )->GetText();
			swscanf(ttext, L"%f", &val);
			manipulator->cube[manipulator->selectedChain]->fMass = val;
			break;

		case IDC_TILT:
			manipulator->cube[manipulator->selectedChain]->bTilt = ((CDXUTCheckBox*)pControl )->GetChecked();
			break;

		case IDC_PRESSURE:
			manipulator->cube[manipulator->selectedChain]->bPressure = ((CDXUTCheckBox*)pControl )->GetChecked();
			break;

		case IDC_LASER:
			manipulator->cube[manipulator->selectedChain]->bLaser = ((CDXUTCheckBox*)pControl )->GetChecked();
			break;


		case IDC_CMD:
			switch( nEvent )
            {
				case EVENT_EDITBOX_STRING:
					ttext = (( CDXUTEditBox* )pControl )->GetText();
					CMDProcess(ttext);
					(( CDXUTEditBox* )pControl )->SetText(L"");
					break;

				case EVENT_EDITBOX_CHANGE:
				break;
			}
			
			break;

    }
}
Example #3
0
//------------------------------------------------------------------------
// Name: OnChainSelect
// Desc: event handler for select one of chains
//------------------------------------------------------------------------
HRESULT OnChainSelect(int iID)
{
	if(iID >= 0)
	{
		wchar_t str[256];
		cprimitive* chain = manipulator->cube[iID];
		
		g_SampleUI.SetVisible(true);

		swprintf(str,L"You picked chain # %d",iID);
		g_SampleUI.GetStatic( IDC_OBJNAME )->SetText(str);

		g_SampleUI.GetSlider(IDC_WIDTH_SLIDER)->SetValue(chain->fWidth);

		swprintf(str,L"%.2f",chain->fWidth);
		g_SampleUI.GetEditBox( IDC_WIDTH )->SetText(str);

		g_SampleUI.GetSlider(IDC_LENGTH_SLIDER)->SetValue(chain->fLength);

		swprintf(str,L"%.2f",chain->fLength);
		g_SampleUI.GetEditBox( IDC_LENGTH )->SetText(str);

		swprintf(str,L"%.2f",chain->restrictAngleX.x);
		g_SampleUI.GetEditBox( IDC_ANGLE_RESTRICT_XL )->SetText(str);
		swprintf(str,L"%.2f",chain->restrictAngleX.y);
		g_SampleUI.GetEditBox( IDC_ANGLE_RESTRICT_XU )->SetText(str);
		swprintf(str,L"%.2f",chain->restrictAngleY.x);
		g_SampleUI.GetEditBox( IDC_ANGLE_RESTRICT_YL )->SetText(str);
		swprintf(str,L"%.2f",chain->restrictAngleY.y);
		g_SampleUI.GetEditBox( IDC_ANGLE_RESTRICT_YU )->SetText(str);

		swprintf(str,L"%.2f",chain->vOffset.x);
		g_SampleUI.GetEditBox( IDC_OFFSET_X )->SetText(str);
		swprintf(str,L"%.2f",chain->vOffset.y);
		g_SampleUI.GetEditBox( IDC_OFFSET_Y )->SetText(str);
		swprintf(str,L"%.2f",chain->vOffset.z);
		g_SampleUI.GetEditBox( IDC_OFFSET_Z )->SetText(str);

		swprintf(str,L"%.2f",chain->fDisplace);
		g_SampleUI.GetEditBox( IDC_DISPLACE )->SetText(str);
		swprintf(str,L"%.2f",chain->fDirection);
		g_SampleUI.GetEditBox( IDC_DIRECTION )->SetText(str);
		swprintf(str,L"%.2f",chain->fCoefficient);
		g_SampleUI.GetEditBox( IDC_COEFFICIENT )->SetText(str);
		swprintf(str,L"%.2f",chain->fMass);
		g_SampleUI.GetEditBox( IDC_MASS )->SetText(str);

		g_SampleUI.GetCheckBox( IDC_TILT )->SetChecked(chain->bTilt);
		g_SampleUI.GetCheckBox( IDC_PRESSURE )->SetChecked(chain->bPressure);
		g_SampleUI.GetCheckBox( IDC_LASER )->SetChecked(chain->bLaser);


		swprintf(str,L"X: %.2f",chain->vAngle.x);
		g_SampleUI.GetStatic( IDC_STATIC7 )->SetText(str);
		swprintf(str,L"Y: %.2f",chain->vAngle.y);
		g_SampleUI.GetStatic( IDC_STATIC8 )->SetText(str);
	}
	else
	{
		g_SampleUI.SetVisible(false);
	}

	return S_OK;
}