From 602a0c5951050e7cce645534cb4f136cf9f4fee4 Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Thu, 17 Jun 2021 14:20:54 +0700 Subject: Rename source and build directory --- src/Decals.cpp | 375 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 375 insertions(+) create mode 100644 src/Decals.cpp (limited to 'src/Decals.cpp') diff --git a/src/Decals.cpp b/src/Decals.cpp new file mode 100644 index 0000000..3cebb4c --- /dev/null +++ b/src/Decals.cpp @@ -0,0 +1,375 @@ +#include "Decals.h" +#include "Textures.h" + +extern double multiplier; +extern bool slomo; +extern Fog fog; +extern bool blood; +extern float fogcolorr; +extern float fogcolorg; +extern float fogcolorb; +//Functions +extern float sinefluct; +extern int environment; +extern Model gunmodels[10]; +extern Camera camera; +extern float precipitationhorz; +extern float precipitationvert; +extern float precipitationdensity; +extern float snowdelay; + +int Decals::MakeDecal(int atype, XYZ location, float size, XYZ normal, int poly, Model *model, XYZ move, float rotation){ + int major=0; + float normalv[3]; + XYZ right; + XYZ up; + XYZ nothing; + XYZ axis[3]; + XYZ temp; + + nothing=0; + + axis[0].x=1; + axis[1].y=1; + axis[2].z=1; + + normalv[0]=abs(normal.x); + normalv[1]=abs(normal.y); + normalv[2]=abs(normal.z); + + + if(normalv[1]>normalv[major])major=1; + if(normalv[2]>normalv[major])major=2; + + if (normalv[0] == 1 || normalv[1] == 1 || normalv[2] == 1) + { + if ((major == 0 && normal.x > 0) || major == 1){ + right=0; + right.z=-1;} + else if (major == 0){ + right=0; + right.z=1;} + else { + right=0; + right.x=normal.z;} + } + else + CrossProduct(axis[major], normal, &right); + + CrossProduct(normal, right, &up); + Normalise(&up); + Normalise(&right); + + float count; + float count2; + float countinc=1/size; + if(countinc<.01)countinc=.01; + if(countinc>.2)countinc=.2; + float normaloffset=.02; + int good; + + numpoints[howmanydecals]=0; + points[howmanydecals*8+numpoints[howmanydecals]] = location + (nothing - right - up) * (size/3) /*+ normal/100*/; + texcoordsx[howmanydecals*8+numpoints[howmanydecals]] = 0; + texcoordsy[howmanydecals*8+numpoints[howmanydecals]] = 0; + if((move.x==0&&move.z==0&&rotation==0)|| + LineFacetd(points[howmanydecals*8+numpoints[howmanydecals]]+normal/25,points[howmanydecals*8+numpoints[howmanydecals]]-normal/25, model->vertex[model->Triangles[poly].vertex[0]], model->vertex[model->Triangles[poly].vertex[1]], model->vertex[model->Triangles[poly].vertex[2]],normal,&temp) + )numpoints[howmanydecals]++; + else { + good=-1; + count=1-countinc; + while(good==-1&&count>-1){ + texcoordsx[howmanydecals*8+numpoints[howmanydecals]] = 0; + texcoordsy[howmanydecals*8+numpoints[howmanydecals]] = .5-count/2; + points[howmanydecals*8+numpoints[howmanydecals]] = location + (nothing - right - up*count) * (size/3); + count-=countinc; + good=model->LineCheck2(points[howmanydecals*8+numpoints[howmanydecals]]+normal/25,points[howmanydecals*8+numpoints[howmanydecals]]-normal/25,&temp,move,rotation); + } + if(good!=-1)numpoints[howmanydecals]++; + good=-1; + count=1-countinc; + while(good==-1&&count>-1){ + texcoordsx[howmanydecals*8+numpoints[howmanydecals]] = .5-count/2; + texcoordsy[howmanydecals*8+numpoints[howmanydecals]] = 0; + points[howmanydecals*8+numpoints[howmanydecals]] = location + (nothing - right*count - up) * (size/3); + count-=countinc; + good=model->LineCheck2(points[howmanydecals*8+numpoints[howmanydecals]]+normal/25,points[howmanydecals*8+numpoints[howmanydecals]]-normal/25,&temp,move,rotation); + } + if(good!=-1)numpoints[howmanydecals]++; + if(good==-1){ + good=-1; + count2=1-countinc; + while(good==-1&&count2>-1){ + count=1-countinc; + while(good==-1&&count>-1){ + texcoordsx[howmanydecals*8+numpoints[howmanydecals]] = .5-count2/2; + texcoordsy[howmanydecals*8+numpoints[howmanydecals]] = .5-count/2; + points[howmanydecals*8+numpoints[howmanydecals]] = location + (nothing - right*count2 - up*count) * (size/3); + count-=countinc; + good=model->LineCheck2(points[howmanydecals*8+numpoints[howmanydecals]]+normal/25,points[howmanydecals*8+numpoints[howmanydecals]]-normal/25,&temp,move,rotation); + } + count2-=countinc; + } + if(good!=-1)numpoints[howmanydecals]++; + } + } + + points[howmanydecals*8+numpoints[howmanydecals]] = location + (nothing + right - up) * (size/3) /*+ normal/100*/; + texcoordsx[howmanydecals*8+numpoints[howmanydecals]] = 1; + texcoordsy[howmanydecals*8+numpoints[howmanydecals]] = 0; + if((move.x==0&&move.y==0&&move.z==0&&rotation==0)|| + LineFacetd(points[howmanydecals*8+numpoints[howmanydecals]]+normal/25,points[howmanydecals*8+numpoints[howmanydecals]]-normal/25, model->vertex[model->Triangles[poly].vertex[0]], model->vertex[model->Triangles[poly].vertex[1]], model->vertex[model->Triangles[poly].vertex[2]],normal,&temp) + )numpoints[howmanydecals]++; + else { + good=-1; + count=1-countinc; + while(good==-1&&count>-1){ + texcoordsx[howmanydecals*8+numpoints[howmanydecals]] = .5+count/2; + texcoordsy[howmanydecals*8+numpoints[howmanydecals]] = 0; + points[howmanydecals*8+numpoints[howmanydecals]] = location + (nothing + right*count - up) * (size/3); + count-=countinc; + good=model->LineCheck2(points[howmanydecals*8+numpoints[howmanydecals]]+normal/25,points[howmanydecals*8+numpoints[howmanydecals]]-normal/25,&temp,move,rotation); + } + if(good!=-1)numpoints[howmanydecals]++; + good=-1; + count=1-countinc; + while(good==-1&&count>-1){ + texcoordsx[howmanydecals*8+numpoints[howmanydecals]] = 1; + texcoordsy[howmanydecals*8+numpoints[howmanydecals]] = .5-count/2; + points[howmanydecals*8+numpoints[howmanydecals]] = location + (nothing + right - up*count) * (size/3); + count-=countinc; + good=model->LineCheck2(points[howmanydecals*8+numpoints[howmanydecals]]+normal/25,points[howmanydecals*8+numpoints[howmanydecals]]-normal/25,&temp,move,rotation); + } + if(good!=-1)numpoints[howmanydecals]++; + if(good==-1){ + good=-1; + count2=1-countinc; + while(good==-1&&count2>-1){ + count=1-countinc; + while(good==-1&&count>-1){ + texcoordsx[howmanydecals*8+numpoints[howmanydecals]] = .5+count2/2; + texcoordsy[howmanydecals*8+numpoints[howmanydecals]] = .5-count/2; + points[howmanydecals*8+numpoints[howmanydecals]] = location + (nothing + right*count2 - up*count) * (size/3); + count-=countinc; + good=model->LineCheck2(points[howmanydecals*8+numpoints[howmanydecals]]+normal/25,points[howmanydecals*8+numpoints[howmanydecals]]-normal/25,&temp,move,rotation); + } + count2-=countinc; + } + if(good!=-1)numpoints[howmanydecals]++; + } + } + + points[howmanydecals*8+numpoints[howmanydecals]] = location + (nothing + right + up) * (size/3) /*+ normal/100*/; + texcoordsx[howmanydecals*8+numpoints[howmanydecals]] = 1; + texcoordsy[howmanydecals*8+numpoints[howmanydecals]] = 1; + if((move.x==0&&move.y==0&&move.z==0&&rotation==0)|| + LineFacetd(points[howmanydecals*8+numpoints[howmanydecals]]+normal/25,points[howmanydecals*8+numpoints[howmanydecals]]-normal/25, model->vertex[model->Triangles[poly].vertex[0]], model->vertex[model->Triangles[poly].vertex[1]], model->vertex[model->Triangles[poly].vertex[2]],normal,&temp) + )numpoints[howmanydecals]++; + else { + good=-1; + count=1-countinc; + while(good==-1&&count>-1){ + texcoordsx[howmanydecals*8+numpoints[howmanydecals]] = 1; + texcoordsy[howmanydecals*8+numpoints[howmanydecals]] = .5+count/2; + points[howmanydecals*8+numpoints[howmanydecals]] = location + (nothing + right + up*count) * (size/3); + count-=countinc; + good=model->LineCheck2(points[howmanydecals*8+numpoints[howmanydecals]]+normal/25,points[howmanydecals*8+numpoints[howmanydecals]]-normal/25,&temp,move,rotation); + } + if(good!=-1)numpoints[howmanydecals]++; + good=-1; + count=1-countinc; + while(good==-1&&count>-1){ + texcoordsx[howmanydecals*8+numpoints[howmanydecals]] = .5+count/2; + texcoordsy[howmanydecals*8+numpoints[howmanydecals]] = 1; + points[howmanydecals*8+numpoints[howmanydecals]] = location + (nothing + right*count + up) * (size/3); + count-=countinc; + good=model->LineCheck2(points[howmanydecals*8+numpoints[howmanydecals]]+normal/25,points[howmanydecals*8+numpoints[howmanydecals]]-normal/25,&temp,move,rotation); + } + if(good!=-1)numpoints[howmanydecals]++; + if(good==-1){ + good=-1; + count2=1-countinc; + while(good==-1&&count2>-1){ + count=1-countinc; + while(good==-1&&count>-1){ + texcoordsx[howmanydecals*8+numpoints[howmanydecals]] = .5+count2/2; + texcoordsy[howmanydecals*8+numpoints[howmanydecals]] = .5+count/2; + points[howmanydecals*8+numpoints[howmanydecals]] = location + (nothing + right*count2 + up*count) * (size/3); + count-=countinc; + good=model->LineCheck2(points[howmanydecals*8+numpoints[howmanydecals]]+normal/25,points[howmanydecals*8+numpoints[howmanydecals]]-normal/25,&temp,move,rotation); + } + count2-=countinc; + } + if(good!=-1)numpoints[howmanydecals]++; + } + } + + points[howmanydecals*8+numpoints[howmanydecals]] = location + (nothing - right + up) * (size/3) /*+ normal/100*/; + texcoordsx[howmanydecals*8+numpoints[howmanydecals]] = 0; + texcoordsy[howmanydecals*8+numpoints[howmanydecals]] = 1; + if((move.x==0&&move.y==0&&move.z==0&&rotation==0)|| + LineFacetd(points[howmanydecals*8+numpoints[howmanydecals]]+normal/25,points[howmanydecals*8+numpoints[howmanydecals]]-normal/25, model->vertex[model->Triangles[poly].vertex[0]], model->vertex[model->Triangles[poly].vertex[1]], model->vertex[model->Triangles[poly].vertex[2]],normal,&temp) + )numpoints[howmanydecals]++; + else { + good=-1; + count=1-countinc; + while(good==-1&&count>-1){ + texcoordsx[howmanydecals*8+numpoints[howmanydecals]] = .5-count/2; + texcoordsy[howmanydecals*8+numpoints[howmanydecals]] = 1; + points[howmanydecals*8+numpoints[howmanydecals]] = location + (nothing - right*count + up) * (size/3); + count-=countinc; + good=model->LineCheck2(points[howmanydecals*8+numpoints[howmanydecals]]+normal/25,points[howmanydecals*8+numpoints[howmanydecals]]-normal/25,&temp,move,rotation); + } + if(good!=-1)numpoints[howmanydecals]++; + good=-1; + count=1-countinc; + while(good==-1&&count>-1){ + texcoordsx[howmanydecals*8+numpoints[howmanydecals]] = 0; + texcoordsy[howmanydecals*8+numpoints[howmanydecals]] = .5+count/2; + points[howmanydecals*8+numpoints[howmanydecals]] = location + (nothing - right + up*count) * (size/3); + count-=countinc; + good=model->LineCheck2(points[howmanydecals*8+numpoints[howmanydecals]]+normal/25,points[howmanydecals*8+numpoints[howmanydecals]]-normal/25,&temp,move,rotation); + } + if(good!=-1)numpoints[howmanydecals]++; + if(good==-1){ + good=-1; + count2=1-countinc; + while(good==-1&&count2>-1){ + count=1-countinc; + while(good==-1&&count>-1){ + texcoordsx[howmanydecals*8+numpoints[howmanydecals]] = .5-count2/2; + texcoordsy[howmanydecals*8+numpoints[howmanydecals]] = .5+count/2; + points[howmanydecals*8+numpoints[howmanydecals]] = location + (nothing - right*count2 + up*count) * (size/3); + count-=countinc; + good=model->LineCheck2(points[howmanydecals*8+numpoints[howmanydecals]]+normal/25,points[howmanydecals*8+numpoints[howmanydecals]]-normal/25,&temp,move,rotation); + } + count2-=countinc; + } + if(good!=-1)numpoints[howmanydecals]++; + } + } + for(int i=0;i=0){ + numpoints[which]=numpoints[howmanydecals-1]; + alivetime[which]=alivetime[howmanydecals-1]; + type[which]=type[howmanydecals-1]; + for(int i=0;i0){howmanydecals--;} + } + + return 0; +} + +void Decals::LoadBulletHoleTexture(char *fileName) +{ + bulletholetextureptr = loadTexture(fileName); +} + +void Decals::LoadBloodTexture(char *fileName, int which) +{ + bloodtextureptr[which] = loadTexture(fileName); +} + +void Decals::LoadCraterTexture(char *fileName) +{ + cratertextureptr = loadTexture(fileName); +} + +void Decals::DoStuff() +{ + for(int i=0;i10&&(type[i]==bullethole||type[i]==crater))DeleteDecal(i); + if(alivetime[i]>20&&(type[i]==bloodpool))DeleteDecal(i); + } +} + +void Decals::draw() +{ + glAlphaFunc(GL_GREATER, 0.01); + + float bloodpoolspeed=1; + + glDepthFunc(GL_LEQUAL); + glEnable(GL_BLEND); + glEnable(GL_CULL_FACE); + glEnable(GL_TEXTURE_2D); + glEnable(GL_LIGHTING); + glDepthMask(0); + glAlphaFunc(GL_GREATER, 0.01); + glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); + glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_POLYGON_OFFSET_FILL); + for(int i=0;i=bloodpoolspeed*.2&&alivetime[i]=bloodpoolspeed*.4&&alivetime[i]=bloodpoolspeed*.6&&alivetime[i]=bloodpoolspeed*.8&&alivetime[i]=bloodpoolspeed*1&&alivetime[i]=bloodpoolspeed*1.2&&alivetime[i]=bloodpoolspeed*1.4&&alivetime[i]=bloodpoolspeed*1.6&&alivetime[i]=bloodpoolspeed*1.8&&alivetime[i]=bloodpoolspeed*2.0)glBindTexture(GL_TEXTURE_2D, bloodtextureptr[10]); + if(type[i]==bloodpool&&alivetime[i]=bloodpoolspeed*2.0)glColor4f(1,1,1,20-alivetime[i]); + + glPushMatrix(); + glBegin(GL_TRIANGLE_FAN); + for(int j=0;j=bloodpoolspeed*.2&&alivetime[i]=bloodpoolspeed*.4&&alivetime[i]=bloodpoolspeed*.6&&alivetime[i]=bloodpoolspeed*.8&&alivetime[i]=bloodpoolspeed*1&&alivetime[i]=bloodpoolspeed*1.2&&alivetime[i]=bloodpoolspeed*1.4&&alivetime[i]=bloodpoolspeed*1.6&&alivetime[i]=bloodpoolspeed*1.8&&alivetime[i]