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<ListNode> LeafList;
00023 extern LinkedList<ListNode> PartitionList;
00024 extern ListNode* 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 void CreateDecal(VECTOR pt, POLYGON* face, DECAL* decal)
00053 {
00054 VECTOR axis[3] =
00055 {
00056 VECTOR(1.0f, 0.0f, 0.0f),
00057 VECTOR(0.0f, 1.0f, 0.0f),
00058 VECTOR(0.0f, 0.0f, 1.0f)
00059 };
00060 VECTOR poly_normal(fabs(face->Vertex[0].nx), fabs(face->Vertex[0].ny), fabs(face->Vertex[0].nz));
00061 poly_normal.Normalize();
00062 VECTOR up, right, temp;
00063 int major;
00064
00065 if (poly_normal.x > poly_normal.y && poly_normal.x > poly_normal.z)
00066 major = 0;
00067 else if (poly_normal.y > poly_normal.x && poly_normal.y > poly_normal.z)
00068 major = 1;
00069 else
00070 major = 2;
00071
00072
00073 if (poly_normal.x == 1.0 || poly_normal.y == 1.0 || poly_normal.z == 1.0)
00074 {
00075 if ((major == 0 && face->Vertex[0].nx > 0.0) || major == 1)
00076 right.Set(0.0, 0.0, -1.0);
00077 else if (major == 0)
00078 right.Set(0.0, 0.0, 1.0);
00079 else
00080 right.Set(1.0 * face->Vertex[0].nz, 0.0, 0.0);
00081 }
00082 else
00083 {
00084 temp.x = face->Vertex[0].nx;
00085 temp.y = face->Vertex[0].ny;
00086 temp.z = face->Vertex[0].nz;
00087 axis[major].CrossVector(temp);
00088 right = axis[major];
00089 }
00090
00091 temp.x = -face->Vertex[0].nx;
00092 temp.y = -face->Vertex[0].ny;
00093 temp.z = -face->Vertex[0].nz;
00094 temp.CrossVector(right);
00095 up = temp;
00096 up.Normalize();
00097 right.Normalize();
00098
00099
00100 decal->Vertex[0].x = pt.x + ((-right.x - up.x) * decal->Size);
00101 decal->Vertex[0].y = pt.y + ((-right.y - up.y) * decal->Size);
00102 decal->Vertex[0].z = pt.z + ((-right.z - up.z) * decal->Size);
00103 decal->Vertex[1].x = pt.x + ((right.x - up.x) * decal->Size);
00104 decal->Vertex[1].y = pt.y + ((right.y - up.y) * decal->Size);
00105 decal->Vertex[1].z = pt.z + ((right.z - up.z) * decal->Size);
00106 decal->Vertex[2].x = pt.x + ((right.x + up.x) * decal->Size);
00107 decal->Vertex[2].y = pt.y + ((right.y + up.y) * decal->Size);
00108 decal->Vertex[2].z = pt.z + ((right.z + up.z) * decal->Size);
00109 decal->Vertex[3].x = pt.x + ((-right.x + up.x) * decal->Size);
00110 decal->Vertex[3].y = pt.y + ((-right.y + up.y) * decal->Size);
00111 decal->Vertex[3].z = pt.z + ((-right.z + up.z) * decal->Size);
00112 }
00113
00114 void RenderBulletDecal(DECAL decal)
00115 {
00116 float mat_ambient[] = { 0.8, 0.8, 0.8, 1.0 };
00117 float mat_diffuse[] = { 0.8, 0.8, 0.8, 1.0 };
00118 glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
00119 glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
00120
00121 glDisable(GL_LIGHTING);
00122 glColor3f(1.0, 1.0, 1.0);
00123 glEnable(GL_BLEND);
00124 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00125 glEnable(GL_ALPHA_TEST);
00126 glAlphaFunc(GL_GREATER, 0);
00127
00128 glBindTexture(GL_TEXTURE_2D, texture[7].TexID);
00129
00130 glBegin(GL_QUADS);
00131 glTexCoord2f(0.0f, 0.0f);
00132 glVertex3fv(&decal.Vertex[0].x);
00133 glTexCoord2f(1.0f, 0.0f);
00134 glVertex3fv(&decal.Vertex[1].x);
00135 glTexCoord2f(1.0f, 1.0f);
00136 glVertex3fv(&decal.Vertex[2].x);
00137 glTexCoord2f(0.0f, 1.0f);
00138 glVertex3fv(&decal.Vertex[3].x);
00139 glEnd();
00140
00141 glDisable(GL_BLEND);
00142 glDisable(GL_ALPHA_TEST);
00143 glEnable(GL_LIGHTING);
00144 }
00145
00146 void RenderBurnDecal(DECAL decal)
00147 {
00148 glEnable(GL_BLEND);
00149 glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
00150 glBindTexture(GL_TEXTURE_2D, texture[4].TexID);
00151
00152 glBegin(GL_QUADS);
00153 glTexCoord2f(0.0f, 0.0f);
00154 glVertex3fv(&decal.Vertex[0].x);
00155 glTexCoord2f(1.0f, 0.0f);
00156 glVertex3fv(&decal.Vertex[1].x);
00157 glTexCoord2f(1.0f, 1.0f);
00158 glVertex3fv(&decal.Vertex[2].x);
00159 glTexCoord2f(0.0f, 1.0f);
00160 glVertex3fv(&decal.Vertex[3].x);
00161 glEnd();
00162
00163 glDisable(GL_BLEND);
00164 }
00165
00166 void DrawImpactFlash()
00167 {
00168 float halfwidth = 1.0;
00169 float halfheight = 1.0;
00170
00171 MATRIX mat;
00172 glGetFloatv(GL_MODELVIEW_MATRIX, mat.Element);
00173
00174 VECTOR right;
00175 right.x = mat.Element[0];
00176 right.y = mat.Element[4];
00177 right.z = mat.Element[8];
00178 right.Normalize();
00179 right.x *= halfwidth;
00180 right.y *= halfwidth;
00181 right.z *= halfwidth;
00182
00183 VECTOR up;
00184 up.x = mat.Element[1];
00185 up.y = mat.Element[5];
00186 up.z = mat.Element[9];
00187 up.Normalize();
00188 up.x *= halfheight;
00189 up.y *= halfheight;
00190 up.z *= halfheight;
00191
00192 glDepthMask(0);
00193 glEnable(GL_BLEND);
00194 glEnable(GL_ALPHA_TEST);
00195 glAlphaFunc(GL_GREATER, 0.5);
00196 glDisable(GL_LIGHTING);
00197 glColor4f(1.0, 1.0, 1.0, 1.0);
00198 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
00199 glEnable(GL_POLYGON_OFFSET_FILL);
00200 glPolygonOffset(-1.0f, -2.0f);
00201 glDisable(GL_DEPTH_TEST);
00202 glBindTexture(GL_TEXTURE_2D, texture[6].TexID);
00203 glBegin(GL_QUADS);
00204 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));
00205 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));
00206 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));
00207 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));
00208 glEnd();
00209 glEnable(GL_DEPTH_TEST);
00210 glDepthMask(1);
00211 glDisable(GL_BLEND);
00212 glDisable(GL_ALPHA_TEST);
00213 glDisable(GL_POLYGON_OFFSET_FILL);
00214 glEnable(GL_LIGHTING);
00215 }
00216
00217 void DrawMuzzleFlash()
00218 {
00219 MATRIX Matrix;
00220 glPushMatrix();
00221 glTranslatef(muzzleflashdecal.Position.x,muzzleflashdecal.Position.y,muzzleflashdecal.Position.z);
00222 Matrix.QuatToMatrix(muzzleflashdecal.Orientation);
00223 glMultMatrixf(Matrix.Element);
00224 glTranslatef(0.0,-4.0,-10.0);
00225
00226 glDepthMask(0);
00227 glEnable(GL_BLEND);
00228 glEnable(GL_ALPHA_TEST);
00229 glAlphaFunc(GL_GREATER, 0);
00230 glDisable(GL_LIGHTING);
00231 glColor4f(1.0, 1.0, 1.0, 1.0);
00232 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
00233 glBindTexture(GL_TEXTURE_2D, texture[5].TexID);
00234 glDisable(GL_CULL_FACE);
00235
00236 glBegin(GL_QUADS);
00237 glTexCoord2f(0.0f, 0.0f);
00238 glVertex3f(-muzzleflashdecal.Size, -muzzleflashdecal.Size, 0.0);
00239 glTexCoord2f(1.0f, 0.0f);
00240 glVertex3f(muzzleflashdecal.Size, -muzzleflashdecal.Size, 0.0);
00241 glTexCoord2f(1.0f, 1.0f);
00242 glVertex3f(muzzleflashdecal.Size, muzzleflashdecal.Size, 0.0);
00243 glTexCoord2f(0.0f, 1.0f);
00244 glVertex3f(-muzzleflashdecal.Size, muzzleflashdecal.Size, 0.0);
00245 glEnd();
00246
00247 glEnable(GL_CULL_FACE);
00248 glDepthMask(1);
00249 glDisable(GL_BLEND);
00250 glDisable(GL_ALPHA_TEST);
00251 glDisable(GL_POLYGON_OFFSET_FILL);
00252 glEnable(GL_LIGHTING);
00253 glPopMatrix();
00254 }
00255
00256 void DrawDecals()
00257 {
00258
00259 if (impactflashdecal.active)
00260 {
00261 impactflashdecal.active = false;
00262 DrawImpactFlash();
00263 }
00264
00265
00266 if (muzzleflashdecal.active)
00267 {
00268 muzzleflashdecal.active = false;
00269 muzzleflashdecal.Position = camera[currentCamera].Position;
00270 muzzleflashdecal.Orientation = camera[currentCamera].Orientation;
00271 DrawMuzzleFlash();
00272 }
00273 }
00274