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

📄 graphicstab.cpp

📁 空战游戏flacon源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
#include "falclib.h"
#include "chandler.h"
#include "userids.h"
#include "PlayerOp.h"
#include <mmsystem.h>
#include "sim\include\stdhdr.h"
#include "sim\include\simio.h"
#include "Graphics\Include\render3d.h"
#include "Graphics\Include\renderow.h"
#include "Graphics\Include\drawBSP.h"
#include "Graphics\Include\matrix.h"
#include "Graphics\Include\loader.h"
#include "objectiv.h"
#include "cbsplist.h"
#include "c3dview.h"
#include "ui_setup.h"
#include "Graphics\Include\RViewPnt.h"
#include "dispcfg.h"
#include "f4find.h"
#include "Graphics\Include\draw2d.h"
#include "Graphics\Include\devmgr.h"
#include "dispopts.h"
#include "sim\include\sinput.h"
#include "classtbl.h"

#pragma warning(disable : 4706)		// assignment within conditional expression
extern C_Handler *gMainHandler;
extern int GraphicSettingMult;

C_3dViewer	*SetupViewer = NULL;
RViewPoint	*tmpVpoint = NULL;
ObjectPos	*Objects = NULL;
FeaturePos	*Features = NULL;
short		NumObjects = 0, NumFeatures = 0;

extern const Trotation	IMatrix;

//defined in this file
void ChangeViewpointCB(long ID,short hittype,C_Base *control);


//defined in another file
void PositandOrientSetData (float x, float y, float z, float pitch, float roll, float yaw,
                            Tpoint* simView, Trotation* viewRotation);
void STPSetupControls(void);

const int	SMOKE = 1000;
Drawable2D *Smoke = NULL;

////////////////
/////GraphicsTab
////////////////

void STPEnterCrit()
{
	F4EnterCriticalSection(SetupCritSection);
}

void STPLeaveCrit()
{
	F4LeaveCriticalSection(SetupCritSection);
}

void STPMoveRendererCB(C_Window *win)
{
	if(SetupViewer)
		SetupViewer->Viewport(win,2);
}//MoveRendererCB

void STPViewTimerCB(long,short,C_Base *control)
{
	control->SetReady(1);
	if(control->GetFlags() & C_BIT_ABSOLUTE)
	{
		control->Parent_->RefreshWindow();
	}
	else
		control->Parent_->RefreshClient(control->GetClient());
}//ViewTimerCB


void STPDisplayCB(long,short,C_Base *)
{
	F4EnterCriticalSection(SetupCritSection);
	if(SetupViewer)
		SetupViewer->ViewOTW();
	F4LeaveCriticalSection(SetupCritSection);
}//DisplayCB

void InitializeViewer(C_Window *win, RenderOTW	*renderer )
{
	C_Slider	*slider;
	C_Button	*button;
	
	slider=(C_Slider *)win->FindControl(OBJECT_DETAIL);
	if(slider != NULL)
	{
		renderer->SetObjectDetail((float)slider->GetSliderPos()/(slider->GetSliderMax()-slider->GetSliderMin())*1.5f + 0.5f);
	}

	slider=(C_Slider *)win->FindControl(TEXTURE_DISTANCE);
	if(slider != NULL)
	{
		float sliderPos;
		sliderPos = (float)slider->GetSliderPos()/(slider->GetSliderMax()-slider->GetSliderMin());
		renderer->SetTerrainTextureLevel( (int)floor(sliderPos * 4.0f) );
	}
	
	button=(C_Button *)win->FindControl(OBJECT_TEXTURES);
	if(button != NULL)
	{
		renderer->SetObjectTextureState( button->GetState() );
	}
	
	button=(C_Button *)win->FindControl(BILINEAR_FILTERING);
	if(button != NULL)
	{
		renderer->SetFilteringMode( button->GetState() );
	}
	
	button=(C_Button *)win->FindControl(HAZING);
	if(button != NULL)
	{
		renderer->SetHazeMode(button->GetState());
	}

	button=(C_Button *)win->FindControl(GOUROUD);
	if(button != NULL)
	{
		renderer->SetSmoothShadingMode(button->GetState());
	}

	button=(C_Button *)win->FindControl(ALPHA_BLENDING);
	if(button != NULL)
	{
		renderer->SetAlphaMode( button->GetState() );
	}
}

void InsertSmokeCloud()
{
	FILE		*fp;
	char		filename[MAX_PATH];

	sprintf(filename,"%s\\config\\viewer.dat",FalconDataDirectory);
	fp = fopen(filename,"rb");
	if(fp)
	{
		ViewPos View;
		Trotation	rot = IMatrix;
		Tpoint		pos = {0.0f};
		float		scale = 100.0F;
		RViewPoint *VP;

		fread(&View,sizeof(ViewPos),1,fp);
		fclose(fp);
		fp = NULL;

		VP = SetupViewer->GetVP();
		
		PositandOrientSetData(View.Xpos * FEET_PER_KM+ 300,View.Ypos * FEET_PER_KM - 100,
						View.CamZ + View.Zpos + 100,0,0,0,&pos,&rot);

		Smoke = new Drawable2D(DRAW2D_SMOKECLOUD1,scale,&pos);
		
		VP->InsertObject(Smoke);
	}
}

void LoadObjects( ViewPos &View ,C_Window *win)
{
	FILE		*fp;
	BSPLIST		*list;
	float		Temp;
	Trotation	rot = IMatrix;
	Tpoint		pos = {0.0f};
	char		filename[MAX_PATH];
	float		scale = 1.0F;
	C_Slider	*slider;

	sprintf(filename,"%s\\config\\viewer.dat",FalconDataDirectory);
	fp = fopen(filename,"rb");
	if(fp)
	{
		fread(&View,sizeof(ViewPos),1,fp);
		
		fread(&Temp,sizeof(float),1,fp);
		
		if(Objects)
			delete [] Objects;
		
		NumObjects = static_cast<short>(FloatToInt32(Temp));
		
		Objects = new ObjectPos[NumObjects];
		
		fread(Objects,sizeof(ObjectPos),NumObjects,fp);
		
		fread(&Temp,sizeof(float),1,fp);
		
		if(Features)
			delete [] Features;

		NumFeatures = static_cast<short>(FloatToInt32(Temp));

		Features = new FeaturePos[NumFeatures];
		
		fread(Features,sizeof(FeaturePos),NumFeatures,fp);
		
		fclose(fp);
		
		fp = NULL;
		
		slider=(C_Slider *)win->FindControl(VEHICLE_SIZE);
		if(slider != NULL)
		{
			scale = ((float)slider->GetSliderPos()/(float)(slider->GetSliderMax()-slider->GetSliderMin()) * 4.0F + 1.0F);
		}

		if(NumObjects)
			{
				for(int i=0;i<NumObjects;i++)
				{
					PositandOrientSetData(View.Xpos * FEET_PER_KM + Objects[i].Xpos ,View.Ypos * FEET_PER_KM + Objects[i].Ypos,
						Objects[i].Zpos,Objects[i].Pitch,Objects[i].Roll,Objects[i].Yaw,&pos,&rot);
					list = SetupViewer->LoadBSP(i,FloatToInt32(Objects[i].VisID),TRUE);
					((DrawableBSP*)list->object)->Update(&pos,&rot);
					if(Objects[i].VisID == VIS_F16C)
						((DrawableBSP*)list->object)->SetSwitchMask(10, TRUE);
					list->object->SetScale(scale); 
				}
			}
			
		if(NumFeatures)
		{
			for(int i=0;i<NumFeatures;i++)
			{
				PositandOrientSetData(View.Xpos * FEET_PER_KM + Features[i].Xpos ,View.Ypos * FEET_PER_KM + Features[i].Ypos,
					Features[i].Zpos,0.0f,0.0f,Features[i].Facing,&pos,&rot);
				list = SetupViewer->LoadBuilding(i + 100,FloatToInt32(Features[i].VisID),&pos,0.0f);
				((DrawableBSP*)list->object)->Update(&pos,&rot);
			}
		}

	}
}


void STPRender(C_Base *control)
{
	C_Text		*text=NULL;
	
	if(SetupViewer == NULL)
	{
		SetCursor(gCursors[CRSR_WAIT]);

		RenderOTW	*renderer=NULL;
		RViewPoint	*viewpt=NULL;
		ViewPos		View = {0.0f};
		C_Slider	*slider=NULL;
		Tpoint		pos={0.0F};
		int			objdetail=0;
		
		F4EnterCriticalSection(SetupCritSection);

		SetupViewer=new C_3dViewer;
		SetupViewer->Setup();
		SetupViewer->Viewport(control->Parent_,2); // use client 2 for this window

		short terrlvl=0;
		float terrdist=40.0F;

		slider=(C_Slider *)control->Parent_->FindControl(TERRAIN_DETAIL);
		if(slider != NULL)
		{
			int mid;
			mid = (slider->GetSliderMax()-slider->GetSliderMin())/2;
		
			if(slider->GetSliderPos() > mid)
			{
				terrdist = (40.0f + ((float)slider->GetSliderPos() - mid)/mid * 40.0f);
				terrlvl = 0;
			}
			else 
			{
				terrdist = 40.0f;
				terrlvl = static_cast<short>(FloatToInt32(2 - ((float)slider->GetSliderPos()/mid * 2)));
			}
		}
		SetupViewer->SetTextureLevels(terrlvl,4);
		SetupViewer->SetViewDistance(terrdist * FEET_PER_KM);
		
		
		LoadObjects( View, control->Parent_ );
		SetupViewer->SetPosition(View.Xpos * FEET_PER_KM, View.Ypos * FEET_PER_KM, View.Zpos);
		SetupViewer->SetCamera(View.CamX, View.CamY, View.CamZ, View.CamYaw, View.CamPitch, View.CamRoll );
		SetupViewer->InitOTW(30.0f,FALSE);

		viewpt = SetupViewer->GetVP();		
		viewpt->GetPos(&pos);
		
		renderer = SetupViewer->GetRendOTW();
		InitializeViewer((C_Window *)control->Parent_, renderer);
		
		slider=(C_Slider *)control->Parent_->FindControl(DISAGG_LEVEL);
		if(slider != NULL)
		{
			objdetail = FloatToInt32((float)slider->GetSliderPos()/(slider->GetSliderMax()-slider->GetSliderMin()) * 5 + 0.5F);
		}
		
		if(NumObjects)
		{
			for(int i=0;i<NumObjects;i++)
			{	
				SetupViewer->AddToView(i);
			}
		}
		
		if(NumFeatures)
		{
			for(int i=0;i<NumFeatures;i++)
			{
				if(Features[i].Priority <= objdetail)
					SetupViewer->AddToView(i + 100);
			}
		}

		InsertSmokeCloud();
		
		TheLoader.WaitForLoader();

		F4LeaveCriticalSection(SetupCritSection);

		

		text = (C_Text *)control->Parent_->FindControl(LOADING);
		if(text)
		{
			text->SetFlagBitOn(C_BIT_INVISIBLE);
			text->Refresh();
		}
		
		if(!tmpVpoint)
		{
			tmpVpoint = new RViewPoint;
			tmpVpoint->Setup(80.0f * FEET_PER_KM, 0, 4,0);
			tmpVpoint->Update(&pos);
		}
		SetCursor(gCursors[CRSR_F16]);
		control->Parent_->RefreshClient(2);
		ready = TRUE;
	}	
}//STPRender

void RenderViewCB(long,short hittype,C_Base *control)
{
	if(hittype != C_TYPE_LMOUSEUP)
		return;
	C_Text		*text;

	if(((C_Button *)control)->GetState())
	{
		text = (C_Text *)control->Parent_->FindControl(LOADING);
		if(text)
		{
			text->SetFlagBitOff(C_BIT_INVISIBLE);
			text->Refresh();
		}
		//Sleep(100);
		//STPRender(control);
		PostMessage(gMainHandler->GetAppWnd(),FM_STP_START_RENDER,0,(LPARAM)control);
	}
	else
	{
		if(SetupViewer)
		{
			if(!ready)
			{
				((C_Button *)control)->SetState(C_STATE_1);
				((C_Button *)control)->Refresh();
				return;
			}

			ready = FALSE;
			F4EnterCriticalSection(SetupCritSection);

			RViewPoint	*viewpt;
			viewpt = SetupViewer->GetVP();
			viewpt->RemoveObject(Smoke);
			delete Smoke;
			Smoke = NULL;
			SetupViewer->Cleanup();
			delete SetupViewer;
			SetupViewer = NULL;
			
			F4LeaveCriticalSection(SetupCritSection);
			//control->Parent_->RefreshClient(2);
			control->Parent_->RefreshWindow();
		}
	}
}



void ChangeViewpointCB(long,short,C_Base *)
{
	static int count = 0;
	
	C_Window	*win;
	
	if(ready)
	{
		// Update the Joystick control
		GetJoystickInput();

		if ( IO.digital[0] || ((count %= 3) == 0) )
		{
			win=gMainHandler->FindWindow(SETUP_WIN);
			if(win != NULL)
			{
				//Leave=UI_Enter(control->Parent_);
				F4EnterCriticalSection(SetupCritSection);
				if(SetupViewer == NULL)
				{
					F4LeaveCriticalSection(SetupCritSection);
					//UI_Leave(Leave);
					return;
				}
			
					
			
				float pitchChg = 0.0f,yawChg = 0.0f;
				float altChg = 0.0f;
				float newPitch=0.0f, newYaw=0.0f, newAlt;
			
				//gMainHandler->EnterCriticalSection();
				
				if(IO.digital[0])
				{
					pitchChg = IO.analog[1].engrValue * PITCH_CHG;
					yawChg = IO.analog[0].engrValue * YAW_CHG;
					
					altChg = 1.0f - IO.analog[2].engrValue;

					if(IO.digital[1])
					{
						altChg = altChg * altChg * ALT_CHG;
					}
					else
					{
						altChg = altChg * altChg * ALT_CHG * -1;
					}
				}
				
				if(fabs(pitchChg)<0.5)
					pitchChg = 0.0f;
				newPitch = SetupViewer->GetCameraPitch() + pitchChg;
				
				if(newPitch > 90.0f)
					newPitch = 90.0f;
				else if(newPitch < -90.0f)
					newPitch = -90.0f;
				
				if(fabs(yawChg) < 0.5)
					yawChg = 0.0f;
				newYaw = SetupViewer->GetCameraHeading() + yawChg;
				
				if(fabs(altChg) < .5f)
					altChg = 0.0f;
				
				newAlt = altChg + SetupViewer->GetCameraZ();
				
				if(newAlt > MIN_ALT)
					newAlt = MIN_ALT;
				else if(newAlt < MAX_ALT)

⌨️ 快捷键说明

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