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

📄 leveledit.cpp

📁 一个96K的3D游戏源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	}
}

void RestoreSector(long Nr)
{
	tSector *SOld,*SNew,*TempO,*TempN,*Temp;

	SOld=GetSubSectorNr(UndoList[0],Nr);
	SNew=GetSubSectorNr(Level,Nr);

	TempO=SOld->Father->SubSector;
	TempN=SNew->Father->SubSector;
	if(TempO!=SOld)
	{
		while(TempO->Next!=SOld)
		{
			TempO=TempO->Next;
			TempN=TempN->Next;
		}
		Temp=SNew->Next;
		SNew->Next=NULL;
		DestroySector(SNew);
		SNew=CopySector(SOld,TempN->Father,true,false);
		SNew->Next=Temp;
		TempN->Next=SNew;
	} else {
		SOld=SOld->Father;
		SNew=SNew->Father;
		Temp=SNew->SubSector->Next;
		SNew->SubSector->Next=NULL;
		DestroySector(SNew->SubSector);
	    SNew->SubSector=CopySector(SOld->SubSector,SNew,true,false);
		SNew->SubSector->Next=Temp;
	}
	  
}


void AddTempCommand(bool ResOld)
{
	if(TempCommand==NULL) return;

	if(ResOld) RestoreResSec(ASNr);
//	DestroySector(Level);
//	Level=CopySector(UndoList[0],NULL,true,true);

	MyCalcCommand(TempCommand,Level);
    AddToUndoList();
//	CreateSectorDL(Level,true);
	GetAktSector();
	CreateSectorDL(AktSector,false);

	AddCommand(CommandList,TempCommand);
	TempCommand=NULL;
}

void ReCalcOldLevel()
{
	  DestroySector(Level);
	  Level=CopySector(UndoList[0],NULL,true,true);
	  CreateSectorDL(Level,true);
}


void ReCalcLastSector()
{
	ReCalcMatrices(AktSector,AktSector->Father->Matrix,AktSector->Father->WSize);
	ReCalcMeshes(AktSector,AktSector->Father->Matrix,AktSector->Father->Pos);
}

void InsertLevelWindows() // L鋎t ne .dat
{
	OPENFILENAME	ofn;					/* common dialog box structure   */
	char			szDirName[MAX_PATH];    /* directory string              */
	char			szFile[4096];			/* filename string               */
	char			szFileTitle[4096];      /* filename string               */
	long I,K,M;
	tP3D Pos;

	/*
    hinst = (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE);
    */

	/*
        Obtain the system directory name and store it in szDirName. 
    */
	GetSystemDirectory(szDirName, sizeof(szDirName)); 

	/*
        Place the terminating null character in the szFile.
    */
	szFile[0] = '\0'; 

	/*
        Set the members of the OPENFILENAME structure.
    */
	memset(&ofn, 0, sizeof(ofn));
	ofn.lStructSize = sizeof(OPENFILENAME); 
	ofn.hwndOwner = MainWindow; 
	ofn.lpstrTitle = "Import Level File\0";
	ofn.lpstrFilter = "B-Clopd3D Level Files (*.bcl)\0*.bcl\0All files (*.*)\0*.*\0\0";
	ofn.lpstrCustomFilter = NULL;
	ofn.nFilterIndex = 1; 
	ofn.lpstrFile = szFile; 
	ofn.nMaxFile = 2048; 
	ofn.lpstrFileTitle = szFileTitle;
	ofn.nMaxFileTitle = 2048;
	ofn.lpstrInitialDir = ".\0";
	ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; 

	/*
        Display the Open dialog box.
    */
	if (GetOpenFileName(&ofn)) 
	{
		char *path = ofn.lpstrFile;
//		char *fname = ofn.lpstrFile;
		char *fname = ofn.lpstrFileTitle;
		char *outp;

//		LoadDaAnimation(fname);
		
//		TestString=fname;

		DestroyCommand(TempCommand);
		TempCommand=CreateCommand();
		SetCommand_InsertLevel(TempCommand,fname);
   	    AddTempCommand(false);

		AktSector=LastSector(Level);
		ASNr=GetNrOfSubSector(Level,LastSector(Level));
		AktSector=GetSubSectorNr(Level,ASNr);
		
		Pos=CalcRelPosition(vAdd(CPos,vMulK(CVek,5)),&Level->Matrix);
	
		if(InsertMove)
		{
			DestroyCommand(TempCommand);
			TempCommand=CreateCommand();
			SetCommand_Change_Attributes(TempCommand,ASNr,Pos,AktSector->Size,AktSector->SizeMul);
   			AddTempCommand(false);
		}
			
		AktSector=LastSector(Level);
		ASNr=GetNrOfSubSector(Level,LastSector(Level));
		AktSector=GetSubSectorNr(Level,ASNr);
		CreateSectorDL(Level,true);
	    SetResSec(ASNr,Level);
	    ResNr=ASNr;
	};
	SetCursorPos(ScreenXSize/2,ScreenYSize/2);
	MX=0;
	MY=0;
	mouse_klick=0;
	mouselklick=0;
}

void KillLastSector(tSector *Level)
{
	Level=Level->SubSector;
	while(Level->Next->Next!=NULL) Level=Level->Next;
	DestroySector(Level->Next);
	Level->Next=NULL;
}

void CalcMouseStuff()
{
  bool Changed=false;
  bool ReCommand=false;
  bool MidSet;
  tSector *TempS;
  tP3D VekF,VekL,Rot,Pos,Size;
  float L,R,A,B,X,Y,Roll,SizeMul,Dir,RotAmount;
  long I,K,M;

  if(KeyPr[VK_F2])
  {
	  ScreenShot=true;
	  KeyPr[VK_F2]=false;
  }
  if(KeyPr[VK_F3])
  {
	  InsertMove=!InsertMove;
	  KeyPr[VK_F3]=false;
  }
  if(KeyPr[VK_SPACE])
  {
	  MenuMode=_Merge;
	  KeyPr[VK_SPACE]=false;
  }
  if(KeyPr[VK_CONTROL])
  {
	  MenuMode=_Select_Object;
	  KeyPr[VK_CONTROL]=false;
  }
  if(KeyPr[VK_SHIFT])
  {
	  MenuMode=_Make_Sub;
	  KeyPr[VK_SHIFT]=false;
  }

  if(mouse_klick==1)
  {

	  if(((OldMouse!=mouse_klick)||(ASNr!=ResNr))&&(ASNr>=2))
	  {
		  SetResSec(ASNr,Level);
		  ResNr=ASNr;
	  }

	if(MenuMode==_Modify)
	{
//	  RestoreSector(ASNr);
	  RestoreResSec(ASNr);
		
	  GetAktSector();
	  Pos=AktSector->OrgPos;
	  Size=AktSector->Size;
	  Roll=AktSector->Roll;
	  SizeMul=AktSector->SizeMul;
	  MidSet=false;

	  if(MouseOverItem(MISize))
		  if(!MouseAdjust)  { StartMouseAdjust();} else
		  {

			  L=vLength2(Size)*(1+(float)(MAY)/10);
			  if(L<0) L=-L;
			  Norm(&Size);
			  Size=vMulK(Size,L);

/*
			  L=SizeMul*(float)(1.0f+(MAY)/10);
			  if(L<0) L=-L;
			  SizeMul=L;
*/
			  
		  }
	  if(MouseOverItem(MISizeX))
		  if(!MouseAdjust)  { StartMouseAdjust();} else {  Size.X*=(1+MAY/40); }
	  if(MouseOverItem(MISizeY))
		  if(!MouseAdjust)  { StartMouseAdjust();} else {  Size.Y*=(1+MAY/40); }
	  if(MouseOverItem(MISizeZ))
		  if(!MouseAdjust)  { StartMouseAdjust();} else {  Size.Z*=(1+MAY/40); }

	  if(MouseOverItem(MIPos))
		  if(!MouseAdjust)  { StartMouseAdjust();} else
			if(AktSector->Father!=NULL)
		  {
			  VekF=CalcRelPosition(CVek,&AktSector->Father->Matrix);
			  VekL=vCross(CVek,vSet(0,1,0));  Norm(&VekL);
			  VekL=CalcRelPosition(VekL,&AktSector->Father->Matrix);

			  Pos=vAdd(Pos,vMulK(VekF,MAY/40));
			  Pos=vAdd(Pos,vMulK(VekL,MAX/40));
		  }
	  if(MouseOverItem(MIPosXZ))
		  if(!MouseAdjust)  { StartMouseAdjust();} else
			if(AktSector->Father!=NULL)
		  {
			  VekF=CVek;VekF.Y=0;
			  VekF=CalcRelPosition(VekF,&AktSector->Father->Matrix);
			  VekL=vCross(CVek,vSet(0,1,0));VekL.Y=0; Norm(&VekL);
			  VekL=CalcRelPosition(VekL,&AktSector->Father->Matrix);

			  Pos=vAdd(Pos,vMulK(VekF,MAY/40));
			  Pos=vAdd(Pos,vMulK(VekL,MAX/40));
		  }
	  if(MouseOverItem(MIPosY))
		  if(!MouseAdjust)  { StartMouseAdjust();} else
			if(AktSector->Father!=NULL)
		  {
			  VekF=vSet(0,1,0);
			  VekF=CalcRelPosition(VekF,&AktSector->Father->Matrix);
			  Pos=vAdd(Pos,vMulK(VekF,MAY/40));
		  }

	  if(MouseOverItem(MIMMPos))
		  if(!MouseAdjust)  { StartMouseAdjust();} else
			if(AktSector->Father!=NULL)
		  {
			  VekF=CalcRelPosition(CVek,&AktSector->Father->Matrix);
			  VekL=vCross(CVek,vSet(0,1,0));  Norm(&VekL);
			  VekL=CalcRelPosition(VekL,&AktSector->Father->Matrix);

			  Pos=vAdd(Pos,vMulK(VekF,MAY/40));
			  Pos=vAdd(Pos,vMulK(VekL,MAX/40));
			  MidSet=true;
		  }
	  if(MouseOverItem(MIMMPosXZ))
		  if(!MouseAdjust)  { StartMouseAdjust();} else
			if(AktSector->Father!=NULL)
		  {
			  VekF=CVek;VekF.Y=0;
			  VekF=CalcRelPosition(VekF,&AktSector->Father->Matrix);
			  VekL=vCross(CVek,vSet(0,1,0));VekL.Y=0; Norm(&VekL);
			  VekL=CalcRelPosition(VekL,&AktSector->Father->Matrix);

			  Pos=vAdd(Pos,vMulK(VekF,MAY/40));
			  Pos=vAdd(Pos,vMulK(VekL,MAX/40));
			  MidSet=true;
		  }
	  if(MouseOverItem(MIMMPosY))
		  if(!MouseAdjust)  { StartMouseAdjust();} else
			if(AktSector->Father!=NULL)
		  {
			  VekF=vSet(0,1,0);
			  VekF=CalcRelPosition(VekF,&AktSector->Father->Matrix);
			  Pos=vAdd(Pos,vMulK(VekF,MAY/40));
			  MidSet=true;
		  }

	  Dir=4;
	  RotAmount=0;
	  if(MouseOverItem(MIRotX))
		  if(!MouseAdjust)  { StartMouseAdjust();} else
		  {
				Dir=0;
				RotAmount=MAY/10;
		  }
	  if(MouseOverItem(MIRotY))
		  if(!MouseAdjust)  { StartMouseAdjust();} else
		  {
				Dir=1;
				RotAmount=MAY/10;
		  }
	  if(MouseOverItem(MIRotZ))
		  if(!MouseAdjust)  { StartMouseAdjust();} else
		  {
				Dir=2;
				RotAmount=MAY/10;
		  }

		MainRotAmount=RotAmount;
		Norm(&Rot);
		DestroyCommand(TempCommand);
		TempCommand=CreateCommand();

		if(MidSet)
		{
			SetCommand_MoveMitte(TempCommand,ASNr,Pos);
		} else 
		{
			if(Dir==4)
			{ SetCommand_Change_Attributes(TempCommand,ASNr,Pos,Size,SizeMul);}
			else
			{ SetCommand_Rotate(TempCommand,ASNr,Dir,RotAmount);}
		}

		MyCalcCommand(TempCommand,Level);

	}
	if(MenuMode==_Change_Flags)
	{
	  long Att1,Att2,Att3,Att4;
	  RestoreResSec(ASNr);
//	  RestoreSector(ASNr);
		
	  GetAktSector();
	  Att1=AktSector->Attr;
	  Att2=AktSector->Attr2;
	  Att3=AktSector->Attr3;
	  Att4=AktSector->Attr4;

	  if(MouseOverItem(MISecAttr))
		  if(!MouseAdjust)  { StartMouseAdjust();} else
		  {
			  Att2+=MAY;
			  if(Att2<0)Att2=0;
			  if(Att2>255)Att2=255;
		  }
	  if(MouseOverItem(MISecAttr2))
		  if(!MouseAdjust)  { StartMouseAdjust();} else
		  {
			  Att3+=MAY;
			  if(Att3<0)Att3=0;
			  if(Att3>255)Att3=255;
		  }
	  if(MouseOverItem(MISecAttr3))
		  if(!MouseAdjust)  { StartMouseAdjust();} else
		  {
			  Att4+=MAY;
			  if(Att4<0)Att4=0;
			  if(Att4>255)Att4=255;
		  }
/*
	  if(MouseOverItem(MISecAttr))
		  if(!MouseAdjust)  { StartMouseAdjust();} else
		  {
			  Att2+=MAY;
			  if(Att2<0)Att2=0;
			  if(Att2>255)Att2=0;
		  }
*/
		DestroyCommand(TempCommand);
		TempCommand=CreateCommand();

		SetCommand_ChangeFlags(TempCommand,ASNr,AktSector->Flags,Att1,Att2,Att3,Att4);

		MyCalcCommand(TempCommand,Level);

	}
	if(MenuMode==_Modify_Vertex)
	{
		RestoreResSec(ASNr);
//	    RestoreSector(ASNr);
//		ReCalcOldLevel();
		GetAktSector();

		if(MouseOverItem(MIPos))
		{ 
		  if(!MouseAdjust)  { StartMouseAdjust();} else
			{
			  VekF=CalcRelPosition(CVek,&AktSector->Matrix);
			  VekL=vCross(CVek,vSet(0,1,0));  Norm(&VekL);
			  VekL=CalcRelPosition(VekL,&AktSector->Matrix);

			  VekF=vMulK(VekF,MAY/100);
			  VekL=vMulK(VekL,MAX/100);

			  DestroyCommand(TempCommand);
			  TempCommand=CreateCommand();
			  SetCommand_Move_Vertice_With_Radius(TempCommand,ASNr,AktVertice,vAdd(VekF,VekL),Radius,SubDivs);

			  MyCalcCommand(TempCommand,Level);
			}
		} else
		if(MouseOverItem(MIPosXZ))
		{ 
		  if(!MouseAdjust)  { StartMouseAdjust();} else
			{
			  VekF=CVek;
			  VekF.Y=0;
			  VekF=CalcRelPosition(VekF,&AktSector->Matrix);
			  VekL=vCross(CVek,vSet(0,1,0));  Norm(&VekL);
			  VekL.Y=0;
			  VekL=CalcRelPosition(VekL,&AktSector->Matrix);

			  VekF=vMulK(VekF,MAY/100);
			  VekL=vMulK(VekL,MAX/100);

			  DestroyCommand(TempCommand);
			  TempCommand=CreateCommand();
			  SetCommand_Move_Vertice_With_Radius(TempCommand,ASNr,AktVertice,vAdd(VekF,VekL),Radius,SubDivs);

			  MyCalcCommand(TempCommand,Level);
			}
		} else
		if(MouseOverItem(MIPosY))
		{ 
		  if(!MouseAdjust)  { StartMouseAdjust();} else
			{
			  VekF=vSet(0,1,0);
			  VekF=CalcRelPosition(VekF,&AktSector->Matrix);

			  VekF=vMulK(VekF,MAY/100);

			  DestroyCommand(TempCommand);
			  TempCommand=CreateCommand();
			  SetComman

⌨️ 快捷键说明

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