-void Model::MakeDecal(int atype, XYZ where,float size, float opacity, float rotation){
- if(decals){
- if(type!=decalstype)return;
-
- static float placex,placez;
- static XYZ rot;
- //static XYZ point,point1,point2;
- static float distance;
- static int i,j;
-
- if(opacity>0)
- if(findDistancefast(&where,&boundingspherecenter)<(boundingsphereradius+size)*(boundingsphereradius+size))
- for(i=0;i<TriangleNum;i++){
- distance=abs(((facenormals[i].x*where.x)+(facenormals[i].y*where.y)+(facenormals[i].z*where.z)-((facenormals[i].x*vertex[Triangles[i].vertex[0]].x)+(facenormals[i].y*vertex[Triangles[i].vertex[0]].y)+(facenormals[i].z*vertex[Triangles[i].vertex[0]].z))));
- if(distance<.02&&abs(facenormals[i].y)>abs(facenormals[i].x)&&abs(facenormals[i].y)>abs(facenormals[i].z)){
- decalposition[numdecals]=where;
- decaltype[numdecals]=atype;
- decalrotation[numdecals]=rotation;
- decalalivetime[numdecals]=0;
- decalopacity[numdecals]=opacity-distance/10;
-
- if(decalopacity[numdecals>0]){
- placex=vertex[Triangles[i].vertex[0]].x;
- placez=vertex[Triangles[i].vertex[0]].z;
-
- decaltexcoords[numdecals][0][0]=(placex-where.x)/(size)/2+.5;
- decaltexcoords[numdecals][0][1]=(placez-where.z)/(size)/2+.5;
-
- decalvertex[numdecals][0].x=placex;
- decalvertex[numdecals][0].z=placez;
- decalvertex[numdecals][0].y=vertex[Triangles[i].vertex[0]].y;
-
-
- placex=vertex[Triangles[i].vertex[1]].x;
- placez=vertex[Triangles[i].vertex[1]].z;
-
- decaltexcoords[numdecals][1][0]=(placex-where.x)/(size)/2+.5;
- decaltexcoords[numdecals][1][1]=(placez-where.z)/(size)/2+.5;
-
- decalvertex[numdecals][1].x=placex;
- decalvertex[numdecals][1].z=placez;
- decalvertex[numdecals][1].y=vertex[Triangles[i].vertex[1]].y;
-
-
- placex=vertex[Triangles[i].vertex[2]].x;
- placez=vertex[Triangles[i].vertex[2]].z;
-
- decaltexcoords[numdecals][2][0]=(placex-where.x)/(size)/2+.5;
- decaltexcoords[numdecals][2][1]=(placez-where.z)/(size)/2+.5;
-
- decalvertex[numdecals][2].x=placex;
- decalvertex[numdecals][2].z=placez;
- decalvertex[numdecals][2].y=vertex[Triangles[i].vertex[2]].y;
-
- if(!(decaltexcoords[numdecals][0][0]<0&&decaltexcoords[numdecals][1][0]<0&&decaltexcoords[numdecals][2][0]<0))
- if(!(decaltexcoords[numdecals][0][1]<0&&decaltexcoords[numdecals][1][1]<0&&decaltexcoords[numdecals][2][1]<0))
- if(!(decaltexcoords[numdecals][0][0]>1&&decaltexcoords[numdecals][1][0]>1&&decaltexcoords[numdecals][2][0]>1))
- if(!(decaltexcoords[numdecals][0][1]>1&&decaltexcoords[numdecals][1][1]>1&&decaltexcoords[numdecals][2][1]>1))
- {
- if(decalrotation[numdecals]){
- for(j=0;j<3;j++){
- rot.y=0;
- rot.x=decaltexcoords[numdecals][j][0]-.5;
- rot.z=decaltexcoords[numdecals][j][1]-.5;
- rot=DoRotation(rot,0,-decalrotation[numdecals],0);
- decaltexcoords[numdecals][j][0]=rot.x+.5;
- decaltexcoords[numdecals][j][1]=rot.z+.5;
- }
- }
- if(numdecals<max_model_decals-1)numdecals++;
- }
- }
- }
- else if(distance<.02&&abs(facenormals[i].x)>abs(facenormals[i].y)&&abs(facenormals[i].x)>abs(facenormals[i].z)){
- decalposition[numdecals]=where;
- decaltype[numdecals]=atype;
- decalrotation[numdecals]=rotation;
- decalalivetime[numdecals]=0;
- decalopacity[numdecals]=opacity-distance/10;
-
- if(decalopacity[numdecals>0]){
- placex=vertex[Triangles[i].vertex[0]].y;
- placez=vertex[Triangles[i].vertex[0]].z;
-
- decaltexcoords[numdecals][0][0]=(placex-where.y)/(size)/2+.5;
- decaltexcoords[numdecals][0][1]=(placez-where.z)/(size)/2+.5;
-
- decalvertex[numdecals][0].x=vertex[Triangles[i].vertex[0]].x;
- decalvertex[numdecals][0].z=placez;
- decalvertex[numdecals][0].y=placex;
-
-
- placex=vertex[Triangles[i].vertex[1]].y;
- placez=vertex[Triangles[i].vertex[1]].z;
-
- decaltexcoords[numdecals][1][0]=(placex-where.y)/(size)/2+.5;
- decaltexcoords[numdecals][1][1]=(placez-where.z)/(size)/2+.5;
-
- decalvertex[numdecals][1].x=vertex[Triangles[i].vertex[1]].x;
- decalvertex[numdecals][1].z=placez;
- decalvertex[numdecals][1].y=placex;
-
-
- placex=vertex[Triangles[i].vertex[2]].y;
- placez=vertex[Triangles[i].vertex[2]].z;
-
- decaltexcoords[numdecals][2][0]=(placex-where.y)/(size)/2+.5;
- decaltexcoords[numdecals][2][1]=(placez-where.z)/(size)/2+.5;
-
- decalvertex[numdecals][2].x=vertex[Triangles[i].vertex[2]].x;
- decalvertex[numdecals][2].z=placez;
- decalvertex[numdecals][2].y=placex;
-
- if(!(decaltexcoords[numdecals][0][0]<0&&decaltexcoords[numdecals][1][0]<0&&decaltexcoords[numdecals][2][0]<0))
- if(!(decaltexcoords[numdecals][0][1]<0&&decaltexcoords[numdecals][1][1]<0&&decaltexcoords[numdecals][2][1]<0))
- if(!(decaltexcoords[numdecals][0][0]>1&&decaltexcoords[numdecals][1][0]>1&&decaltexcoords[numdecals][2][0]>1))
- if(!(decaltexcoords[numdecals][0][1]>1&&decaltexcoords[numdecals][1][1]>1&&decaltexcoords[numdecals][2][1]>1))
- {
- if(decalrotation[numdecals]){
- for(j=0;j<3;j++){
- rot.y=0;
- rot.x=decaltexcoords[numdecals][j][0]-.5;
- rot.z=decaltexcoords[numdecals][j][1]-.5;
- rot=DoRotation(rot,0,-decalrotation[numdecals],0);
- decaltexcoords[numdecals][j][0]=rot.x+.5;
- decaltexcoords[numdecals][j][1]=rot.z+.5;
- }
- }
- if(numdecals<max_model_decals-1)numdecals++;
- }
- }
- }
- else if(distance<.02&&abs(facenormals[i].z)>abs(facenormals[i].y)&&abs(facenormals[i].z)>abs(facenormals[i].x)){
- decalposition[numdecals]=where;
- decaltype[numdecals]=atype;
- decalrotation[numdecals]=rotation;
- decalalivetime[numdecals]=0;
- decalopacity[numdecals]=opacity-distance/10;
-
- if(decalopacity[numdecals>0]){
- placex=vertex[Triangles[i].vertex[0]].x;
- placez=vertex[Triangles[i].vertex[0]].y;
-
- decaltexcoords[numdecals][0][0]=(placex-where.x)/(size)/2+.5;
- decaltexcoords[numdecals][0][1]=(placez-where.y)/(size)/2+.5;
-
- decalvertex[numdecals][0].x=placex;
- decalvertex[numdecals][0].z=vertex[Triangles[i].vertex[0]].z;
- decalvertex[numdecals][0].y=placez;
-
-
- placex=vertex[Triangles[i].vertex[1]].x;
- placez=vertex[Triangles[i].vertex[1]].y;
-
- decaltexcoords[numdecals][1][0]=(placex-where.x)/(size)/2+.5;
- decaltexcoords[numdecals][1][1]=(placez-where.y)/(size)/2+.5;
-
- decalvertex[numdecals][1].x=placex;
- decalvertex[numdecals][1].z=vertex[Triangles[i].vertex[1]].z;
- decalvertex[numdecals][1].y=placez;
-
-
- placex=vertex[Triangles[i].vertex[2]].x;
- placez=vertex[Triangles[i].vertex[2]].y;
-
- decaltexcoords[numdecals][2][0]=(placex-where.x)/(size)/2+.5;
- decaltexcoords[numdecals][2][1]=(placez-where.y)/(size)/2+.5;
-
- decalvertex[numdecals][2].x=placex;
- decalvertex[numdecals][2].z=vertex[Triangles[i].vertex[2]].z;
- decalvertex[numdecals][2].y=placez;
-
- if(!(decaltexcoords[numdecals][0][0]<0&&decaltexcoords[numdecals][1][0]<0&&decaltexcoords[numdecals][2][0]<0))
- if(!(decaltexcoords[numdecals][0][1]<0&&decaltexcoords[numdecals][1][1]<0&&decaltexcoords[numdecals][2][1]<0))
- if(!(decaltexcoords[numdecals][0][0]>1&&decaltexcoords[numdecals][1][0]>1&&decaltexcoords[numdecals][2][0]>1))
- if(!(decaltexcoords[numdecals][0][1]>1&&decaltexcoords[numdecals][1][1]>1&&decaltexcoords[numdecals][2][1]>1))
- {
- if(decalrotation[numdecals]){
- for(j=0;j<3;j++){
- rot.y=0;
- rot.x=decaltexcoords[numdecals][j][0]-.5;
- rot.z=decaltexcoords[numdecals][j][1]-.5;
- rot=DoRotation(rot,0,-decalrotation[numdecals],0);
- decaltexcoords[numdecals][j][0]=rot.x+.5;
- decaltexcoords[numdecals][j][1]=rot.z+.5;
- }
- }
- if(numdecals<max_model_decals-1)numdecals++;
- }
- }
- }
- }
- }
+void Model::MakeDecal(int atype, XYZ where, float size, float opacity, float rotation)
+{
+ if (decals) {
+ if (type != decalstype)
+ return;
+
+ static float placex, placez;
+ static XYZ rot;
+ //static XYZ point,point1,point2;
+ static float distance;
+ static int i, j;
+
+ if (opacity > 0)
+ if (distsq(&where, &boundingspherecenter) < (boundingsphereradius + size) * (boundingsphereradius + size))
+ for (i = 0; i < TriangleNum; i++) {
+ distance = abs(((facenormals[i].x * where.x) + (facenormals[i].y * where.y) + (facenormals[i].z * where.z) - ((facenormals[i].x * vertex[Triangles[i].vertex[0]].x) + (facenormals[i].y * vertex[Triangles[i].vertex[0]].y) + (facenormals[i].z * vertex[Triangles[i].vertex[0]].z))));
+ if (distance < .02 && abs(facenormals[i].y) > abs(facenormals[i].x) && abs(facenormals[i].y) > abs(facenormals[i].z)) {
+ decalposition[numdecals] = where;
+ decaltype[numdecals] = atype;
+ decalrotation[numdecals] = rotation;
+ decalalivetime[numdecals] = 0;
+ decalopacity[numdecals] = opacity - distance / 10;
+
+ if (decalopacity[numdecals > 0]) {
+ placex = vertex[Triangles[i].vertex[0]].x;
+ placez = vertex[Triangles[i].vertex[0]].z;
+
+ decaltexcoords[numdecals][0][0] = (placex - where.x) / (size) / 2 + .5;
+ decaltexcoords[numdecals][0][1] = (placez - where.z) / (size) / 2 + .5;
+
+ decalvertex[numdecals][0].x = placex;
+ decalvertex[numdecals][0].z = placez;
+ decalvertex[numdecals][0].y = vertex[Triangles[i].vertex[0]].y;
+
+
+ placex = vertex[Triangles[i].vertex[1]].x;
+ placez = vertex[Triangles[i].vertex[1]].z;
+
+ decaltexcoords[numdecals][1][0] = (placex - where.x) / (size) / 2 + .5;
+ decaltexcoords[numdecals][1][1] = (placez - where.z) / (size) / 2 + .5;
+
+ decalvertex[numdecals][1].x = placex;
+ decalvertex[numdecals][1].z = placez;
+ decalvertex[numdecals][1].y = vertex[Triangles[i].vertex[1]].y;
+
+
+ placex = vertex[Triangles[i].vertex[2]].x;
+ placez = vertex[Triangles[i].vertex[2]].z;
+
+ decaltexcoords[numdecals][2][0] = (placex - where.x) / (size) / 2 + .5;
+ decaltexcoords[numdecals][2][1] = (placez - where.z) / (size) / 2 + .5;
+
+ decalvertex[numdecals][2].x = placex;
+ decalvertex[numdecals][2].z = placez;
+ decalvertex[numdecals][2].y = vertex[Triangles[i].vertex[2]].y;
+
+ if (!(decaltexcoords[numdecals][0][0] < 0 && decaltexcoords[numdecals][1][0] < 0 && decaltexcoords[numdecals][2][0] < 0))
+ if (!(decaltexcoords[numdecals][0][1] < 0 && decaltexcoords[numdecals][1][1] < 0 && decaltexcoords[numdecals][2][1] < 0))
+ if (!(decaltexcoords[numdecals][0][0] > 1 && decaltexcoords[numdecals][1][0] > 1 && decaltexcoords[numdecals][2][0] > 1))
+ if (!(decaltexcoords[numdecals][0][1] > 1 && decaltexcoords[numdecals][1][1] > 1 && decaltexcoords[numdecals][2][1] > 1)) {
+ if (decalrotation[numdecals]) {
+ for (j = 0; j < 3; j++) {
+ rot.y = 0;
+ rot.x = decaltexcoords[numdecals][j][0] - .5;
+ rot.z = decaltexcoords[numdecals][j][1] - .5;
+ rot = DoRotation(rot, 0, -decalrotation[numdecals], 0);
+ decaltexcoords[numdecals][j][0] = rot.x + .5;
+ decaltexcoords[numdecals][j][1] = rot.z + .5;
+ }
+ }
+ if (numdecals < max_model_decals - 1)
+ numdecals++;
+ }
+ }
+ } else if (distance < .02 && abs(facenormals[i].x) > abs(facenormals[i].y) && abs(facenormals[i].x) > abs(facenormals[i].z)) {
+ decalposition[numdecals] = where;
+ decaltype[numdecals] = atype;
+ decalrotation[numdecals] = rotation;
+ decalalivetime[numdecals] = 0;
+ decalopacity[numdecals] = opacity - distance / 10;
+
+ if (decalopacity[numdecals > 0]) {
+ placex = vertex[Triangles[i].vertex[0]].y;
+ placez = vertex[Triangles[i].vertex[0]].z;
+
+ decaltexcoords[numdecals][0][0] = (placex - where.y) / (size) / 2 + .5;
+ decaltexcoords[numdecals][0][1] = (placez - where.z) / (size) / 2 + .5;
+
+ decalvertex[numdecals][0].x = vertex[Triangles[i].vertex[0]].x;
+ decalvertex[numdecals][0].z = placez;
+ decalvertex[numdecals][0].y = placex;
+
+
+ placex = vertex[Triangles[i].vertex[1]].y;
+ placez = vertex[Triangles[i].vertex[1]].z;
+
+ decaltexcoords[numdecals][1][0] = (placex - where.y) / (size) / 2 + .5;
+ decaltexcoords[numdecals][1][1] = (placez - where.z) / (size) / 2 + .5;
+
+ decalvertex[numdecals][1].x = vertex[Triangles[i].vertex[1]].x;
+ decalvertex[numdecals][1].z = placez;
+ decalvertex[numdecals][1].y = placex;
+
+
+ placex = vertex[Triangles[i].vertex[2]].y;
+ placez = vertex[Triangles[i].vertex[2]].z;
+
+ decaltexcoords[numdecals][2][0] = (placex - where.y) / (size) / 2 + .5;
+ decaltexcoords[numdecals][2][1] = (placez - where.z) / (size) / 2 + .5;
+
+ decalvertex[numdecals][2].x = vertex[Triangles[i].vertex[2]].x;
+ decalvertex[numdecals][2].z = placez;
+ decalvertex[numdecals][2].y = placex;
+
+ if (!(decaltexcoords[numdecals][0][0] < 0 && decaltexcoords[numdecals][1][0] < 0 && decaltexcoords[numdecals][2][0] < 0))
+ if (!(decaltexcoords[numdecals][0][1] < 0 && decaltexcoords[numdecals][1][1] < 0 && decaltexcoords[numdecals][2][1] < 0))
+ if (!(decaltexcoords[numdecals][0][0] > 1 && decaltexcoords[numdecals][1][0] > 1 && decaltexcoords[numdecals][2][0] > 1))
+ if (!(decaltexcoords[numdecals][0][1] > 1 && decaltexcoords[numdecals][1][1] > 1 && decaltexcoords[numdecals][2][1] > 1)) {
+ if (decalrotation[numdecals]) {
+ for (j = 0; j < 3; j++) {
+ rot.y = 0;
+ rot.x = decaltexcoords[numdecals][j][0] - .5;
+ rot.z = decaltexcoords[numdecals][j][1] - .5;
+ rot = DoRotation(rot, 0, -decalrotation[numdecals], 0);
+ decaltexcoords[numdecals][j][0] = rot.x + .5;
+ decaltexcoords[numdecals][j][1] = rot.z + .5;
+ }
+ }
+ if (numdecals < max_model_decals - 1)
+ numdecals++;
+ }
+ }
+ } else if (distance < .02 && abs(facenormals[i].z) > abs(facenormals[i].y) && abs(facenormals[i].z) > abs(facenormals[i].x)) {
+ decalposition[numdecals] = where;
+ decaltype[numdecals] = atype;
+ decalrotation[numdecals] = rotation;
+ decalalivetime[numdecals] = 0;
+ decalopacity[numdecals] = opacity - distance / 10;
+
+ if (decalopacity[numdecals > 0]) {
+ placex = vertex[Triangles[i].vertex[0]].x;
+ placez = vertex[Triangles[i].vertex[0]].y;
+
+ decaltexcoords[numdecals][0][0] = (placex - where.x) / (size) / 2 + .5;
+ decaltexcoords[numdecals][0][1] = (placez - where.y) / (size) / 2 + .5;
+
+ decalvertex[numdecals][0].x = placex;
+ decalvertex[numdecals][0].z = vertex[Triangles[i].vertex[0]].z;
+ decalvertex[numdecals][0].y = placez;
+
+
+ placex = vertex[Triangles[i].vertex[1]].x;
+ placez = vertex[Triangles[i].vertex[1]].y;
+
+ decaltexcoords[numdecals][1][0] = (placex - where.x) / (size) / 2 + .5;
+ decaltexcoords[numdecals][1][1] = (placez - where.y) / (size) / 2 + .5;
+
+ decalvertex[numdecals][1].x = placex;
+ decalvertex[numdecals][1].z = vertex[Triangles[i].vertex[1]].z;
+ decalvertex[numdecals][1].y = placez;
+
+
+ placex = vertex[Triangles[i].vertex[2]].x;
+ placez = vertex[Triangles[i].vertex[2]].y;
+
+ decaltexcoords[numdecals][2][0] = (placex - where.x) / (size) / 2 + .5;
+ decaltexcoords[numdecals][2][1] = (placez - where.y) / (size) / 2 + .5;
+
+ decalvertex[numdecals][2].x = placex;
+ decalvertex[numdecals][2].z = vertex[Triangles[i].vertex[2]].z;
+ decalvertex[numdecals][2].y = placez;
+
+ if (!(decaltexcoords[numdecals][0][0] < 0 && decaltexcoords[numdecals][1][0] < 0 && decaltexcoords[numdecals][2][0] < 0))
+ if (!(decaltexcoords[numdecals][0][1] < 0 && decaltexcoords[numdecals][1][1] < 0 && decaltexcoords[numdecals][2][1] < 0))
+ if (!(decaltexcoords[numdecals][0][0] > 1 && decaltexcoords[numdecals][1][0] > 1 && decaltexcoords[numdecals][2][0] > 1))
+ if (!(decaltexcoords[numdecals][0][1] > 1 && decaltexcoords[numdecals][1][1] > 1 && decaltexcoords[numdecals][2][1] > 1)) {
+ if (decalrotation[numdecals]) {
+ for (j = 0; j < 3; j++) {
+ rot.y = 0;
+ rot.x = decaltexcoords[numdecals][j][0] - .5;
+ rot.z = decaltexcoords[numdecals][j][1] - .5;
+ rot = DoRotation(rot, 0, -decalrotation[numdecals], 0);
+ decaltexcoords[numdecals][j][0] = rot.x + .5;
+ decaltexcoords[numdecals][j][1] = rot.z + .5;
+ }
+ }
+ if (numdecals < max_model_decals - 1)
+ numdecals++;
+ }
+ }
+ }
+ }
+ }