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

📄 leveledit.cpp

📁 一个96K的3D游戏源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
#include "stdio.h"
#include "stdlib.h"
#include <string.h>
#include <stdarg.h>
#include <math.h>
#include <windows.h>
#include <conio.h>
#include "music.h"
#include "maindefs.h"
#include <gl\gl.h>												// Header File For The OPenGL32 Library
#include <gl\glu.h>												// Header File For The GLu32 Library
#include <gl\glaux.h>												// Header File For The GLu32 Library
#include <time.h>												// For Random Seed
#include "MainNeHeLevel.h"												// Header File For NeHeGL
#include "MainGameLevel.h"
#include "SYSTEMIO.h"
#include "vectors.h"
#include "objekt.h"
#include "animation.h"
#include "Level.h"
#include "LevelPlus.h"
#include "LevelEdit.h"
#include "Texditor\TexCommander.h"
#include "Texditor\Papfilter.h"

// Prevent errors with Texditor
tImage *LoadedImage=NULL;
tLayer *TempLayer=NULL;
// 

bool InsertMove=true;
bool UnDoOn=true;

#define CamEntf 100.0
//#define ReduceFak 0.6

GLfloat		SunLightAmbient[]	= { 1, 1, 1};						// Ambient Light is 20% white
GLfloat		SunLightDiffuse[]	= { 1, 1, 1};
GLfloat		SunLightPosition[] = { 0.0f, 30.0f, 50.0f};						// Position is somewhat in front of screen
GLfloat		SunLightSpecular[] = { 1, 1, 1,0};						// Position is somewhat in front of screen

float MainRotAmount;

#define UndoSteps 5
tSector *UndoList[UndoSteps];

tSector *Level,*AktSector;
tCommand *CommandList;
tCommand *TempCommand;
bool ItemCreated=false;

typedef struct
{
	GLubyte Header[12];									// TGA File Header
} TGAHeader;


typedef struct
{
	GLubyte		header[6];								// First 6 Useful Bytes From The Header
	GLuint		bytesPerPixel;							// Holds Number Of Bytes Per Pixel Used In The TGA File
	GLuint		imageSize;								// Used To Store The Image Size When Setting Aside Ram
	GLuint		temp;									// Temporary Variable
	GLuint		type;	
	GLuint		Height;									//Height of Image
	GLuint		Width;									//Width ofImage
	GLuint		Bpp;									// Bits Per Pixel
} TGA;

TGAHeader tgaheader;									// TGA header
TGA tga;												// TGA image data



tSector *ResSec=NULL;
long ResAdd=0;
long ResNr=-1;
long OldMouse=-2;
char *TestString;
long AktVertice=0;
long ASNr;
long DrawNr;

long CFlags,CAttr;
tP3D ComPos,ComPosOld;

long SelV;
long SelO=-1;
long CamMode=0;
long MX=100,MY=100;
tP3D CPos,CLook,CVek;

GL_Window   *my_g_window;
tGrund		*Grund;
RECT		window;												// Storage For Window Dimensions

#define CamSpeed 0.4
float Roll=0;

long FramesPS=0;

//bool LoadTGA(Texture *, char *);

bool		 Key[256];
bool		 KeyPr[256];

bool MouseAdjust=false;
long MAStartX,MAStartY;
tP3D ModPos,OldModPos;
float MAX,MAY;
float OldTX,OldTY;

struct tMenuItem
{
	char Text[100];
	long X,Y;
	long X1,Y1,X2,Y2;
	float C1,C2,C3;
};

#define _Main_Menu 0
#define		_Create_Primitive	1
#define			_Create_Cube	11
#define			_Create_Plane	12
#define			_Create_Kegel	13
#define			_Create_Torus	14
#define			_Create_Cylinder 15
#define			_Create_Item	16
#define		_Modify				2
#define		    _Modify_Vertex	21
//#define			_Modellieren	22
#define			_Set_Material	23
#define			_Change_Flags	24
#define		_Select_Object		3
#define		_Make_Sub			4
#define		_Merge				5

long MenuMode=_Create_Primitive;

long TexSize=12;
#define _TexSize_Add 1

float TexXS=1;
float TexYS=1;
#define _TexS_Add 0.1

long MatNr=1;
long TexMode=2;

long Parts1=4;
long Parts1Min=1;
long Parts1Max=10000;
long _Parts1_Add=1;

float Parts2=0.3;
float Parts2Min=0.0;
float Parts2Max=1;
float _Parts2_Add=0.05;

long Parts3=6;
long Parts3Min=1;
long Parts3Max=10000;
long _Parts3_Add=1;

float Parts4=0.3;
float Parts4Min=0.0;
float Parts4Max=10;
float _Parts4_Add=0.05;

long Attr1=20;
#define _Attr1_Add 1
long Attr1Min=_Attr1_Add;
long Attr1Max=10000;

long Attr2=20;
#define _Attr2_Add 1
long Attr2Min=_Attr2_Add;
long Attr2Max=10000;

long Attr3=20;
#define _Attr3_Add 1
long Attr3Min=_Attr3_Add;
long Attr3Max=10000;

float Radius=1.5;
float RadiusMin=0.0;
float RadiusMax=100000;
float _Radius_Add=0.05;

long SubDivs=1;
#define _SubDivs_Add 1
long SubDivsMin=0;
long SubDivsMax=10;


tMenuItem MICreatePrimitive,MILoadLevel,MISaveLevel,MINewLevel,MIBack;
tMenuItem MIInsert;
tMenuItem MIUndo;
tMenuItem MIModify;
// PrimitiveMenuItems
	tMenuItem MIPlattform;
	tMenuItem MIPlane;
	tMenuItem MIKegel;
	tMenuItem MITorus;
	tMenuItem MICylinder;
	tMenuItem MIItem;
	tMenuItem MISetMaterial;
		tMenuItem MITexSize,MITexSizeX,MITexSizeY;
		tMenuItem MITexSphere,MITexCube,MITexCylinderX,MITexCylinderY,MITexCylinderZ;
// Modify
	tMenuItem MIParts1Plus,MIParts1Minus;
	tMenuItem MIParts2Plus,MIParts2Minus;
	tMenuItem MIParts3Plus,MIParts3Minus;
	tMenuItem MIParts4Plus,MIParts4Minus;
	tMenuItem MIAttr1Plus,MIAttr1Minus;
	tMenuItem MIAttr2Plus,MIAttr2Minus;
	tMenuItem MIAttr3Plus,MIAttr3Minus;
	tMenuItem MISubDivsPlus,MISubDivsMinus;

	tMenuItem MISecAttr;
	tMenuItem MISecAttr2;
	tMenuItem MISecAttr3;

		tMenuItem MIModifyVertex;
		tMenuItem MIRadiusPlus,MIRadiusMinus;
//		tMenuItem MIModellieren;
		tMenuItem MIDoIt;

tMenuItem MIClone;
tMenuItem MISelectObject;
tMenuItem MIMakeSub;
tMenuItem MIUnSub;
tMenuItem MIMerge;

tMenuItem MIChangeFlags;
tMenuItem MIDead;
tMenuItem MIWalkThrough;
tMenuItem MISkeletonNode;
tMenuItem MIPlayer;
tMenuItem MIEnemy1;
tMenuItem MIEnemy2;
tMenuItem MIEnemy3;
tMenuItem MIEnemy4;
tMenuItem MIEnemy5;
tMenuItem MIBumper;
tMenuItem MIFlamer;
tMenuItem MIWater;
tMenuItem MISwing;
tMenuItem MIMove;

tMenuItem MIBoxGun1;
tMenuItem MIBoxMediKit;
tMenuItem MIBoxContinue;
tMenuItem MIBoxLevEnd;
tMenuItem MIBoxGun2;

tMenuItem MITexSizePlus,MITexSizeMinus;
tMenuItem MITexXSPlus,MITexXSMinus;
tMenuItem MITexYSPlus,MITexYSMinus;
tMenuItem MISize,MISizeX,MISizeY,MISizeZ;
tMenuItem MIPos,MIPosXZ,MIPosY;
tMenuItem MIRotX,MIRotY,MIRotZ;
tMenuItem MIMMPos,MIMMPosXZ,MIMMPosY;

tMenuItem MIMatPlus,MIMatMinus;

typedef struct													// Create A Structure
{
	GLubyte	*imageData;											// Image Data (UP To 32 Bits)
	GLuint	bPP;												// Image Color DePth In Bits Per Pixel.
	GLuint	width;												// Image Width
	GLuint	height;												// Image Height
	GLuint	texID;												// Texture ID Used To Select A Texture
} TextureImage;													// Structure Name

TextureImage textures[100];										// Storage For 10 Textures
bool ScreenShot=false;
GLuint ScreenTex;
char LastFileName[80];

GLuint		base;												// Font DisPlay List
void CreateDisplayList(tGrund *Mesh)
{
	tWandPoly *Temp;

	if(Mesh==NULL) return;
	if(Mesh->DisplayListOn)
		glDeleteLists(Mesh->DisplayList,1);

	Mesh->DisplayList=glGenLists(1);
	glNewList(Mesh->DisplayList,GL_COMPILE);

		glBegin(GL_TRIANGLES);
		Temp=Mesh->Poly;
		while(Temp!=NULL)
		{
			{
				glNormal3f(Temp->P1->Normal.X,Temp->P1->Normal.Y,Temp->P1->Normal.Z);
				glTexCoord2f(Temp->T1.X,Temp->T1.Y); 
				glVertex3f(Temp->P1->WorldPos.X,Temp->P1->WorldPos.Y,Temp->P1->WorldPos.Z);
				glNormal3f(Temp->P2->Normal.X,Temp->P2->Normal.Y,Temp->P2->Normal.Z);
				glTexCoord2f(Temp->T2.X,Temp->T2.Y); 
				glVertex3f(Temp->P2->WorldPos.X,Temp->P2->WorldPos.Y,Temp->P2->WorldPos.Z);
				glNormal3f(Temp->P3->Normal.X,Temp->P3->Normal.Y,Temp->P3->Normal.Z);
				glTexCoord2f(Temp->T3.X,Temp->T3.Y); 
				glVertex3f(Temp->P3->WorldPos.X,Temp->P3->WorldPos.Y,Temp->P3->WorldPos.Z);
			}
			Temp=Temp->Next;
		}
		glEnd();
	glEndList();
	Mesh->DisplayListOn=true;
}
void SetResSec(long Nr,tSector *TempStart)
{
	tSector *T,*Temp;
	if(ResSec!=NULL) 
	{
		ResSec->Next=NULL;
		DestroySector(ResSec);
	}
	Temp=GetSubSectorNr(TempStart,Nr);

	ResSec=CopySector(Temp,NULL,true,false);
	ResSec->Next=NULL;

	ResAdd=0;
	T=Temp->Father->SubSector;
	while(T!=Temp)
	{
		ResAdd++;
		T=T->Next;
	}

}

GLuint EmptyTexture(long X,long Y)											// Create An Empty Texture
{
	GLuint txtnumber;											// Texture ID
	unsigned int* data;											// Stored Data

	// Create Storage Space For Texture Data (128x128x4)
	data = (unsigned int*)new GLuint[((X * Y)* 4 * sizeof(unsigned int))];
	ZeroMemory(data,((X * Y)* 4 * sizeof(unsigned int)));	// Clear Storage Memory

	glGenTextures(1, &txtnumber);								// Create 1 Texture
	glBindTexture(GL_TEXTURE_2D, txtnumber);					// Bind The Texture
	glTexImage2D(GL_TEXTURE_2D, 0, 4, X, Y, 0,
		GL_RGBA, GL_UNSIGNED_BYTE, data);						// Build Texture Using Information In data
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

	delete [] data;												// Release data

	return txtnumber;											// Return The Texture ID
}


void CreateMeshListDL(tMeshList *List)
{
	if(List==NULL) return;
	CreateDisplayList(List->Mesh);
	CreateMeshListDL(List->Next);
}

void CreateSkelNodeDL(tSkeletonNode *Temp)
{
	if(Temp==NULL) return;
	CreateMeshListDL(Temp->MeshList);
	CreateSkelNodeDL(Temp->Child);
	CreateSkelNodeDL(Temp->Next);
}

void CreateSectorDL(tSector *Temp,bool WithNext)
{
	if(Temp==NULL) return;
	CreateDisplayList(Temp->Mesh);
	CreateSectorDL(Temp->SubSector,true);
	if(WithNext)
		CreateSectorDL(Temp->Next,WithNext);
}
void CalcEnv(tGrund *Mesh,char Dir)
{
	tWandVertice *Temp;
	tWandPoly *TempP;
	tP3D Normal;
	float TempF;
	if(Mesh==NULL) return;
	Temp=Mesh->Vertice;
	while(Temp!=NULL)
	{
		Normal=Temp->Normal;
		Norm(&Normal);
		if(Dir==1)
		{
			TempF=Normal.Z;
			Normal.Z=Normal.Y;
			Normal.Y=Normal.X;
			Normal.X=TempF;
		}
//		SetTexPos(Normal,&Temp->EnvTex);
		SetTexPos(Normal,&Temp->TexPos);
		Temp=Temp->Next;
	}
	TempP=Mesh->Poly;
	while(TempP!=NULL)
	{
		TempP->Env1=TempP->P1->TexPos;
		TempP->Env2=TempP->P2->TexPos;
		TempP->Env3=TempP->P3->TexPos;
/*
		TempP->Env1=TempP->P1->EnvTex;
		TempP->Env2=TempP->P2->EnvTex;
		TempP->Env3=TempP->P3->EnvTex;
*/
		if((fabs(TempP->Env1.X-TempP->Env2.X)>0.5)||(fabs(TempP->Env1.X-TempP->Env3.X)>0.5)||(fabs(TempP->Env3.X-TempP->Env2.X)>0.5))
		{
			if(TempP->Env1.X<0.5) TempP->Env1.X+=1.0;
			if(TempP->Env2.X<0.5) TempP->Env2.X+=1.0;
			if(TempP->Env3.X<0.5) TempP->Env3.X+=1.0;
		}
		TempP=TempP->Next;
	}
}

void SetMesh(tGrund *Mesh)
{
	tWandVertice *Temp;
	tP3D Normal;
	if(Mesh==NULL) return;
	Temp=Mesh->Vertice;
	while(Temp!=NULL)
	{
		Temp->WorldPos=Temp->Pos;
		Temp=Temp->Next;
	}
	CalcNormalsBasedOnPolys(Mesh);
	CalcEnv(Mesh,1);
}

void SetList(tMeshList *List)
{
	if(List==NULL) return;
	SetMesh(List->Mesh);
	SetList(List->Next);
}

void SetSkelList(tSkelList *List)
{
	if(List==NULL) return;
	SetList(List->Node->MeshList);
	SetSkelList(List->Next);
}

void SetSectorList(tSector *List)
{
	if(List==NULL) return;
	List->ModPos=vNull;
	CalcEnv(List->Mesh,0);
	SetSectorList(List->SubSector);
	SetSectorList(List->Next);
}

⌨️ 快捷键说明

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