📄 particlesys.cpp
字号:
#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 "Particlesys.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 "NeHeGL.h" // Header File For NeHeGL
#include "lesson32.h"
#include "SYSTEMIO.h"
#include "vectors.h"
#include "objekt.h"
#include "animation.h"
#include "AnimationPlus.h"
#include "level.h"
#include "BCLS.h"
#include "texditor\PapFilter.h"
tImage *LoadedImage=NULL;
tLayer *TempLayer=NULL;
unsigned char *LevelName=(unsigned char*)BCLSPIDER;
typedef struct // Line - Definition
{
long P1,P2; // Punkte der Linie
char Tag; // 0-Normal 1-Skel
} tSimpleLine;
typedef struct
{
long P1,P2,P3;
float C1,C2,C3;
} tSimplePoly;
#define NullChar '0';
long ViewMode=0;
long Points;
long Lines;
long Polys;
long OldFrame;
tSimpleLine *Line;
tSimplePoly *Poly;
bool SkelTag[100000];
tP3D *Point;
tP3D PPos,PRot;
long SelV,LastActive,BasePoint;
tObjekt *Obj,*Frame1,*Frame2,*Ghost;
float Roll=0;
float PSpeed=0.5;
long PlayLoop=65;
char ShowGhost=0;
bool ShowSplines=true;
bool PlayReal=false;
bool ShowTexture=false;
bool InsertFrame=false;
tP3D SkelDruck[100];
tAnimation *Animation,*BaseAni;
bool Playing=false;
long PlayPos;
long PlaySpeed=1;
long gFrame=0;
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[10]; // Storage For 10 Textures
GLuint base; // Font DisPlay List
void CalcMesh(tGrund *Mesh,tOMatrix Matrix,tP3D Pos)
{
tWandVertice *Temp;
Temp=Mesh->Vertice;
while(Temp!=NULL)
{
Temp->WorldPos=vAdd(Pos,CalcRealPosition(Temp->Pos,&Matrix));
Temp=Temp->Next;
}
// CalcNormalsBasedOnPolys(Mesh);
}
void CalcMeshList(tMeshList *Mesh,tOMatrix Matrix,tP3D Pos)
{
if(Mesh==NULL) return;
if(Mesh->Mesh!=NULL)
{
CalcMesh(Mesh->Mesh,Matrix,Pos);
}
CalcMeshList(Mesh->Next,Matrix,Pos);
}
void CalcSkelMesh(tSkeletonNode *Temp)
{
if(Temp==NULL) return;
CalcMeshList(Temp->MeshList,Temp->Matrix,Temp->Pos);
CalcSkelMesh(Temp->Child);
CalcSkelMesh(Temp->Next);
}
void SetSkeletonNode(tSkeletonNode *Temp,tP3D Pos)
{
tP3D NPos;
if(Temp->Father==NULL) return;
NPos=vSub(Pos,Temp->Father->Pos);
Temp->OrgPos=CalcRelPosition(NPos,&Temp->Father->Matrix);
Temp->Pos=Pos;
Temp->Matrix=CalcNewMatrix(Temp->Father->Pos,Temp->Pos,&Temp->Father->Matrix,Temp->Roll);
if(Temp->Child!=NULL)
ReCalcSkelNode(Temp->Child,&Temp->Matrix,&Temp->Pos,0);
}
void TestMessage()
{
MessageBox (HWND_DESKTOP, "Test Message", "B-Clopd3D Interrupted", MB_OK | MB_ICONEXCLAMATION);
}
bool LoadTGA(TextureImage *texture, char *filename) // Loads A TGA File Into Memory
{
GLubyte TGAheader[12]={0,0,2,0,0,0,0,0,0,0,0,0}; // UncomPressed TGA Header
GLubyte TGAcomPare[12]; // Used To ComPare TGA Header
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=GL_RGBA; // Set The Default GL Mode To RBGA (32 BPP)
FILE *file = fopen(filename, "rb"); // OPen The TGA File
if( file==NULL || // Does File Even Exist?
fread(TGAcomPare,1,sizeof(TGAcomPare),file)!=sizeof(TGAcomPare) || // Are There 12 Bytes To Read?
memcmp(TGAheader,TGAcomPare,sizeof(TGAheader))!=0 || // Does The Header Match What We Want?
fread(header,1,sizeof(header),file)!=sizeof(header)) // If So Read Next 6 Header Bytes
{
if (file == NULL) // Did The File Even Exist? *Added Jim Strong*
return FALSE; // Return False
else // Otherwise
{
fclose(file); // If Anything Failed, Close The File
return FALSE; // Return False
}
}
texture->width = header[1] * 256 + header[0]; // Determine The TGA Width (highbyte*256+lowbyte)
texture->height = header[3] * 256 + header[2]; // Determine The TGA Height (highbyte*256+lowbyte)
if( texture->width <=0 || // Is The Width Less Than Or Equal To Zero
texture->height <=0 || // Is The Height Less Than Or Equal To Zero
(header[4]!=24 && header[4]!=32)) // Is The TGA 24 or 32 Bit?
{
fclose(file); // If Anything Failed, Close The File
return FALSE; // Return False
}
texture->bPP = header[4]; // Grab The TGA's Bits Per Pixel (24 or 32)
bytesPerPixel = texture->bPP/8; // Divide By 8 To Get The Bytes Per Pixel
imageSize = texture->width*texture->height*bytesPerPixel; // Calculate The Memory Required For The TGA Data
texture->imageData=(GLubyte *)malloc(imageSize); // Reserve Memory To Hold The TGA Data
if( texture->imageData==NULL || // Does The Storage Memory Exist?
fread(texture->imageData, 1, imageSize, file)!=imageSize) // Does The Image Size Match The Memory Reserved?
{
if(texture->imageData!=NULL) // Was Image Data Loaded
free(texture->imageData); // If So, Release The Image Data
fclose(file); // Close The File
return FALSE; // Return False
}
for(GLuint i=0; i<int(imageSize); i+=bytesPerPixel) // LooP Through The Image Data
{ // SwaPs The 1st And 3rd Bytes ('R'ed and 'B'lue)
temP=texture->imageData[i]; // TemPorarily Store The Value At Image Data 'i'
texture->imageData[i] = texture->imageData[i + 2]; // Set The 1st Byte To The Value Of The 3rd Byte
texture->imageData[i + 2] = temP; // Set The 3rd Byte To The Value In 'temP' (1st Byte Value)
}
fclose (file); // Close The File
// Build A Texture From The Data
glGenTextures(1, &texture[0].texID); // Generate OPenGL texture IDs
glBindTexture(GL_TEXTURE_2D, texture[0].texID); // Bind Our Texture
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtered
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtered
if (texture[0].bPP==24) // Was The TGA 24 Bits
{
tyPe=GL_RGB; // If So Set The 'tyPe' To GL_RGB
}
glTexImage2D(GL_TEXTURE_2D, 0, tyPe, texture[0].width, texture[0].height, 0, tyPe, GL_UNSIGNED_BYTE, texture[0].imageData);
return true; // Texture Building Went Ok, Return True
}
GLvoid BuildFont(GLvoid) // Build Our Font DisPlay List
{
base=glGenLists(95); // Creating 95 DisPlay Lists
glBindTexture(GL_TEXTURE_2D, textures[9].texID); // Bind Our Font Texture
for (int looP=0; looP<95; looP++) // LooP Through All 95 Lists
{
float cx=float(looP%16)/16.0f; // X Position Of Current Character
float cy=float(looP/16)/8.0f; // Y Position Of Current Character
glNewList(base+looP,GL_COMPILE); // Start Building A List
glBegin(GL_QUADS); // Use A Quad For Each Character
glTexCoord2f(cx, 1.0f-cy-0.120f); glVertex2i(0,0); // Texture / Vertex Coord (Bottom Left)
glTexCoord2f(cx+0.0625f, 1.0f-cy-0.120f); glVertex2i(16,0); // Texutre / Vertex Coord (Bottom Right)
glTexCoord2f(cx+0.0625f, 1.0f-cy); glVertex2i(16,16);// Texture / Vertex Coord (ToP Right)
glTexCoord2f(cx, 1.0f-cy); glVertex2i(0,16); // Texture / Vertex Coord (ToP Left)
glEnd(); // Done Building Our Quad (Character)
glTranslated(10,0,0); // Move To The Right Of The Character
glEndList(); // Done Building The DisPlay List
} // LooP Until All 256 Are Built
}
GLvoid glPrint(GLint x, GLint y, const char *string, ...) // Where The Printing HaPPens
{
char text[256]; // Holds Our String
va_list aP; // Pointer To List Of Arguments
if (string == NULL) // If There's No Text
return; // Do Nothing
va_start(aP, string); // Parses The String For Variables
vsprintf(text, string, aP); // And Converts Symbols To Actual Numbers
va_end(aP); // Results Are Stored In Text
glBindTexture(GL_TEXTURE_2D, textures[9].texID); // Select Our Font Texture
glPushMatrix(); // Store The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
glTranslated(x,y,0); // Position The Text (0,0 - Bottom Left)
glListBase(base-32); // Choose The Font Set
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The DisPlay List Text
glPopMatrix(); // Restore The Old Projection Matrix
}
void InitText()
{
glEnable(GL_TEXTURE_2D); // Enable Texture MaPPing
glDisable(GL_DEPTH_TEST); // Disables DePth Testing
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glPushMatrix(); // Store The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
glOrtho(0,640,0,480,-1,1); // Set UP An Ortho Screen
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glPushMatrix(); // Store The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
glOrtho(0,640,0,480,-1,1); // Set UP An Ortho Screen
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
}
void ScanForDoublePoints()
{
long I,K,M;
for(I=0;I<Points-1;I++)
{
for(K=I+1;K<Points;K++)
{
if(AbstandP((Point+I),(Point+K))==0)
{
for(M=0;M<Lines;M++)
{
if(((Line+M)->P1==K)|((Line+M)->P2==K))
{
if(((Line+M)->P1==K)) (Line+M)->P1=I;
if(((Line+M)->P2==K)) (Line+M)->P2=I;
}
}
for(M=0;M<Lines;M++)
{
if(((Line+M)->P1==(Points-1))|((Line+M)->P2==(Points-1)))
{
if(((Line+M)->P1==(Points-1))) (Line+M)->P1=K;
if(((Line+M)->P2==(Points-1))) (Line+M)->P2=K;
}
}
for(M=0;M<Polys;M++)
{
if(((Poly+M)->P1==K)|((Poly+M)->P2==K)|((Poly+M)->P3==K))
{
if(((Poly+M)->P1==K)) (Poly+M)->P1=I;
if(((Poly+M)->P2==K)) (Poly+M)->P2=I;
if(((Poly+M)->P3==K)) (Poly+M)->P3=I;
}
}
for(M=0;M<Polys;M++)
{
if(((Poly+M)->P1==(Points-1))|((Poly+M)->P2==(Points-1))|((Poly+M)->P3==(Points-1)))
{
if(((Poly+M)->P1==(Points-1))) (Poly+M)->P1=K;
if(((Poly+M)->P2==(Points-1))) (Poly+M)->P2=K;
if(((Poly+M)->P3==(Points-1))) (Poly+M)->P3=K;
}
}
(Point+K)->X=(Point+(Points-1))->X;
(Point+K)->Y=(Point+(Points-1))->Y;
(Point+K)->Z=(Point+(Points-1))->Z;
K--;
Points--;
}
}
}
}
void SaveSkeletonNode(FILE *F,tSkeletonNode *Temp)
{
fwrite(Temp,sizeof(tSkeletonNode),1,F);
if(Temp->Child!=NULL) SaveSkeletonNode(F,Temp->Child);
if(Temp->Next!=NULL) SaveSkeletonNode(F,Temp->Next);
}
void SaveModel(char *fname)
{
FILE *F;
fpos_t Pos;
if(strchr(fname,'.')==NULL)
strcat(fname,".b3d");
F=fopen(fname,"wb");
fwrite(Obj,sizeof(tObjekt),1,F);
SaveSkeletonNode(F,Obj->Skel);
fclose(F);
}
void LoadModelToObj(char *fname) // L鋎t ne .b3d
{
/*
if(Obj!=NULL) Obj=DelObj(Obj);
Obj=LoadModel(fname);
if(Ghost!=NULL) Ghost=DelObj(Ghost);
Ghost=CopyObject(Obj);
UpDateAnimList(Obj,Animation,gFrame);
*/
}
/*
void LoadPureModel(char *fname) // L鋎t ne .dat
{
long P,S,M,I,K;
char T;
t_File_Handle *F;
F=Load_File(fname);
FileRead(F,&P,4);
FileRead(F,&S,4);
FileRead(F,&K,4);
M=sizeof(tP3D)*P;
Point=(tP3D*) malloc(M);
M=sizeof(tSimpleLine)*S;
Line=(tSimpleLine*) malloc(M);
M=sizeof(tSimplePoly)*K;
Poly=(tSimplePoly*) malloc(M);
Points=P;
Lines=S;
Polys=K;
for(I=0;I<P;I++)
{
FileRead(F,&M,4);
(Point+I)->X=M;
(Point+I)->X/=4096/4;
FileRead(F,&M,4);
(Point+I)->Y=M;
(Point+I)->Y/=4096/4;
FileRead(F,&M,4);
(Point+I)->Z=M;
(Point+I)->Z/=4096/4;
}
for(I=0;I<S;I++)
{
FileRead(F,&M,4);
(Line+I)->P1=M;
FileRead(F,&M,4);
(Line+I)->P2=M;
FileRead(F,&T,1);
(Line+I)->Tag=T;
}
for(I=0;I<K;I++)
{
FileRead(F,&M,4);
(Poly+I)->P1=M;
FileRead(F,&M,4);
(Poly+I)->P2=M;
FileRead(F,&M,4);
(Poly+I)->P3=M;
FileRead(F,&M,4);
(Poly+I)->C1=M;
(Poly+I)->C1/=255;
FileRead(F,&M,4);
(Poly+I)->C2=M;
(Poly+I)->C2/=255;
FileRead(F,&M,4);
(Poly+I)->C3=M;
(Poly+I)->C3/=255;
}
Close_File(F);
ScanForDoublePoints();
for(I=0;I<Lines;I++)
{
if((Line+I)->Tag==1)
{
SkelTag[(Line+I)->P1]=true;
SkelTag[(Line+I)->P2]=true;
} else
{
SkelTag[(Line+I)->P1]=false;
SkelTag[(Line+I)->P2]=false;
}
}
}
*/
void LoadDaAnimation(char *DatName)
{
Animation=LoadAnimation(DatName,BaseAni);
StartAnimationPlay(Obj,Animation);
}
void LoadDaBaseAnimation(char *DatName)
{
/*
Animation=LoadAnimation(DatName);
StartAnimationPlay(Obj,Animation);
*/
BaseAni=LoadBaseAnimation(Obj,DatName);
// LoadBaseAnimation(Obj,DatName);
}
void SaveDaAnimation(char *DatName)
{
SaveAnimation(DatName,Animation);
}
void DoneText()
{
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glPopMatrix(); // Restore The Old Projection Matrix
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glPopMatrix(); // Restore The Old Projection Matrix
glEnable(GL_DEPTH_TEST); // Enables DePth Testing
}
void DeInitEngine()
{
glDeleteLists(base,95); // Delete All 95 Font DisPlay Lists
}
void DrawSplines()
{
long I,K,M;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glMatrixMode (GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity (); // Reset The Modelview Matrix
/*
glRotatef(PRot.X,1,0,0);
glRotatef(PRot.Y,0,1,0);
glRotatef(PRot.Z,0,0,1);
glTranslatef(PPos.X,PPos.Y,PPos.Z); // Move Left 1.5 Units And Into The Screen 6.0
*/
// gluLookAt(0,0,0,0,0,1,sin(Roll),cos(Roll),0);
gluLookAt(0,0,0,PRot.X,PRot.Y,PRot.Z,sin(Roll),cos(Roll),0);
glTranslatef(PPos.X,PPos.Y,PPos.Z); // Move Left 1.5 Units And Into The Screen 6.0
I=0;
glDisable(GL_TEXTURE_2D); // Enable Texture MaPPing
glBegin(GL_LINES); // Start Drawing Our Player Using Lines
for(M=0;M<Lines;M++)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -