📄 level.cpp
字号:
/* LEVEL.CPP
*
* provides Level-Declarations & -operations
*
* Copyright 2003 by PaP / JTMK
*/
#include "stdio.h"
#include <math.h>
#include <windows.h>
#include "SystemIO.h"
#include "level.h"
#include "Vectors.h"
#include <gl\glaux.h> // Header File For The GLu32 Library
#include "GameDefines.h"
#include "BCLS.h"
#define RutschGrenze 0.07
float RutschQuad=RutschGrenze*RutschGrenze;
bool RutschAble;
long SectorNr,FirstType;
tSector *SSec,*GlobalSector;
tMaterial *Material,*TempM,*Mat[MaxMaterials],*MatFeld;
tP3D Err1,Err2,Err3,Err4,Err5,Err6;
long Materials=0;
tP3D HitNormal;
tSector *StandSector;
long GetCommandSize(long ID)
{
switch(ID)
{
case _Command_GlobalEnd:return(0);break;
case _Command_GlobalStart:return(0);break;
case _Command_Cube_Opt:return(sizeof(tCommand_Create_Cube_Opt));break;
case _Command_Move_Vertice_With_Radius_Opt:return(sizeof(tCommand_Move_Vertice_With_Radius_Opt));break;
case _Command_Clone:return(sizeof(tCommand_Clone));break;
case _Command_Clone2:return(sizeof(tCommand_Clone2));break;
case _Command_Make_Sub:return(sizeof(tCommand_Make_Sub));break;
case _Command_Make_Sub2:return(sizeof(tCommand_Make_Sub2));break;
case _Command_Create_Plane:return(sizeof(tCommand_Create_Plane));break;
case _Command_Create_Kegel:return(sizeof(tCommand_Create_Kegel));break;
case _Command_Create_Torus:return(sizeof(tCommand_Create_Torus));break;
case _Command_Set_Material_Opt:return(sizeof(tCommand_Set_Material_Opt));break;
case _Command_Create_Cylinder:return(sizeof(tCommand_Create_Cylinder));break;
case _Command_Rotate_Opt:return(sizeof(tCommand_Rotate_Opt));break;
case _Command_Merge:return(sizeof(tCommand_Merge));break;
#ifndef BCLMemoryLoading
case _Command_Rotate:return(sizeof(tCommand_Rotate));break;
case _Command_Set_Material:return(sizeof(tCommand_Set_Material));break;
case _Command_Move_Vertice_With_Radius:return(sizeof(tCommand_Move_Vertice_With_Radius));break;
case _Command_Cube:return(sizeof(tCommand_Create_Cube));break;
case _Command_InsertLevel:return(sizeof(tCommand_InsertLevel));break;
case _Command_Change_Attributes:return(sizeof(tCommand_Change_Attributes));break;
case _Command_ChangeFlags:return(sizeof(tCommand_ChangeFlags));break;
#endif
case _Command_ChangeFlags_Opt:return(sizeof(tCommand_ChangeFlags_Opt));break;
case _Command_MoveMitte:return(sizeof(tCommand_MoveMitte));break;
case _Command_CreateItem:return(sizeof(tCommand_CreateItem));break;
case _Command_Change_Attributes_Opt:return(sizeof(tCommand_Change_Attributes_Opt));break;
case _Command_Insert_Opt:return(sizeof(tCommand_InsertOpt));break;
}
}
tGrund *CreateMesh()
{
tGrund *Temp;
Temp=(tGrund*)malloc(sizeof(tGrund));
Temp->DisplayListOn=NULL;
// Temp->BoundBox=NULL;
return(Temp);
}
tWandVertice *CopyVertList(tWandVertice *Vert,bool Single,bool MarkOrig)
{
tWandVertice *Temp;
if(Vert==NULL) return(NULL);
Temp=(tWandVertice*)malloc(sizeof(tWandVertice));
*Temp=*Vert;
Temp->Child=NULL;
if(MarkOrig) Vert->Child=Temp;
if(Single)
{ Temp->Next=NULL; }
else
{Temp->Next=CopyVertList(Vert->Next,Single,MarkOrig);}
return(Temp);
}
void UnChild(tWandVertice *Vert)
{
if(Vert==NULL) return;
Vert->Child=NULL;
UnChild(Vert->Next);
}
bool IsInBoundBox(tBoundBox *Temp,tP3D *Pos,float Toleranz)
{
__asm
{
mov ecx,[Pos]
xor eax,eax
mov ebx,[ebp+8]
fld dword ptr [Toleranz]
fld dword ptr [ecx+tP3D.X]
fld dword ptr [ebx+tBoundBox.P1.X]
fsub st(0),st(2)
fcomip st(0),st(1)
jnb JumpOut
fld dword ptr [ebx+tBoundBox.P2.X]
fadd st(0),st(2)
fcomip st(0),st(1)
jb JumpOut
fstp st(0)
fld dword ptr [ecx+tP3D.Y]
fld dword ptr [ebx+tBoundBox.P1.Y]
fsub st(0),st(2)
fcomip st(0),st(1)
jnb JumpOut
fld dword ptr [ebx+tBoundBox.P2.Y]
fadd st(0),st(2)
fcomip st(0),st(1)
jb JumpOut
fstp st(0)
fld dword ptr [ecx+tP3D.Z]
fld dword ptr [ebx+tBoundBox.P1.Z]
fsub st(0),st(2)
fcomip st(0),st(1)
jnb JumpOut
fld dword ptr [ebx+tBoundBox.P2.Z]
fadd st(0),st(2)
fcomip st(0),st(1)
jb JumpOut
mov eax,1
JumpOut:
fstp st(0)
fstp st(0)
}
/*
if( ((*Pos).X>=Temp->P1.X-Toleranz)&&((*Pos).X<=Temp->P2.X+Toleranz)&&
((*Pos).Y>=Temp->P1.Y-Toleranz)&&((*Pos).Y<=Temp->P2.Y+Toleranz)&&
((*Pos).Z>=Temp->P1.Z-Toleranz)&&((*Pos).Z<=Temp->P2.Z+Toleranz) )
{ return(true); } else { return(false);}
*/
}
void ReCalcMatrixAndRelPoints(tGrund *Grund)
{
tWandPoly *TempP;
TempP=Grund->Poly;
while(TempP!=NULL)
{
TempP->Norm1=vCross(vSub(TempP->P2->WorldPos,TempP->P1->WorldPos),TempP->Normal);
Norm(&TempP->Norm1);
TempP->Norm2=vCross(vSub(TempP->P3->WorldPos,TempP->P2->WorldPos),TempP->Normal);
Norm(&TempP->Norm2);
TempP->Norm3=vCross(vSub(TempP->P1->WorldPos,TempP->P3->WorldPos),TempP->Normal);
Norm(&TempP->Norm3);
TempP=TempP->Next;
}
}
tWandVertice *GetWandVertice(tWandVertice *Temp,long Nr)
{
while(Nr>0)
{
Temp=Temp->Next;
Nr--;
}
return(Temp);
}
tBoundBox *BeginBoundBox(tBoundBox *Temp1)
{
tBoundBox *Temp;
if(Temp1==NULL)
{ Temp=(tBoundBox*)malloc(sizeof(tBoundBox));} else { Temp=Temp1;}
Temp->P1=vNull;
Temp->P2=Temp->P1;
// Temp->Anz=true;
// Temp->Anz=0;
return(Temp);
}
void AddToBoundBox(tBoundBox *Temp,tP3D *Pos)
{
// if(Temp->Anz)
// if(Temp->Anz==0)
if(vEqual(Temp->P1,vNull))
{
Temp->P1=*Pos;
Temp->P2=*Pos;
} else {
if(Pos->X<Temp->P1.X) Temp->P1.X=Pos->X;
if(Pos->Y<Temp->P1.Y) Temp->P1.Y=Pos->Y;
if(Pos->Z<Temp->P1.Z) Temp->P1.Z=Pos->Z;
if(Pos->X>Temp->P2.X) Temp->P2.X=Pos->X;
if(Pos->Y>Temp->P2.Y) Temp->P2.Y=Pos->Y;
if(Pos->Z>Temp->P2.Z) Temp->P2.Z=Pos->Z;
}
// Temp->Anz=false;
// Temp->Anz++;
}
void DelBoundBox(tBoundBox *Temp)
{
if(Temp==NULL) return;
free(Temp);
}
tBoundBox ReCalcBoundBoxes(tGrund *Grund)
{
tWandPoly *TempP;
tBoundBox TempB;
// TempB=BeginBoundBox(NULL);
BeginBoundBox(&TempB);
TempP=Grund->Poly;
while(TempP!=NULL)
{
// TempP->BoundBox=BeginBoundBox(TempP->BoundBox);
BeginBoundBox(&TempP->BoundBox);
AddToBoundBox(&TempP->BoundBox,&TempP->P1->WorldPos);
AddToBoundBox(&TempP->BoundBox,&TempP->P2->WorldPos);
AddToBoundBox(&TempP->BoundBox,&TempP->P3->WorldPos);
AddToBoundBox(&TempB,&TempP->P1->WorldPos);
AddToBoundBox(&TempB,&TempP->P2->WorldPos);
AddToBoundBox(&TempB,&TempP->P3->WorldPos);
TempP=TempP->Next;
}
// DelBoundBox(Grund->BoundBox);
// Grund->BoundBox=CopyBoundBox(TempB);
Grund->BoundBox=TempB;
return(TempB);
}
void MergeBoundBox(tBoundBox *B1,tBoundBox *B2)
{
// if(B2->Anz!=0)
if(!vEqual(B2->P1,vNull))
{
AddToBoundBox(B1,&B2->P1);
AddToBoundBox(B1,&B2->P2);
}
}
tBoundBox ReCalcSectorBoundBoxes(tSector *Sector)
{
tBoundBox Temp,ChildBox;
// Temp.Anz=0;
Temp.P1=vNull;
Temp.P2=vNull;
if(Sector==NULL) return(Temp);
if(Sector->Mesh!=NULL)
{
// DelBoundBox(Sector->BoundBox);
Sector->BoundBox=ReCalcBoundBoxes(Sector->Mesh);
ReCalcMatrixAndRelPoints(Sector->Mesh);
ChildBox=ReCalcSectorBoundBoxes(Sector->SubSector);
MergeBoundBox(&Sector->BoundBox,&ChildBox);
// DelBoundBox(ChildBox);
Temp=Sector->BoundBox;
ChildBox=ReCalcSectorBoundBoxes(Sector->Next);
MergeBoundBox(&Temp,&ChildBox);
// DelBoundBox(ChildBox);
return(Temp);
} else {
// DelBoundBox(Sector->BoundBox);
// Sector->BoundBox=BeginBoundBox(NULL);
BeginBoundBox(&Sector->BoundBox);
Temp=ReCalcSectorBoundBoxes(Sector->SubSector);
Sector->BoundBox=Temp;
ChildBox=ReCalcSectorBoundBoxes(Sector->Next);
MergeBoundBox(&Temp,&ChildBox);
return(Temp);
}
}
//tWandPoly *CreateWandPoly(tWandVertice *_P1,tWandVertice *_P2,tWandVertice *_P3,tP3D _T1,tP3D _T2,tP3D _T3,long TexNr)
tWandPoly *CreateWandPoly(tWandVertice *_P1,tWandVertice *_P2,tWandVertice *_P3)
{
tWandPoly *Temp;
Temp=(tWandPoly*)malloc(sizeof(tWandPoly));
Temp->P1=_P1;
Temp->P2=_P3;
Temp->P3=_P2;
// Temp->TType=_TT_X;
Temp->Next=NULL;
Temp->Normal=GetNormalVek(Temp->P3->Pos,Temp->P2->Pos,Temp->P1->Pos);
// Temp->BoundBox=BeginBoundBox(NULL);
BeginBoundBox(&Temp->BoundBox);
AddToBoundBox(&Temp->BoundBox,&Temp->P1->Pos);
AddToBoundBox(&Temp->BoundBox,&Temp->P2->Pos);
AddToBoundBox(&Temp->BoundBox,&Temp->P3->Pos);
return(Temp);
}
tWandVertice *CreateWandVertice(tP3D ToPos)
{
tWandVertice *Temp;
Temp=(tWandVertice*) malloc(sizeof(tWandVertice));
Temp->Pos=ToPos;
Temp->WorldPos=ToPos;
Temp->Next=NULL;
Temp->Child=NULL;
return(Temp);
}
bool PInPoly(tP3D *Pos,tP3D *A,tP3D *B,tP3D *C)
{
__asm
{
xor eax,eax
mov esi,[Pos]
mov ebx,[A]
mov ecx,[B]
mov edx,[C]
fldz
fld dword ptr [ebx+tP3D.Y]
fmul dword ptr [ecx+tP3D.Z]
fld dword ptr [ecx+tP3D.Y]
fmul dword ptr [edx+tP3D.Z]
faddp st(1),st(0)
fld dword ptr [edx+tP3D.Y]
fmul dword ptr [ebx+tP3D.Z]
faddp st(1),st(0)
fld dword ptr [ebx+tP3D.Y]
fmul dword ptr [edx+tP3D.Z]
fsubp st(1),st(0)
fld dword ptr [ecx+tP3D.Y]
fmul dword ptr [ebx+tP3D.Z]
fsubp st(1),st(0)
fld dword ptr [edx+tP3D.Y]
fmul dword ptr [ecx+tP3D.Z]
fsubp st(1),st(0)
// T | 0
fld dword ptr [esi+tP3D.Y]
fmul dword ptr [ecx+tP3D.Z]
fld dword ptr [ecx+tP3D.Y]
fmul dword ptr [edx+tP3D.Z]
faddp st(1),st(0)
fld dword ptr [edx+tP3D.Y]
fmul dword ptr [esi+tP3D.Z]
faddp st(1),st(0)
fld dword ptr [esi+tP3D.Y]
fmul dword ptr [edx+tP3D.Z]
fsubp st(1),st(0)
fld dword ptr [ecx+tP3D.Y]
fmul dword ptr [esi+tP3D.Z]
fsubp st(1),st(0)
fld dword ptr [edx+tP3D.Y]
fmul dword ptr [ecx+tP3D.Z]
fsubp st(1),st(0)
// T1 | T | 0
fmul st(0),st(1)
fcomip st(0),st(2)
jb JumpOut
// T | 0
fld dword ptr [ebx+tP3D.Y]
fmul dword ptr [esi+tP3D.Z]
fld dword ptr [esi+tP3D.Y]
fmul dword ptr [edx+tP3D.Z]
faddp st(1),st(0)
fld dword ptr [edx+tP3D.Y]
fmul dword ptr [ebx+tP3D.Z]
faddp st(1),st(0)
fld dword ptr [ebx+tP3D.Y]
fmul dword ptr [edx+tP3D.Z]
fsubp st(1),st(0)
fld dword ptr [esi+tP3D.Y]
fmul dword ptr [ebx+tP3D.Z]
fsubp st(1),st(0)
fld dword ptr [edx+tP3D.Y]
fmul dword ptr [esi+tP3D.Z]
fsubp st(1),st(0)
// T2 | T | 0
fmul st(0),st(1)
fcomip st(0),st(2)
jb JumpOut
// T | 0
fld dword ptr [ebx+tP3D.Y]
fmul dword ptr [ecx+tP3D.Z]
fld dword ptr [ecx+tP3D.Y]
fmul dword ptr [esi+tP3D.Z]
faddp st(1),st(0)
fld dword ptr [esi+tP3D.Y]
fmul dword ptr [ebx+tP3D.Z]
faddp st(1),st(0)
fld dword ptr [ebx+tP3D.Y]
fmul dword ptr [esi+tP3D.Z]
fsubp st(1),st(0)
fld dword ptr [ecx+tP3D.Y]
fmul dword ptr [ebx+tP3D.Z]
fsubp st(1),st(0)
fld dword ptr [esi+tP3D.Y]
fmul dword ptr [ecx+tP3D.Z]
fsubp st(1),st(0)
// T3 | T | 0
fmul st(0),st(1)
fcomip st(0),st(2)
jb JumpOut
// T | 0
mov al,1
JumpOut:
fstp st(0)
fstp st(0)
}
}
long ClipPointAgainstLine(tP3D *NextPos,tP3D *_PSpeed,tWandVertice *P1,tWandVertice *P2,float MinAb,float MinAb2)
{
float L;
__asm
{
xor eax,eax
mov ebx,[P1]
mov ecx,[P2]
mov edx,[NextPos]
fld dword ptr [ecx+t_WandVertice.WorldPos.X]
fsub dword ptr [ebx+t_WandVertice.WorldPos.X]
// LineVekX
fld dword ptr [ecx+t_WandVertice.WorldPos.Y]
fsub dword ptr [ebx+t_WandVertice.WorldPos.Y]
// LineVekY | LineVekX
fld dword ptr [ecx+t_WandVertice.WorldPos.Z]
fsub dword ptr [ebx+t_WandVertice.WorldPos.Z]
// LineVekZ | LineVekY | LineVekX
fld dword ptr [edx+tP3D.X]
fsub dword ptr [ebx+t_WandVertice.WorldPos.X]
fmul st(0),st(3)
// E | LineVekZ | LineVekY | LineVekX
fld dword ptr [edx+tP3D.Y]
fsub dword ptr [ebx+t_WandVertice.WorldPos.Y]
fmul st(0),st(3)
faddp st(1),st(0)
// E | LineVekZ | LineVekY | LineVekX
fld dword ptr [edx+tP3D.Z]
fsub dword ptr [ebx+t_WandVertice.WorldPos.Z]
fmul st(0),st(2)
faddp st(1),st(0)
// E | LineVekZ | LineVekY | LineVekX
fld st(1)
fmul st(0),st(0)
// L | E | LineVekZ | LineVekY | LineVekX
fld st(3)
fmul st(0),st(0)
faddp st(1),st(0)
// L | E | LineVekZ | LineVekY | LineVekX
fld st(4)
fmul st(0),st(0)
faddp st(1),st(0)
// L | E | LineVekZ | LineVekY | LineVekX
fdivp st(1),st(0)
// t | LineVekZ | LineVekY | LineVekX
fldz
fcomip st(0),st(1)
jnbe JumpOut
fld1
fcomip st(0),st(1)
jb JumpOut
fmul st(1),st(0)
fmul st(2),st(0)
fmulp st(3),st(0)
// LineVekZ*t | LineVekY*t | LineVekX*t
fld st(0)
fadd dword ptr [ebx+t_WandVertice.WorldPos.Z]
fsub dword ptr [edx+tP3D.Z]
fst st(1)
fmul st(0),st(0)
// E | LZ | LineVekY*t | LineVekX*t
fld st(2)
fadd dword ptr [ebx+t_WandVertice.WorldPos.Y]
fsub dword ptr [edx+tP3D.Y]
fst st(3)
fmul st(0),st(0)
faddp st(1),st(0)
// E | LZ | LY | LineVekX*t
fld st(3)
fadd dword ptr [ebx+t_WandVertice.WorldPos.X]
fsub dword ptr [edx+tP3D.X]
fst st(4)
fmul st(0),st(0)
faddp st(1),st(0)
// E | LZ | LY | LX
fld dword ptr [MinAb2]
fcomip st(0),st(1)
jbe JumpOut2
fsqrt
fld st(0)
fsub dword ptr [MinAb]
fstp dword ptr [L]
fdiv st(1),st(0)
fdiv st(2),st(0)
fdivp st(3),st(0)
// LZ | LY | LX
fld st(0)
fstp dword ptr [HitNormal.Z]
fld st(1)
fstp dword ptr [HitNormal.Y]
fld st(2)
fstp dword ptr [HitNormal.X]
// LZ | LY | LX
fld dword ptr [L]
fmul st(1),st(0)
fmul st(2),st(0)
fmulp st(3),st(0)
// LZ*L | LY*L | LX*L
cmp [RutschAble],0
jne GoOn
// LZ*L | LY*L | LX*L
fld st(2)
fmul st(0),st(0)
// E | LZ*L | LY*L | LX*L
fld st(1)
fmul st(0),st(0)
faddp st(1),st(0)
// E | LZ*L | LY*L | LX*L
fld dword ptr [RutschQuad]
// RutschQuad | E | LZ*L | LY*L | LX*L
fcomip st(0),st(1)
jbe GoOn2
// E | LZ*L | LY*L | LX*L
fldz
// 0 | E | LZ*L | LY*L | LX*L
fst st(2)
fstp st(4)
// E | LZ*L | LY*L | LX*L
GoOn2:
fstp st(0)
GoOn:
// LZ*L | LY*L | LX*L
mov edi,[_PSpeed]
fadd dword ptr [edi+tP3D.Z]
fstp dword ptr [edi+tP3D.Z]
fadd dword ptr [edi+tP3D.Y]
fstp dword ptr [edi+tP3D.Y]
fadd dword ptr [edi+tP3D.X]
fstp dword ptr [edi+tP3D.X]
mov eax,1
jmp Ende
JumpOut2:
// fstp st(0)
JumpOut:
fstp st(0)
fstp st(0)
fstp st(0)
fstp st(0)
Ende:
}
}
long ClipPointAgainstVertice(tP3D *NextPos,tP3D *_PSpeed,tWandVertice *P1,float MinAb,float MinAb2)
{
float L;
__asm
{
xor eax,eax
mov ebx,[NextPos]
mov ecx,[P1]
fld dword ptr [ebx+tP3D.X]
fsub dword ptr [ecx+t_WandVertice.WorldPos.X]
fld dword ptr [ebx+tP3D.Y]
fsub dword ptr [ecx+t_WandVertice.WorldPos.Y]
fld dword ptr [ebx+tP3D.Z]
fsub dword ptr [ecx+t_WandVertice.WorldPos.Z]
// LZ | LY | LX
fld st(0)
fmul st(0),st(0)
// E | LZ | LY | LX
fld st(2)
fmul st(0),st(0)
faddp st(1),st(0)
// E | LZ | LY | LX
fld st(3)
fmul st(0),st(0)
faddp st(1),st(0)
// Ab
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -