00001 #include <windows.h>
00002 #include "bullet.h"
00003 #include "decal.h"
00004 #include "vector.h"
00005 #include "vertex.h"
00006 #include "polygon.h"
00007 #include "texture.h"
00008 #include "listnode.h"
00009 #include "collision.h"
00010 #include "general.h"
00011 #include "camera.h"
00012 #include "bsp.h"
00013 #include "tll.h"
00014 #include "mmgr.h"
00015
00016 extern VERTEX* vertex;
00017 extern TEXTURE* texture;
00018 extern int numBullets;
00019 extern BULLET* bullet;
00020 extern int numBulletsActive;
00021 extern int numleaves;
00022 extern LinkedList<BSP_node> LeafList;
00023 extern LinkedList<BSP_node> PartitionList;
00024 extern BSP_node* listnode;
00025 extern CAMERA* camera;
00026 extern int currentCamera;
00027 extern int bulletspeed;
00028 extern int bullettype;
00029 extern BSP_node* root;
00030 extern int maxDecals;
00031 extern DECAL muzzleflashdecal;
00032 extern DECAL impactflashdecal;
00033
00034 DECAL::DECAL()
00035 {
00036 }
00037
00038 DECAL::~DECAL()
00039 {
00040 }
00041
00042 int DECAL::Compare(const DECAL& Decal)
00043 {
00044 if (linkPosition < Decal.linkPosition)
00045 return smaller;
00046 if (linkPosition > Decal.linkPosition)
00047 return bigger;
00048 else
00049 return same;
00050 }
00051
00052
00053 void CreateDecal(VECTOR pt, POLYGON* face, DECAL* decal)
00054 {
00055 VECTOR axis[3] =
00056 {
00057 VECTOR(1.0f, 0.0f, 0.0f),
00058 VECTOR(0.0f, 1.0f, 0.0f),
00059 VECTOR(0.0f, 0.0f, 1.0f)
00060 };
00061 VECTOR poly_normal(fabs(face->Vertex[0].normal.x), fabs(face->Vertex[0].normal.y), fabs(face->Vertex[0].normal.z));
00062 poly_normal.Normalize();
00063 VECTOR up, right, temp;
00064 int major;
00065
00066 if (poly_normal.x > poly_normal.y && poly_normal.x > poly_normal.z)
00067 major = 0;
00068 else if (poly_normal.y > poly_normal.x && poly_normal.y > poly_normal.z)
00069 major = 1;
00070 else
00071 major = 2;
00072
00073
00074 if (poly_normal.x == 1.0 || poly_normal.y == 1.0 || poly_normal.z == 1.0)
00075 {
00076 if ((major == 0 && face->Vertex[0].normal.x > 0.0) || major == 1)
00077 right.Set(0.0, 0.0, -1.0);
00078 else if (major == 0)
00079 right.Set(0.0, 0.0, 1.0);
00080 else
00081 right.Set(1.0 * face->Vertex[0].normal.z, 0.0, 0.0);
00082 }
00083 else
00084 {
00085 temp = face->Vertex[0].normal;
00086 axis[major].CrossVector(temp);
00087 right = axis[major];
00088 }
00089
00090 temp.x = -face->Vertex[0].normal.x;
00091 temp.y = -face->Vertex[0].normal.y;
00092 temp.z = -face->Vertex[0].normal.z;
00093 temp.CrossVector(right);
00094 up = temp;
00095 up.Normalize();
00096 right.Normalize();
00097
00098
00099 decal->Vertex[0].coords.x = pt.x + ((-right.x - up.x) * decal->Size);
00100 decal->Vertex[0].coords.y = pt.y + ((-right.y - up.y) * decal->Size);
00101 decal->Vertex[0].coords.z = pt.z + ((-right.z - up.z) * decal->Size);
00102 decal->Vertex[1].coords.x = pt.x + ((right.x - up.x) * decal->Size);
00103 decal->Vertex[1].coords.y = pt.y + ((right.y - up.y) * decal->Size);
00104 decal->Vertex[1].coords.z = pt.z + ((right.z - up.z) * decal->Size);
00105 decal->Vertex[2].coords.x = pt.x + ((right.x + up.x) * decal->Size);
00106 decal->Vertex[2].coords.y = pt.y + ((right.y + up.y) * decal->Size);
00107 decal->Vertex[2].coords.z = pt.z + ((right.z + up.z) * decal->Size);
00108 decal->Vertex[3].coords.x = pt.x + ((-right.x + up.x) * decal->Size);
00109 decal->Vertex[3].coords.y = pt.y + ((-right.y + up.y) * decal->Size);
00110 decal->Vertex[3].coords.z = pt.z + ((-right.z + up.z) * decal->Size);
00111 }
00112
00113 void RenderBulletDecal(DECAL decal)
00114 {
00115 float mat_ambient[] = { 0.8, 0.8, 0.8, 1.0 };
00116 float mat_diffuse[] = { 0.8, 0.8, 0.8, 1.0 };
00117 glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
00118 glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
00119
00120 glEnable(GL_BLEND);
00121 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00122 glEnable(GL_ALPHA_TEST);
00123 glAlphaFunc(GL_GREATER, 0);
00124
00125 glBindTexture(GL_TEXTURE_2D, texture[7].TexID);
00126
00127 glBegin(GL_QUADS);
00128 glTexCoord2f(0.0f, 0.0f);
00129 glVertex3fv(&decal.Vertex[0].coords.x);
00130 glTexCoord2f(1.0f, 0.0f);
00131 glVertex3fv(&decal.Vertex[1].coords.x);
00132 glTexCoord2f(1.0f, 1.0f);
00133 glVertex3fv(&decal.Vertex[2].coords.x);
00134 glTexCoord2f(0.0f, 1.0f);
00135 glVertex3fv(&decal.Vertex[3].coords.x);
00136 glEnd();
00137
00138 glDisable(GL_BLEND);
00139 glDisable(GL_ALPHA_TEST);
00140 }
00141
00142 void RenderBurnDecal(DECAL decal)
00143 {
00144 glEnable(GL_BLEND);
00145 glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
00146 glBindTexture(GL_TEXTURE_2D, texture[4].TexID);
00147
00148 glBegin(GL_QUADS);
00149 glTexCoord2f(0.0f, 0.0f);
00150 glVertex3fv(&decal.Vertex[0].coords.x);
00151 glTexCoord2f(1.0f, 0.0f);
00152 glVertex3fv(&decal.Vertex[1].coords.x);
00153 glTexCoord2f(1.0f, 1.0f);
00154 glVertex3fv(&decal.Vertex[2].coords.x);
00155 glTexCoord2f(0.0f, 1.0f);
00156 glVertex3fv(&decal.Vertex[3].coords.x);
00157 glEnd();
00158
00159 glDisable(GL_BLEND);
00160 }
00161
00162 void DrawImpactFlash()
00163 {
00164 float halfwidth = 1.0;
00165 float halfheight = 1.0;
00166
00167 MATRIX mat;
00168 glGetFloatv(GL_MODELVIEW_MATRIX, mat.Element);
00169
00170 VECTOR right;
00171 right.x = mat.Element[0];
00172 right.y = mat.Element[4];
00173 right.z = mat.Element[8];
00174 right.Normalize();
00175 right.x *= halfwidth;
00176 right.y *= halfwidth;
00177 right.z *= halfwidth;
00178
00179 VECTOR up;
00180 up.x = mat.Element[1];
00181 up.y = mat.Element[5];
00182 up.z = mat.Element[9];
00183 up.Normalize();
00184 up.x *= halfheight;
00185 up.y *= halfheight;
00186 up.z *= halfheight;
00187
00188 glEnable(GL_BLEND);
00189 glDepthMask(0);
00190 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
00191 glDisable(GL_LIGHTING);
00192
00193 glDisable(GL_CULL_FACE);
00194 glBindTexture(GL_TEXTURE_2D, texture[6].TexID);
00195 glBegin(GL_QUADS);
00196 glTexCoord2f(0.0f, 0.0f); glVertex3f(impactflashdecal.CollisionVector.x + (-right.x - up.x), impactflashdecal.CollisionVector.y + (-right.y - up.y), impactflashdecal.CollisionVector.z + (-right.z - up.z));
00197 glTexCoord2f(1.0f, 0.0f); glVertex3f(impactflashdecal.CollisionVector.x + (right.x - up.x), impactflashdecal.CollisionVector.y + (right.y - up.y), impactflashdecal.CollisionVector.z + (right.z - up.z));
00198 glTexCoord2f(1.0f, 1.0f); glVertex3f(impactflashdecal.CollisionVector.x + (right.x + up.x), impactflashdecal.CollisionVector.y + (right.y + up.y), impactflashdecal.CollisionVector.z + (right.z + up.z));
00199 glTexCoord2f(0.0f, 1.0f); glVertex3f(impactflashdecal.CollisionVector.x + (up.x - right.x), impactflashdecal.CollisionVector.y + (up.y - right.y), impactflashdecal.CollisionVector.z + (up.z - right.z));
00200 glEnd();
00201 glEnable(GL_DEPTH_TEST);
00202 glDepthMask(1);
00203 glDisable(GL_BLEND);
00204 glEnable(GL_LIGHTING);
00205 glEnable(GL_CULL_FACE);
00206 }
00207
00208 void DrawMuzzleFlash()
00209 {
00210 MATRIX Matrix;
00211 glPushMatrix();
00212 glTranslatef(muzzleflashdecal.Position.x,muzzleflashdecal.Position.y,muzzleflashdecal.Position.z);
00213 Matrix.QuatToMatrix(muzzleflashdecal.Orientation);
00214 glMultMatrixf(Matrix.Element);
00215 glTranslatef(0.0,-4.0,-10.0);
00216
00217 glEnable(GL_BLEND);
00218 glDepthMask(0);
00219 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
00220 glDisable(GL_LIGHTING);
00221 glColor4f(1.0, 1.0, 1.0, 1.0);
00222 glBindTexture(GL_TEXTURE_2D, texture[5].TexID);
00223 glDisable(GL_CULL_FACE);
00224
00225 glBegin(GL_QUADS);
00226 glTexCoord2f(0.0f, 0.0f);
00227 glVertex3f(-muzzleflashdecal.Size, -muzzleflashdecal.Size, 0.0);
00228 glTexCoord2f(1.0f, 0.0f);
00229 glVertex3f(muzzleflashdecal.Size, -muzzleflashdecal.Size, 0.0);
00230 glTexCoord2f(1.0f, 1.0f);
00231 glVertex3f(muzzleflashdecal.Size, muzzleflashdecal.Size, 0.0);
00232 glTexCoord2f(0.0f, 1.0f);
00233 glVertex3f(-muzzleflashdecal.Size, muzzleflashdecal.Size, 0.0);
00234 glEnd();
00235
00236 glEnable(GL_CULL_FACE);
00237 glDepthMask(1);
00238 glDisable(GL_BLEND);
00239 glEnable(GL_LIGHTING);
00240 glPopMatrix();
00241 }
00242
00243 void DrawDecals()
00244 {
00245
00246 if (impactflashdecal.active)
00247 {
00248 impactflashdecal.active = false;
00249 DrawImpactFlash();
00250 }
00251
00252
00253 if (muzzleflashdecal.active)
00254 {
00255 muzzleflashdecal.active = false;
00256 muzzleflashdecal.Position = camera[currentCamera].Position;
00257 muzzleflashdecal.Orientation = camera[currentCamera].Orientation;
00258 DrawMuzzleFlash();
00259 }
00260 }
00261