⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 geneditpreviewdlg.cpp

📁 3D游戏场景编辑器
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		{
			AfxMessageBox(sDriverFindError);
			weScrewedUp = true;
		}// if(Driver...
	}
	
	while (Driver != NULL)
	{
		geDriver_GetName(Driver, &drvname);
		if (strstr(drvname, m_DriverName) != NULL) break;
		
		Driver = geDriver_SystemGetNextDriver(DrvSys, Driver);
		
		if (!Driver && !strcmp(m_DriverName, "Glide"))
		{
			AfxMessageBox("Glide not available on this system. Please choose Software or Direct 3D");
			weScrewedUp = true;
			//			return GE_FALSE;
		}
		
		if (!Driver && !strcmp(m_DriverName, "D3D"))
		{
			AfxMessageBox("Direct3D not available on this system. Please choose Software or Glide");
			weScrewedUp = true;
			//			return GE_FALSE;
		}
		
		if (!Driver)
		{
			AfxMessageBox("Cannot find the specified driver");
			weScrewedUp = true;		
			//			return GE_FALSE;
		}	
	}	//	while(Driver...
	
	
	if (weScrewedUp)
	{
		return GE_FALSE;
	}
	
	if (Mode == NULL)
	{	
		Mode = geDriver_GetNextMode(Driver, NULL);
		while (Mode != NULL)
		{
			geDriver_ModeGetWidthHeight(Mode, &tempwidth, &tempheight);
			if ((tempwidth == Width) && (tempheight == Height) ||	//	specced res
				(tempwidth == -1) && (tempheight == -1))			//	for software
				break;//	return TRUE;
			
			Mode = geDriver_GetNextMode(Driver, Mode);
		};	//	while (DriverMode...
		
	}
	geEngine_EnableFrameRateCounter(Engine, GE_FALSE);
	ShowCursor(FALSE);	
	
	if (!geEngine_SetDriverAndMode(Engine, Driver, Mode))		//	post 0.55
	{
		AfxMessageBox("Could not start the engine!\nDriver or Mode Problems");
		return GE_FALSE;
	}

	ShowWindow(SW_SHOWNORMAL);
	
	return GE_TRUE;
}




geBoolean CGenEditPreviewDlg::LoadLevel(char *FileName)
{
	geVFile			*Level;

	Level = geVFile_OpenNewSystem(NULL, GE_VFILE_TYPE_DOS, FileName, 
		NULL, GE_VFILE_OPEN_READONLY);
	
	if (!Level)
	{
		AfxMessageBox( "Could not load file!");
		return GE_FALSE;
	}

	World = geWorld_Create(Level);
	if (!World)
	{
		AfxMessageBox( "Could not create world!");
		return GE_FALSE;
	}

	if (!geEngine_AddWorld(Engine, World))
	{
		AfxMessageBox( "Could not add world to engine!");
		return GE_FALSE;
	}

	return GE_TRUE;
}

				//	post 0.55
void CGenEditPreviewDlg::Shutdown()
{
	if (World != NULL)
	{
		if (!geEngine_RemoveWorld(Engine, World))
		{
			AfxMessageBox("Failed to Remove World");
		}
		geWorld_Free(World);
	}

	if (Camera != NULL)
		geCamera_Destroy(&Camera);

	if (SoundSys != NULL)
		geSound_DestroySoundSystem(SoundSys);


	if (Engine != NULL)
	{
		if (!geEngine_ShutdownDriver(Engine))
		{
			AfxMessageBox("Failed to Shutdown Driver");
		}

		if (!geEngine_UpdateWindow(Engine))
		{
			AfxMessageBox("Failed to Update Window following Diver Shutdown");
		}
		
		geEngine_Free(Engine);
	}
	
	World = NULL;
	Engine = NULL;
	SoundSys = NULL;
	DrvSys = NULL;
	Camera = NULL;
	Driver = NULL;
	Mode = NULL;

	UnloadDirectInput();
	ShowCursor(TRUE);

}


				//	post 0.55
void CGenEditPreviewDlg::DisableDlgControls()
{
					//	if everything checks out, then disable all of the dialog
					//	components so we don't get that incessant dinging during
					//	our viewing session
	m_previewWithEngineBtn.EnableWindow(FALSE);

	m_softwareRadioBtn->EnableWindow(FALSE);
	m_direct3dRadioBtn->EnableWindow(FALSE);
	m_glideRadioBtn->EnableWindow(FALSE);

	m_640RadioBtn->EnableWindow(FALSE);

	if (m_softwareRadioBtn->GetCheck() == 0)
	{
		m_800RadioBtn->EnableWindow(FALSE);
		m_1024RadioBtn->EnableWindow(FALSE);
	}

	m_collideRadioBtn->EnableWindow(FALSE);
	m_noCollideRadioBtn->EnableWindow(FALSE);

	m_zeroCameraBtn.EnableWindow(FALSE);

	GetDlgItem(IDC_CAMERA_X)->EnableWindow(FALSE);
	GetDlgItem(IDC_CAMERA_Y)->EnableWindow(FALSE);
	GetDlgItem(IDC_CAMERA_Z)->EnableWindow(FALSE);

	GetDlgItem(IDC_CAMERA_SLIDERX)->EnableWindow(FALSE);
	GetDlgItem(IDC_CAMERA_SLIDERY)->EnableWindow(FALSE);
	GetDlgItem(IDC_CAMERA_SLIDERX)->EnableWindow(FALSE);

	GetDlgItem(IDC_PREVIEW_LIST)->EnableWindow(FALSE);
	GetDlgItem(IDC_PREVIEW_BROWSE_BTN)->EnableWindow(FALSE);

	GetDlgItem(IDOK)->EnableWindow(FALSE);
}

				//	post 0.55
void CGenEditPreviewDlg::EnableDlgControls()
{
					//	enable all previously-disabled dialog box items
	m_previewWithEngineBtn.EnableWindow(TRUE);

	m_softwareRadioBtn->EnableWindow(TRUE);
	m_direct3dRadioBtn->EnableWindow(TRUE);
	m_glideRadioBtn->EnableWindow(TRUE);

	m_640RadioBtn->EnableWindow(TRUE);
					//	if not software, then enable higher resoultions
	if (m_softwareRadioBtn->GetCheck() == 0)
	{
		m_800RadioBtn->EnableWindow(TRUE);
		m_1024RadioBtn->EnableWindow(TRUE);
	}

	m_collideRadioBtn->EnableWindow(TRUE);
	m_noCollideRadioBtn->EnableWindow(TRUE);

	m_zeroCameraBtn.EnableWindow(TRUE);

	GetDlgItem(IDC_CAMERA_X)->EnableWindow(TRUE);
	GetDlgItem(IDC_CAMERA_Y)->EnableWindow(TRUE);
	GetDlgItem(IDC_CAMERA_Z)->EnableWindow(TRUE);

	GetDlgItem(IDC_CAMERA_SLIDERX)->EnableWindow(TRUE);
	GetDlgItem(IDC_CAMERA_SLIDERY)->EnableWindow(TRUE);
	GetDlgItem(IDC_CAMERA_SLIDERX)->EnableWindow(TRUE);

	GetDlgItem(IDC_PREVIEW_LIST)->EnableWindow(TRUE);
	GetDlgItem(IDC_PREVIEW_BROWSE_BTN)->EnableWindow(TRUE);

	GetDlgItem(IDOK)->EnableWindow(TRUE);
}

								//	post 0.55
void CGenEditPreviewDlg::RestoreDialogBox()
{
	if (m_DriverName ==  _T("Glide"))
	{
		this->ClientToScreen(m_restoreRect);
		SetWindowPos(&wndTopMost, m_restoreRect.left, m_restoreRect.top, 
		m_restoreRect.right, m_restoreRect.bottom, SWP_SHOWWINDOW);
	}

	CenterWindow();
					//	once out of the loop, redraw the dialog box controls
	RedrawWindow();
	EnableDlgControls();	//	post 0.55
}



void CGenEditPreviewDlg::OnShowPreviewBtn() 
{
					//	get the current Rect of this dialog box
	GetClientRect(m_previewRect);

					//	if the Software driver is selected, then rendering will
					//	be in the window defined by this dialog box
	if (m_DriverName ==  _T("Software"))
	{
		Rect.Left = m_previewRect.left;
		Rect.Right = m_previewRect.right - 1;
		Rect.Top = m_previewRect.top;
		Rect.Bottom = m_previewRect.bottom - 1;
	}
	else			//	otherwise, it will be full screen
	{
		Rect.Left = 0;
		Rect.Right = Width - 1;
		Rect.Top = 0;
		Rect.Bottom = Height - 1;
	}
					//	initialize direct input and link it to this window
	if(!InitInput(AfxGetApp()->m_hInstance, this->m_hWnd, 0))	//	post 0.55
	{
		AfxMessageBox("Failed to initialize DirectInput");
		Shutdown();
		RestoreDialogBox();
		return;
	}
					// initialize thew Genesis3D engine and link it to this window
	if (!InitEngine(this->m_hWnd))		//	post 0.55
	{
		AfxMessageBox("Failed to initialize Engine");
		Shutdown();
		RestoreDialogBox();
		return;
	}
					//	establish how the keyboard keys will influence movement
	SetCommonKeyboardControls();
	SetKeyboardControls();

	DisableDlgControls();	//	post 0.55

	this->SetFocus();

					//	Enter the rendering loop
	run = 1;
	OldTimeGetTime = (float)timeGetTime();
	MSG		msg;
	
	while (run == 1)
	{
		m_cameraOldPos = XForm.Translation;		//	old position
		m_cameraNewPos = XForm.Translation;		//	new position	
		ControlCamera();						//	for controlling our camera's flight
		
		deltaTime = (float)(timeGetTime() - OldTimeGetTime)*0.001f;
		OldTimeGetTime = (float)timeGetTime();
		
		
		if (!geEngine_BeginFrame(Engine, Camera, GE_TRUE))
			run = 0;
		
		if (!geEngine_RenderWorld(Engine, World, Camera, 0.0f))
			run = 0;
		
		geEngine_Printf(Engine, Rect.Left + 10, Rect.Bottom - 20, "EDSF keys to move");
		geEngine_Printf(Engine, Rect.Right - 110, Rect.Bottom - 20, "<Esc> to exit");

		if (m_DriverName ==  _T("D3D"))
			geEngine_Printf(Engine, (Rect.Right/2) - 10, Rect.Bottom - 20, "Direct3D");
		if (m_DriverName ==  _T("Glide"))
			geEngine_Printf(Engine, (Rect.Right/2) - 10, Rect.Bottom - 20, "Glide");
		if (m_DriverName ==  _T("Software"))
			geEngine_Printf(Engine, (Rect.Right/2) - 10, Rect.Bottom - 20, "Software");


		if (!geEngine_EndFrame(Engine))
			run = 0;
		
					//	let window poll for messages
		while (PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE))
		{
			if (!GetMessage(&msg, NULL, 0, 0 ))
			{
				run = 0;
				break;
			}
			TranslateMessage(&msg); 
			DispatchMessage(&msg);
		}
	}

					//	Shutdown the Genesis engine and clean up the memory	
	Shutdown();

	RestoreDialogBox();

}


//	MoveCamera	================================================================
//				Moves our camera forward or backward, and checks for collisions
//	============================================================================
void CGenEditPreviewDlg::MoveCamera(float speed, geVec3d *Direction)
{
	float	movespeed;
	movespeed = speed * deltaTime; 
											//	Move forward or backward
	geVec3d_AddScaled (&m_cameraNewPos, Direction, movespeed, &m_cameraNewPos); 
	
	if (m_collisionDetection)
	{
		DetectCollisions();
	}
}




//	DetectCollisions	===============================================================
//						Checks for collisions w/ up to 3 intersecting planes
//	===========================================================================
void CGenEditPreviewDlg::DetectCollisions()
{
	float	Slide;
	BOOL    Result;
	GE_Collision Collision;

	
	//	First, check to see if we are colliding with ONE surface 
	Result = geWorld_Collision(World, &CameraExtBox.Min, &CameraExtBox.Max, &m_cameraOldPos, &m_cameraNewPos, 
		GE_CONTENTS_SOLID_CLIP, GE_COLLIDE_ALL, 0xffffffff, NULL, NULL, &Collision);
	
	if(Result == 1)					//Your new position collides with something
	{
		Slide = geVec3d_DotProduct (&m_cameraNewPos, &Collision.Plane.Normal) - Collision.Plane.Dist;
		m_cameraNewPos.X -= Collision.Plane.Normal.X * Slide;
		m_cameraNewPos.Y -= Collision.Plane.Normal.Y * Slide;
		m_cameraNewPos.Z -= Collision.Plane.Normal.Z * Slide;
	
		//	Now, test to see if you are also colliding with a SECOND surface
		Result = geWorld_Collision(World, &CameraExtBox.Min, &CameraExtBox.Max, &m_cameraOldPos, &m_cameraNewPos, 
			GE_CONTENTS_SOLID_CLIP, GE_COLLIDE_ALL, 0xffffffff, NULL, NULL, &Collision);
		
		if(Result == 1)					//Your new position collides with something
		{
			Slide = geVec3d_DotProduct (&m_cameraNewPos, &Collision.Plane.Normal) - Collision.Plane.Dist;
			m_cameraNewPos.X -= Collision.Plane.Normal.X * Slide;
			m_cameraNewPos.Y -= Collision.Plane.Normal.Y * Slide;
			m_cameraNewPos.Z -= Collision.Plane.Normal.Z * Slide;
			
			//	Finally, test to see if you are also colliding with a THIRD surface			
			Result = geWorld_Collision(World, &CameraExtBox.Min, &CameraExtBox.Max, &m_cameraOldPos, &m_cameraNewPos, 
				GE_CONTENTS_SOLID_CLIP, GE_COLLIDE_ALL, 0xffffffff, NULL, NULL, &Collision);
			
			if(Result == 1)					//Your new position collides with something
			{
				Slide = geVec3d_DotProduct (&m_cameraNewPos, &Collision.Plane.Normal) - Collision.Plane.Dist;
				m_cameraNewPos.X -= Collision.Plane.Normal.X * Slide;
				m_cameraNewPos.Y -= Collision.Plane.Normal.Y * Slide;
				m_cameraNewPos.Z -= Collision.Plane.Normal.Z * Slide;
			}
		}
	}
}



//	ControlCamera	==============================================================
//						Sets up rotation & movement based on mouse pos & key presses

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -