Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

brush.cpp

Go to the documentation of this file.
00001 #include <windows.h>
00002 #include "brush.h"
00003 #include "tll.h"
00004 #include "texture.h"
00005 #include "mmgr.h"
00006 
00007 extern int numBrushes;
00008 extern POLYGON* brushPolygons;
00009 extern BRUSH* BrushSet;
00010 extern BRUSH* Brush;
00011 extern VERTEX* vertex1;
00012 extern VERTEX* vertex2;
00013 extern VERTEX* vertex3;
00014 extern TEXTURE* texture;
00015 extern bool Texturing;
00016 extern bool CSGflag;
00017 extern bool CSGcullface;
00018 
00019 BRUSH::BRUSH()
00020 {
00021     NextBrush = NULL;
00022     numPolygons    = 0;
00023     id = 0;
00024 }
00025 
00026 BRUSH::~BRUSH()
00027 {
00028 }
00029 
00030 bool BRUSH::IsLast()
00031 {
00032     if (NextBrush == NULL)
00033         return true;
00034     else
00035         return false;
00036 }
00037 
00038 BRUSH* BRUSH::GetNext()
00039 {
00040     if (!IsLast())
00041         return NextBrush;
00042     else
00043         return NULL;
00044 }
00045 
00046 void BRUSH::SetNext(BRUSH* Brush)
00047 {
00048     if (IsLast())
00049     {
00050         NextBrush = Brush;
00051         return;
00052     }
00053 
00054     BRUSH* TempBrush = Brush;
00055 
00056     while (!TempBrush->IsLast())
00057         TempBrush = TempBrush->GetNext();
00058 
00059     TempBrush->SetNext(NextBrush);
00060     NextBrush = Brush;
00061 }
00062 
00063 BRUSH* BRUSH::CopyList()
00064 {
00065     BRUSH* TempBrush = new BRUSH;
00066 
00067     TempBrush->id = id;
00068 
00069     TempBrush->numPolygons = numPolygons;
00070 
00071     for (int loop = 0; loop < numPolygons; loop++)
00072         TempBrush->Polygon[loop] = Polygon[loop];
00073 
00074     if (!IsLast())
00075         TempBrush->AddBrush(NextBrush->CopyList());
00076 
00077     return TempBrush;
00078 }
00079 
00080 void BRUSH::AddBrush(BRUSH* Brush)
00081 {
00082     if (Brush != NULL)
00083     {
00084         if (IsLast())
00085         {
00086             NextBrush = Brush;
00087             return;
00088         }
00089 
00090         BRUSH* TempBrush = NextBrush;
00091 
00092         while (!TempBrush->IsLast())
00093             TempBrush = TempBrush->GetNext();
00094 
00095         TempBrush->NextBrush = Brush;
00096     }
00097 }
00098 
00099 int BRUSH::Compare(const BRUSH& Brush)
00100 {
00101     if (linkPosition < Brush.linkPosition)
00102             return smaller;
00103       if (linkPosition > Brush.linkPosition)
00104             return bigger;
00105       else
00106             return same;
00107 }
00108 
00109 void DeleteList(BRUSH* Brush)
00110 {
00111     if (Brush->IsLast())
00112     {
00113         delete Brush;
00114         return;
00115     }
00116     
00117     DeleteList(Brush->GetNext());
00118     delete Brush;
00119 }
00120 
00121 void InvertBrushPolygons(BRUSH* Brush)
00122 {
00123     int numverts;
00124     VERTEX tempvertices[maxPolygonVerts];
00125     for (int loop = 0; loop < Brush->numPolygons; loop++)
00126     {
00127         numverts = Brush->Polygon[loop].numVertices;
00128         for (int innerloop = 0; innerloop < numverts; innerloop++)
00129             tempvertices[innerloop] = Brush->Polygon[loop].Vertex[innerloop];
00130         for (int innerloop = 0; innerloop < numverts; innerloop++)
00131             Brush->Polygon[loop].Vertex[innerloop] = tempvertices[(numverts - 1) - innerloop];
00132         Brush->Polygon[loop].SetNormal();
00133     }
00134     return;
00135 }
00136 
00137 // Brush vertex and polygon initialization
00138 void Set1stVertices()
00139 {
00140 // Set cubes vertices
00141 
00142     vertex1[0].coords.x = 20;
00143     vertex1[0].coords.y = 5;
00144     vertex1[0].coords.z = 30;
00145 
00146     vertex1[1].coords.x = -20;
00147     vertex1[1].coords.y = 5;
00148     vertex1[1].coords.z = 30;
00149 
00150     vertex1[2].coords.x = -20;
00151     vertex1[2].coords.y = 5;
00152     vertex1[2].coords.z = 10;
00153 
00154     vertex1[3].coords.x = 20;
00155     vertex1[3].coords.y = 5;
00156     vertex1[3].coords.z = 10;
00157 
00158     vertex1[4].coords.x = 20;
00159     vertex1[4].coords.y = -5;
00160     vertex1[4].coords.z = 30;
00161 
00162     vertex1[5].coords.x = -20;
00163     vertex1[5].coords.y = -5;
00164     vertex1[5].coords.z = 30;
00165 
00166     vertex1[6].coords.x = -20;
00167     vertex1[6].coords.y = -5;
00168     vertex1[6].coords.z = 10;
00169 
00170     vertex1[7].coords.x = 20;
00171     vertex1[7].coords.y = -5;
00172     vertex1[7].coords.z = 10;
00173 }
00174 
00175 void Set2ndVertices()
00176 {
00177 // Set cubes vertices
00178     vertex2[0].coords.x = -20;
00179     vertex2[0].coords.y = -10;
00180     vertex2[0].coords.z = 20;
00181 
00182     vertex2[1].coords.x = 20;
00183     vertex2[1].coords.y = -10;
00184     vertex2[1].coords.z = 20;
00185 
00186     vertex2[2].coords.x = 20;
00187     vertex2[2].coords.y = 10;
00188     vertex2[2].coords.z = 20;
00189 
00190     vertex2[3].coords.x = -20;
00191     vertex2[3].coords.y = 10;
00192     vertex2[3].coords.z = 20;
00193 
00194     vertex2[4].coords.x = -20;
00195     vertex2[4].coords.y = -10;
00196     vertex2[4].coords.z = -20;
00197 
00198     vertex2[5].coords.x = 20;
00199     vertex2[5].coords.y = -10;
00200     vertex2[5].coords.z = -20;
00201 
00202     vertex2[6].coords.x = 20;
00203     vertex2[6].coords.y = 10;
00204     vertex2[6].coords.z = -20;
00205 
00206     vertex2[7].coords.x = -20;
00207     vertex2[7].coords.y = 10;
00208     vertex2[7].coords.z = -20;
00209 }
00210 
00211 void Set3rdVertices()
00212 {
00213 // Set cubes vertices
00214     vertex3[0].coords.x = -30;
00215     vertex3[0].coords.y = -5;
00216     vertex3[0].coords.z = 10;
00217 
00218     vertex3[1].coords.x = 5;
00219     vertex3[1].coords.y = -5;
00220     vertex3[1].coords.z = 10;
00221 
00222     vertex3[2].coords.x = 5;
00223     vertex3[2].coords.y = 20;
00224     vertex3[2].coords.z = 10;
00225 
00226     vertex3[3].coords.x = -30;
00227     vertex3[3].coords.y = 20;
00228     vertex3[3].coords.z = 10;
00229 
00230     vertex3[4].coords.x = -30;
00231     vertex3[4].coords.y = -5;
00232     vertex3[4].coords.z = -10;
00233 
00234     vertex3[5].coords.x = 5;
00235     vertex3[5].coords.y = -5;
00236     vertex3[5].coords.z = -10;
00237 
00238     vertex3[6].coords.x = 5;
00239     vertex3[6].coords.y = 20;
00240     vertex3[6].coords.z = -10;
00241 
00242     vertex3[7].coords.x = -30;
00243     vertex3[7].coords.y = 20;
00244     vertex3[7].coords.z = -10;
00245 }
00246 
00247 void SetBrushPolygons()
00248 {
00249 // Set brush 1 polygons
00250 
00251     Brush[0].Polygon[0].Vertex[0] = vertex1[1];
00252     Brush[0].Polygon[0].Vertex[1] = vertex1[0];
00253     Brush[0].Polygon[0].Vertex[2] = vertex1[3];
00254     Brush[0].Polygon[0].Vertex[3] = vertex1[2];
00255     Brush[0].Polygon[0].Vertex[0].u = 0.0;
00256     Brush[0].Polygon[0].Vertex[0].v = 0.0;
00257     Brush[0].Polygon[0].Vertex[1].u = 1.0;
00258     Brush[0].Polygon[0].Vertex[1].v = 0.0;
00259     Brush[0].Polygon[0].Vertex[2].u = 1.0;
00260     Brush[0].Polygon[0].Vertex[2].v = 1.0;
00261     Brush[0].Polygon[0].Vertex[3].u = 0.0;
00262     Brush[0].Polygon[0].Vertex[3].v = 1.0;
00263     Brush[0].Polygon[0].Vertex[0].polyNumber = 0;
00264     Brush[0].Polygon[0].Vertex[1].polyNumber = 0;
00265     Brush[0].Polygon[0].Vertex[2].polyNumber = 0;
00266     Brush[0].Polygon[0].Vertex[3].polyNumber = 0;
00267     Brush[0].Polygon[0].Texture = texture[10].TexID;
00268 
00269     Brush[0].Polygon[1].Vertex[0] = vertex1[5];
00270     Brush[0].Polygon[1].Vertex[1] = vertex1[4];
00271     Brush[0].Polygon[1].Vertex[2] = vertex1[0];
00272     Brush[0].Polygon[1].Vertex[3] = vertex1[1];
00273     Brush[0].Polygon[1].Vertex[0].u = 0.0;
00274     Brush[0].Polygon[1].Vertex[0].v = 0.0;
00275     Brush[0].Polygon[1].Vertex[1].u = 1.0;
00276     Brush[0].Polygon[1].Vertex[1].v = 0.0;
00277     Brush[0].Polygon[1].Vertex[2].u = 1.0;
00278     Brush[0].Polygon[1].Vertex[2].v = 1.0;
00279     Brush[0].Polygon[1].Vertex[3].u = 0.0;
00280     Brush[0].Polygon[1].Vertex[3].v = 1.0;
00281     Brush[0].Polygon[1].Vertex[0].polyNumber = 3;
00282     Brush[0].Polygon[1].Vertex[1].polyNumber = 3;
00283     Brush[0].Polygon[1].Vertex[2].polyNumber = 3;
00284     Brush[0].Polygon[1].Vertex[3].polyNumber = 3;
00285     Brush[0].Polygon[1].Texture = texture[10].TexID;
00286 
00287     Brush[0].Polygon[2].Vertex[0] = vertex1[6];
00288     Brush[0].Polygon[2].Vertex[1] = vertex1[5];
00289     Brush[0].Polygon[2].Vertex[2] = vertex1[1];
00290     Brush[0].Polygon[2].Vertex[3] = vertex1[2];
00291     Brush[0].Polygon[2].Vertex[0].u = 0.0;
00292     Brush[0].Polygon[2].Vertex[0].v = 0.0;
00293     Brush[0].Polygon[2].Vertex[1].u = 1.0;
00294     Brush[0].Polygon[2].Vertex[1].v = 0.0;
00295     Brush[0].Polygon[2].Vertex[2].u = 1.0;
00296     Brush[0].Polygon[2].Vertex[2].v = 1.0;
00297     Brush[0].Polygon[2].Vertex[3].u = 0.0;
00298     Brush[0].Polygon[2].Vertex[3].v = 1.0;
00299     Brush[0].Polygon[2].Vertex[0].polyNumber = 4;
00300     Brush[0].Polygon[2].Vertex[1].polyNumber = 4;
00301     Brush[0].Polygon[2].Vertex[2].polyNumber = 4;
00302     Brush[0].Polygon[2].Vertex[3].polyNumber = 4;
00303     Brush[0].Polygon[2].Texture = texture[10].TexID;
00304 
00305     Brush[0].Polygon[3].Vertex[0] = vertex1[7];
00306     Brush[0].Polygon[3].Vertex[1] = vertex1[6];
00307     Brush[0].Polygon[3].Vertex[2] = vertex1[2];
00308     Brush[0].Polygon[3].Vertex[3] = vertex1[3];
00309     Brush[0].Polygon[3].Vertex[0].u = 0.0;
00310     Brush[0].Polygon[3].Vertex[0].v = 0.0;
00311     Brush[0].Polygon[3].Vertex[1].u = 1.0;
00312     Brush[0].Polygon[3].Vertex[1].v = 0.0;
00313     Brush[0].Polygon[3].Vertex[2].u = 1.0;
00314     Brush[0].Polygon[3].Vertex[2].v = 1.0;
00315     Brush[0].Polygon[3].Vertex[3].u = 0.0;
00316     Brush[0].Polygon[3].Vertex[3].v = 1.0;
00317     Brush[0].Polygon[3].Vertex[0].polyNumber = 9;
00318     Brush[0].Polygon[3].Vertex[1].polyNumber = 9;
00319     Brush[0].Polygon[3].Vertex[2].polyNumber = 9;
00320     Brush[0].Polygon[3].Vertex[3].polyNumber = 9;
00321     Brush[0].Polygon[3].Texture = texture[10].TexID;
00322 
00323     Brush[0].Polygon[4].Vertex[0] = vertex1[4];
00324     Brush[0].Polygon[4].Vertex[1] = vertex1[7];
00325     Brush[0].Polygon[4].Vertex[2] = vertex1[3];
00326     Brush[0].Polygon[4].Vertex[3] = vertex1[0];
00327     Brush[0].Polygon[4].Vertex[0].u = 0.0;
00328     Brush[0].Polygon[4].Vertex[0].v = 0.0;
00329     Brush[0].Polygon[4].Vertex[1].u = 1.0;
00330     Brush[0].Polygon[4].Vertex[1].v = 0.0;
00331     Brush[0].Polygon[4].Vertex[2].u = 1.0;
00332     Brush[0].Polygon[4].Vertex[2].v = 1.0;
00333     Brush[0].Polygon[4].Vertex[3].u = 0.0;
00334     Brush[0].Polygon[4].Vertex[3].v = 1.0;
00335     Brush[0].Polygon[4].Vertex[0].polyNumber = 10;
00336     Brush[0].Polygon[4].Vertex[1].polyNumber = 10;
00337     Brush[0].Polygon[4].Vertex[2].polyNumber = 10;
00338     Brush[0].Polygon[4].Vertex[3].polyNumber = 10;
00339     Brush[0].Polygon[4].Texture = texture[10].TexID;
00340 
00341     Brush[0].Polygon[5].Vertex[0] = vertex1[5];
00342     Brush[0].Polygon[5].Vertex[1] = vertex1[6];
00343     Brush[0].Polygon[5].Vertex[2] = vertex1[7];
00344     Brush[0].Polygon[5].Vertex[3] = vertex1[4];
00345     Brush[0].Polygon[5].Vertex[0].u = 0.0;
00346     Brush[0].Polygon[5].Vertex[0].v = 0.0;
00347     Brush[0].Polygon[5].Vertex[1].u = 1.0;
00348     Brush[0].Polygon[5].Vertex[1].v = 0.0;
00349     Brush[0].Polygon[5].Vertex[2].u = 1.0;
00350     Brush[0].Polygon[5].Vertex[2].v = 1.0;
00351     Brush[0].Polygon[5].Vertex[3].u = 0.0;
00352     Brush[0].Polygon[5].Vertex[3].v = 1.0;
00353     Brush[0].Polygon[5].Vertex[0].polyNumber = 11;
00354     Brush[0].Polygon[5].Vertex[1].polyNumber = 11;
00355     Brush[0].Polygon[5].Vertex[2].polyNumber = 11;
00356     Brush[0].Polygon[5].Vertex[3].polyNumber = 11;
00357     Brush[0].Polygon[5].Texture = texture[10].TexID;
00358 
00359     for (int loop = 0; loop < Brush[0].numPolygons; loop++)
00360     {
00361         Brush[0].Polygon[loop].SetNormal();
00362     }
00363 
00364 // Set brush 2 polygons
00365 
00366 //Front
00367     Brush[1].Polygon[0].Vertex[0] = vertex2[0];
00368     Brush[1].Polygon[0].Vertex[1] = vertex2[1];
00369     Brush[1].Polygon[0].Vertex[2] = vertex2[2];
00370     Brush[1].Polygon[0].Vertex[3] = vertex2[3];
00371     Brush[1].Polygon[0].Vertex[0].u = 0.0;
00372     Brush[1].Polygon[0].Vertex[0].v = 0.0;
00373     Brush[1].Polygon[0].Vertex[1].u = 1.0;
00374     Brush[1].Polygon[0].Vertex[1].v = 0.0;
00375     Brush[1].Polygon[0].Vertex[2].u = 1.0;
00376     Brush[1].Polygon[0].Vertex[2].v = 1.0;
00377     Brush[1].Polygon[0].Vertex[3].u = 0.0;
00378     Brush[1].Polygon[0].Vertex[3].v = 1.0;
00379     Brush[1].Polygon[0].Vertex[0].polyNumber = 14;
00380     Brush[1].Polygon[0].Vertex[1].polyNumber = 14;
00381     Brush[1].Polygon[0].Vertex[2].polyNumber = 14;
00382     Brush[1].Polygon[0].Vertex[3].polyNumber = 14;
00383     Brush[1].Polygon[0].Texture = texture[10].TexID;
00384 
00385 //Back
00386     Brush[1].Polygon[1].Vertex[0] = vertex2[5];
00387     Brush[1].Polygon[1].Vertex[1] = vertex2[4];
00388     Brush[1].Polygon[1].Vertex[2] = vertex2[7];
00389     Brush[1].Polygon[1].Vertex[3] = vertex2[6];
00390     Brush[1].Polygon[1].Vertex[0].u = 0.0;
00391     Brush[1].Polygon[1].Vertex[0].v = 0.0;
00392     Brush[1].Polygon[1].Vertex[1].u = 1.0;
00393     Brush[1].Polygon[1].Vertex[1].v = 0.0;
00394     Brush[1].Polygon[1].Vertex[2].u = 1.0;
00395     Brush[1].Polygon[1].Vertex[2].v = 1.0;
00396     Brush[1].Polygon[1].Vertex[3].u = 0.0;
00397     Brush[1].Polygon[1].Vertex[3].v = 1.0;
00398     Brush[1].Polygon[1].Vertex[0].polyNumber = 15;
00399     Brush[1].Polygon[1].Vertex[1].polyNumber = 15;
00400     Brush[1].Polygon[1].Vertex[2].polyNumber = 15;
00401     Brush[1].Polygon[1].Vertex[3].polyNumber = 15;
00402     Brush[1].Polygon[1].Texture = texture[10].TexID;
00403 
00404 //Left
00405     Brush[1].Polygon[2].Vertex[0] = vertex2[4];
00406     Brush[1].Polygon[2].Vertex[1] = vertex2[0];
00407     Brush[1].Polygon[2].Vertex[2] = vertex2[3];
00408     Brush[1].Polygon[2].Vertex[3] = vertex2[7];
00409     Brush[1].Polygon[2].Vertex[0].u = 0.0;
00410     Brush[1].Polygon[2].Vertex[0].v = 0.0;
00411     Brush[1].Polygon[2].Vertex[1].u = 1.0;
00412     Brush[1].Polygon[2].Vertex[1].v = 0.0;
00413     Brush[1].Polygon[2].Vertex[2].u = 1.0;
00414     Brush[1].Polygon[2].Vertex[2].v = 1.0;
00415     Brush[1].Polygon[2].Vertex[3].u = 0.0;
00416     Brush[1].Polygon[2].Vertex[3].v = 1.0;
00417     Brush[1].Polygon[2].Vertex[0].polyNumber = 16;
00418     Brush[1].Polygon[2].Vertex[1].polyNumber = 16;
00419     Brush[1].Polygon[2].Vertex[2].polyNumber = 16;
00420     Brush[1].Polygon[2].Vertex[3].polyNumber = 16;
00421     Brush[1].Polygon[2].Texture = texture[10].TexID;
00422 
00423 //Right
00424     Brush[1].Polygon[3].Vertex[0] = vertex2[1];
00425     Brush[1].Polygon[3].Vertex[1] = vertex2[5];
00426     Brush[1].Polygon[3].Vertex[2] = vertex2[6];
00427     Brush[1].Polygon[3].Vertex[3] = vertex2[2];
00428     Brush[1].Polygon[3].Vertex[0].u = 0.0;
00429     Brush[1].Polygon[3].Vertex[0].v = 0.0;
00430     Brush[1].Polygon[3].Vertex[1].u = 1.0;
00431     Brush[1].Polygon[3].Vertex[1].v = 0.0;
00432     Brush[1].Polygon[3].Vertex[2].u = 1.0;
00433     Brush[1].Polygon[3].Vertex[2].v = 1.0;
00434     Brush[1].Polygon[3].Vertex[3].u = 0.0;
00435     Brush[1].Polygon[3].Vertex[3].v = 1.0;
00436     Brush[1].Polygon[3].Vertex[0].polyNumber = 17;
00437     Brush[1].Polygon[3].Vertex[1].polyNumber = 17;
00438     Brush[1].Polygon[3].Vertex[2].polyNumber = 17;
00439     Brush[1].Polygon[3].Vertex[3].polyNumber = 17;
00440     Brush[1].Polygon[3].Texture = texture[10].TexID;
00441 
00442 //Top
00443     Brush[1].Polygon[4].Vertex[0] = vertex2[3];
00444     Brush[1].Polygon[4].Vertex[1] = vertex2[2];
00445     Brush[1].Polygon[4].Vertex[2] = vertex2[6];
00446     Brush[1].Polygon[4].Vertex[3] = vertex2[7];
00447     Brush[1].Polygon[4].Vertex[0].u = 0.0;
00448     Brush[1].Polygon[4].Vertex[0].v = 0.0;
00449     Brush[1].Polygon[4].Vertex[1].u = 1.0;
00450     Brush[1].Polygon[4].Vertex[1].v = 0.0;
00451     Brush[1].Polygon[4].Vertex[2].u = 1.0;
00452     Brush[1].Polygon[4].Vertex[2].v = 1.0;
00453     Brush[1].Polygon[4].Vertex[3].u = 0.0;
00454     Brush[1].Polygon[4].Vertex[3].v = 1.0;
00455     Brush[1].Polygon[4].Vertex[0].polyNumber = 18;
00456     Brush[1].Polygon[4].Vertex[1].polyNumber = 18;
00457     Brush[1].Polygon[4].Vertex[2].polyNumber = 18;
00458     Brush[1].Polygon[4].Vertex[3].polyNumber = 18;
00459     Brush[1].Polygon[4].Texture = texture[10].TexID;
00460 
00461 //Bottom
00462     Brush[1].Polygon[5].Vertex[0] = vertex2[5];
00463     Brush[1].Polygon[5].Vertex[1] = vertex2[1];
00464     Brush[1].Polygon[5].Vertex[2] = vertex2[0];
00465     Brush[1].Polygon[5].Vertex[3] = vertex2[4];
00466     Brush[1].Polygon[5].Vertex[0].u = 0.0;
00467     Brush[1].Polygon[5].Vertex[0].v = 0.0;
00468     Brush[1].Polygon[5].Vertex[1].u = 1.0;
00469     Brush[1].Polygon[5].Vertex[1].v = 0.0;
00470     Brush[1].Polygon[5].Vertex[2].u = 1.0;
00471     Brush[1].Polygon[5].Vertex[2].v = 1.0;
00472     Brush[1].Polygon[5].Vertex[3].u = 0.0;
00473     Brush[1].Polygon[5].Vertex[3].v = 1.0;
00474     Brush[1].Polygon[5].Vertex[0].polyNumber = 19;
00475     Brush[1].Polygon[5].Vertex[1].polyNumber = 19;
00476     Brush[1].Polygon[5].Vertex[2].polyNumber = 19;
00477     Brush[1].Polygon[5].Vertex[3].polyNumber = 19;
00478     Brush[1].Polygon[5].Texture = texture[10].TexID;
00479 
00480     for (int loop = 0; loop < Brush[1].numPolygons; loop++)
00481     {
00482         Brush[1].Polygon[loop].SetNormal();
00483     }
00484 
00485 // Set brush 3 polygons
00486 
00487 //Front
00488     Brush[2].Polygon[0].Vertex[0] = vertex3[0];
00489     Brush[2].Polygon[0].Vertex[1] = vertex3[1];
00490     Brush[2].Polygon[0].Vertex[2] = vertex3[2];
00491     Brush[2].Polygon[0].Vertex[3] = vertex3[3];
00492     Brush[2].Polygon[0].Vertex[0].u = 0.0;
00493     Brush[2].Polygon[0].Vertex[0].v = 0.0;
00494     Brush[2].Polygon[0].Vertex[1].u = 1.0;
00495     Brush[2].Polygon[0].Vertex[1].v = 0.0;
00496     Brush[2].Polygon[0].Vertex[2].u = 1.0;
00497     Brush[2].Polygon[0].Vertex[2].v = 1.0;
00498     Brush[2].Polygon[0].Vertex[3].u = 0.0;
00499     Brush[2].Polygon[0].Vertex[3].v = 1.0;
00500     Brush[2].Polygon[0].Vertex[0].polyNumber = 14;
00501     Brush[2].Polygon[0].Vertex[1].polyNumber = 14;
00502     Brush[2].Polygon[0].Vertex[2].polyNumber = 14;
00503     Brush[2].Polygon[0].Vertex[3].polyNumber = 14;
00504     Brush[2].Polygon[0].Texture = texture[10].TexID;
00505 
00506 //Back
00507     Brush[2].Polygon[1].Vertex[0] = vertex3[5];
00508     Brush[2].Polygon[1].Vertex[1] = vertex3[4];
00509     Brush[2].Polygon[1].Vertex[2] = vertex3[7];
00510     Brush[2].Polygon[1].Vertex[3] = vertex3[6];
00511     Brush[2].Polygon[1].Vertex[0].u = 0.0;
00512     Brush[2].Polygon[1].Vertex[0].v = 0.0;
00513     Brush[2].Polygon[1].Vertex[1].u = 1.0;
00514     Brush[2].Polygon[1].Vertex[1].v = 0.0;
00515     Brush[2].Polygon[1].Vertex[2].u = 1.0;
00516     Brush[2].Polygon[1].Vertex[2].v = 1.0;
00517     Brush[2].Polygon[1].Vertex[3].u = 0.0;
00518     Brush[2].Polygon[1].Vertex[3].v = 1.0;
00519     Brush[2].Polygon[1].Vertex[0].polyNumber = 15;
00520     Brush[2].Polygon[1].Vertex[1].polyNumber = 15;
00521     Brush[2].Polygon[1].Vertex[2].polyNumber = 15;
00522     Brush[2].Polygon[1].Vertex[3].polyNumber = 15;
00523     Brush[2].Polygon[1].Texture = texture[10].TexID;
00524 
00525 //Left
00526     Brush[2].Polygon[2].Vertex[0] = vertex3[4];
00527     Brush[2].Polygon[2].Vertex[1] = vertex3[0];
00528     Brush[2].Polygon[2].Vertex[2] = vertex3[3];
00529     Brush[2].Polygon[2].Vertex[3] = vertex3[7];
00530     Brush[2].Polygon[2].Vertex[0].u = 0.0;
00531     Brush[2].Polygon[2].Vertex[0].v = 0.0;
00532     Brush[2].Polygon[2].Vertex[1].u = 1.0;
00533     Brush[2].Polygon[2].Vertex[1].v = 0.0;
00534     Brush[2].Polygon[2].Vertex[2].u = 1.0;
00535     Brush[2].Polygon[2].Vertex[2].v = 1.0;
00536     Brush[2].Polygon[2].Vertex[3].u = 0.0;
00537     Brush[2].Polygon[2].Vertex[3].v = 1.0;
00538     Brush[2].Polygon[2].Vertex[0].polyNumber = 16;
00539     Brush[2].Polygon[2].Vertex[1].polyNumber = 16;
00540     Brush[2].Polygon[2].Vertex[2].polyNumber = 16;
00541     Brush[2].Polygon[2].Vertex[3].polyNumber = 16;
00542     Brush[2].Polygon[2].Texture = texture[10].TexID;
00543 
00544 //Right
00545     Brush[2].Polygon[3].Vertex[0] = vertex3[1];
00546     Brush[2].Polygon[3].Vertex[1] = vertex3[5];
00547     Brush[2].Polygon[3].Vertex[2] = vertex3[6];
00548     Brush[2].Polygon[3].Vertex[3] = vertex3[2];
00549     Brush[2].Polygon[3].Vertex[0].u = 0.0;
00550     Brush[2].Polygon[3].Vertex[0].v = 0.0;
00551     Brush[2].Polygon[3].Vertex[1].u = 1.0;
00552     Brush[2].Polygon[3].Vertex[1].v = 0.0;
00553     Brush[2].Polygon[3].Vertex[2].u = 1.0;
00554     Brush[2].Polygon[3].Vertex[2].v = 1.0;
00555     Brush[2].Polygon[3].Vertex[3].u = 0.0;
00556     Brush[2].Polygon[3].Vertex[3].v = 1.0;
00557     Brush[2].Polygon[3].Vertex[0].polyNumber = 17;
00558     Brush[2].Polygon[3].Vertex[1].polyNumber = 17;
00559     Brush[2].Polygon[3].Vertex[2].polyNumber = 17;
00560     Brush[2].Polygon[3].Vertex[3].polyNumber = 17;
00561     Brush[2].Polygon[3].Texture = texture[10].TexID;
00562 
00563 //Top
00564     Brush[2].Polygon[4].Vertex[0] = vertex3[3];
00565     Brush[2].Polygon[4].Vertex[1] = vertex3[2];
00566     Brush[2].Polygon[4].Vertex[2] = vertex3[6];
00567     Brush[2].Polygon[4].Vertex[3] = vertex3[7];
00568     Brush[2].Polygon[4].Vertex[0].u = 0.0;
00569     Brush[2].Polygon[4].Vertex[0].v = 0.0;
00570     Brush[2].Polygon[4].Vertex[1].u = 1.0;
00571     Brush[2].Polygon[4].Vertex[1].v = 0.0;
00572     Brush[2].Polygon[4].Vertex[2].u = 1.0;
00573     Brush[2].Polygon[4].Vertex[2].v = 1.0;
00574     Brush[2].Polygon[4].Vertex[3].u = 0.0;
00575     Brush[2].Polygon[4].Vertex[3].v = 1.0;
00576     Brush[2].Polygon[4].Vertex[0].polyNumber = 18;
00577     Brush[2].Polygon[4].Vertex[1].polyNumber = 18;
00578     Brush[2].Polygon[4].Vertex[2].polyNumber = 18;
00579     Brush[2].Polygon[4].Vertex[3].polyNumber = 18;
00580     Brush[2].Polygon[4].Texture = texture[10].TexID;
00581 
00582 //Bottom
00583     Brush[2].Polygon[5].Vertex[0] = vertex3[5];
00584     Brush[2].Polygon[5].Vertex[1] = vertex3[1];
00585     Brush[2].Polygon[5].Vertex[2] = vertex3[0];
00586     Brush[2].Polygon[5].Vertex[3] = vertex3[4];
00587     Brush[2].Polygon[5].Vertex[0].u = 0.0;
00588     Brush[2].Polygon[5].Vertex[0].v = 0.0;
00589     Brush[2].Polygon[5].Vertex[1].u = 1.0;
00590     Brush[2].Polygon[5].Vertex[1].v = 0.0;
00591     Brush[2].Polygon[5].Vertex[2].u = 1.0;
00592     Brush[2].Polygon[5].Vertex[2].v = 1.0;
00593     Brush[2].Polygon[5].Vertex[3].u = 0.0;
00594     Brush[2].Polygon[5].Vertex[3].v = 1.0;
00595     Brush[2].Polygon[5].Vertex[0].polyNumber = 19;
00596     Brush[2].Polygon[5].Vertex[1].polyNumber = 19;
00597     Brush[2].Polygon[5].Vertex[2].polyNumber = 19;
00598     Brush[2].Polygon[5].Vertex[3].polyNumber = 19;
00599     Brush[2].Polygon[5].Texture = texture[10].TexID;
00600 
00601     for (int loop = 0; loop < Brush[2].numPolygons; loop++)
00602     {
00603         Brush[2].Polygon[loop].SetNormal();
00604     }
00605 }
00606 
00607 
00608 void CreateBrushSet()
00609 {
00610     for (int loop = 0; loop < numBrushes; loop++)
00611     {
00612         BRUSH* newBrush = new BRUSH;
00613         *newBrush = Brush[loop];
00614         if (BrushSet)
00615             BrushSet->AddBrush(newBrush);            
00616         else
00617             BrushSet = newBrush;
00618     }
00619 }
00620 
00621 void ResetBrushes()
00622 {
00623     if (CSGflag)
00624         return;
00625 
00626     Brush[0].numPolygons = 6;
00627     Brush[1].numPolygons = 6;
00628     Brush[2].numPolygons = 6;
00629     Brush[0].id = 1;
00630     Brush[1].id = 2;
00631     Brush[2].id = 3;
00632 
00633     for (int loop = 0; loop < Brush[0].numPolygons; loop++)
00634     {
00635         Brush[0].Polygon[loop].id = loop;
00636         Brush[0].Polygon[loop].numVertices = 4;
00637     }
00638 
00639     for (int loop = 0; loop < Brush[1].numPolygons; loop++)
00640     {
00641         Brush[1].Polygon[loop].id = loop;
00642         Brush[1].Polygon[loop].numVertices = 4;
00643     }
00644 
00645     for (int loop = 0; loop < Brush[2].numPolygons; loop++)
00646     {
00647         Brush[2].Polygon[loop].id = loop;
00648         Brush[2].Polygon[loop].numVertices = 4;
00649     }
00650     Set1stVertices();
00651     Set2ndVertices();
00652     Set3rdVertices();
00653     SetBrushPolygons();
00654 
00655     if (BrushSet)
00656     {
00657         DeleteList(BrushSet);
00658         BrushSet = NULL;
00659     }
00660     CreateBrushSet();
00661 
00662     CSGflag = 1;
00663     return;
00664 }
00665 
00666 void RenderWireframeBrush(BRUSH* Brush)
00667 {
00668     glDisable(GL_TEXTURE_2D);
00669     glDisable(GL_LIGHTING);
00670     glColor3f(1.0, 1.0, 0.0); 
00671 
00672     for (int loop = 0; loop < Brush->numPolygons; loop++)
00673     {
00674         glBegin(GL_LINES);
00675             for (int innerloop = 0; innerloop < Brush->Polygon[loop].numVertices - 1; innerloop++)
00676             {
00677                 glVertex3fv(&Brush->Polygon[loop].Vertex[innerloop].coords.x);
00678                 glVertex3fv(&Brush->Polygon[loop].Vertex[innerloop + 1].coords.x);
00679             }
00680             glVertex3fv(&Brush->Polygon[loop].Vertex[Brush->Polygon[loop].numVertices - 1].coords.x);
00681             glVertex3fv(&Brush->Polygon[loop].Vertex[0].coords.x);
00682         glEnd();
00683     }
00684     glEnable(GL_TEXTURE_2D);
00685     glEnable(GL_LIGHTING);
00686 }
00687 
00688 void RenderTexturedBrush(BRUSH* Brush)
00689 {
00690     for (int loop = 0; loop < Brush->numPolygons; loop++)
00691     {
00692         glBindTexture(GL_TEXTURE_2D, Brush->Polygon[loop].Texture);
00693         glBegin(GL_POLYGON);
00694             glNormal3fv(&Brush->Polygon[loop].Vertex[0].normal.x);
00695             for (int innerloop = 0; innerloop < Brush->Polygon[loop].numVertices; innerloop++)
00696             {
00697                    glTexCoord2f(Brush->Polygon[loop].Vertex[innerloop].u, Brush->Polygon[loop].Vertex[innerloop].v);
00698                 glVertex3fv(&Brush->Polygon[loop].Vertex[innerloop].coords.x);
00699             }
00700             glTexCoord2f(Brush->Polygon[loop].Vertex[0].u, Brush->Polygon[loop].Vertex[0].v);
00701             glVertex3fv(&Brush->Polygon[loop].Vertex[0].coords.x);
00702         glEnd();
00703     }
00704 }
00705 
00706 void DrawBrushes()
00707 {
00708     glPushMatrix();
00709 
00710     if (CSGcullface)
00711         glDisable(GL_CULL_FACE);
00712 
00713     if (Texturing)
00714         RenderTexturedBrush(&Brush[0]);
00715     else
00716         RenderWireframeBrush(&Brush[0]);
00717 
00718     if (CSGflag)
00719     {
00720         if (Texturing)
00721         {
00722             RenderTexturedBrush(&Brush[1]);
00723             RenderTexturedBrush(&Brush[2]);
00724         }
00725         else
00726         {
00727             RenderWireframeBrush(&Brush[1]);
00728             RenderWireframeBrush(&Brush[2]);
00729         }
00730     }
00731 
00732     glEnable(GL_CULL_FACE);
00733     glPopMatrix();
00734 }

Generated on Fri Dec 23 05:15:46 2005 for Constructive Solid Geometry by doxygen1.2.15