#include "polygon.h"#include "lightmap.h"#include "portal.h"#include "tll.h"Go to the source code of this file.
Compounds | |
| struct | BSP_node |
Typedefs | |
| typedef BSP_node | BSP_node |
Enumerations | |
| enum | { Front, Back, TwoFrontOneBack, OneFrontTwoBack, OneFrontOneBack, PortalWasSplit, OnPartition } |
Functions | |
| int | FindCurrentLeaf (VECTOR Position, BSP_node *node) |
| int | SplitPolygon (POLYGON, POLYGON, POLYGON *) |
| int | SelectPartitionfromList (POLYGON *nodepolylist, int numpolys, int *bestfront, int *bestback) |
| void | BuildBSP (BSP_node *node) |
| int | RenderBSP (BSP_node *node) |
| void | DeleteBSP (BSP_node *node) |
| void | DrawIntersectionSphere (VECTOR coordinates) |
|
|
|
|
|
Definition at line 10 of file bsp.h.
00010 {Front, Back, TwoFrontOneBack, OneFrontTwoBack, OneFrontOneBack, PortalWasSplit, OnPartition};
|
|
|
Definition at line 114 of file bsp.cpp. References Back, BSP_node::backnode, Front, BSP_node::frontnode, BSP_node::leaf, BSP_node::nodeid, BSP_node::nodepolylist, numleaves, numpartitions, BSP_node::numpolys, BSP_node::numportals, OneFrontOneBack, OneFrontTwoBack, BSP_node::partition, SelectPartitionfromList(), SplitPolygon(), TwoFrontOneBack, and BSP_node::visible. Referenced by InitGL().
00115 {
00116 int result, front, back, polytoclassify, partplane;
00117 POLYGON output[3];
00118
00119 partplane = SelectPartitionfromList(node->nodepolylist, node->numpolys, &front, &back);
00120
00121 if (partplane == -1)
00122 {
00123 node->nodeid = ++numleaves;
00124 node->leaf = true;
00125 return;
00126 }
00127
00128 node->nodeid = ++numpartitions;
00129 node->partition = node->nodepolylist[partplane];
00130
00131 //Allocate memory for a front and back node
00132 node->frontnode = new BSP_node;
00133 node->frontnode->visible = 0;
00134 node->frontnode->leaf = 0;
00135 node->frontnode->numpolys = front;
00136 node->frontnode->nodepolylist = new POLYGON[front];
00137 node->frontnode->numportals = 0;
00138
00139 node->backnode = new BSP_node;
00140 node->backnode->visible = 0;
00141 node->backnode->leaf = 0;
00142 node->backnode->numpolys = back;
00143 node->backnode->nodepolylist = new POLYGON[back];
00144 node->backnode->numportals = 0;
00145 //Classify each polygon in the current node with respect to the partitioning plane.
00146 front = back = 0;
00147 for (polytoclassify = 0; polytoclassify < node->numpolys; polytoclassify++)
00148 {
00149 output[0] = node->nodepolylist[polytoclassify];
00150 output[1] = node->nodepolylist[polytoclassify];
00151 output[2] = node->nodepolylist[polytoclassify];
00152
00153 result = SplitPolygon(node->nodepolylist[polytoclassify], node->partition, output);
00154 switch (result)
00155 {
00156 case Front:
00157 node->frontnode->nodepolylist[front] = node->nodepolylist[polytoclassify];
00158 front++;
00159 break;
00160
00161 case Back:
00162 node->backnode->nodepolylist[back] = node->nodepolylist[polytoclassify];
00163 back++;
00164 break;
00165
00166 case TwoFrontOneBack:
00167 node->frontnode->nodepolylist[front] = output[0];
00168 node->frontnode->nodepolylist[front + 1] = output[1];
00169 front += 2;
00170 node->backnode->nodepolylist[back] = output[2];
00171 back++;
00172 break;
00173
00174 case OneFrontTwoBack:
00175 node->frontnode->nodepolylist[front] = output[0];
00176 front++;
00177 node->backnode->nodepolylist[back] = output[1];
00178 node->backnode->nodepolylist[back + 1] = output[2];
00179 back += 2;
00180 break;
00181
00182 case OneFrontOneBack:
00183 node->frontnode->nodepolylist[front] = output[0];
00184 front++;
00185 node->backnode->nodepolylist[back] = output[1];
00186 back++;
00187 break;
00188 }
00189 }
00190
00191 node->numpolys = 0;
00192 delete[] node->nodepolylist;
00193 node->nodepolylist = 0;
00194 // delete[] node->nodelightmaplist;
00195
00196 BuildBSP(node->frontnode);
00197 BuildBSP(node->backnode);
00198 }
|
|
|
Definition at line 327 of file bsp.cpp. References BSP_node::backnode, LinkedList< PORTAL >::Delete(), BSP_node::frontnode, LinkedList< PORTAL >::Get(), BSP_node::leaf, BSP_node::nodelightmaplist, BSP_node::nodepolylist, BSP_node::numportals, BSP_node::portallist, and PORTAL::Vertex. Referenced by WndProc().
00328 {
00329 if (node->leaf == true)
00330 {
00331 delete[] node->nodepolylist;
00332 delete[] node->nodelightmaplist;
00333 for (int i = node->numportals; i > 0 ; i--)
00334 {
00335 PORTAL* temp = node->portallist.Get(i);
00336 delete[] temp->Vertex;
00337 node->portallist.Delete(i);
00338 delete temp;
00339 }
00340 node->numportals = 0;
00341 return;
00342 }
00343
00344 DeleteBSP(node->frontnode);
00345 delete node->frontnode;
00346 DeleteBSP(node->backnode);
00347 delete node->backnode;
00348 }
|
|
|
Definition at line 350 of file bsp.cpp. References VECTOR::x, VECTOR::y, and VECTOR::z.
00351 {
00352 float mat_ambient[] = { 0.2, 1.0, 0.1, 1.0 };
00353 float mat_diffuse[] = { 0.2, 1.0, 0.1, 1.0 };
00354 glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
00355 glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
00356 glDisable(GL_TEXTURE_2D);
00357 glPushMatrix();
00358 glTranslatef(coordinates.x, coordinates.y, coordinates.z);
00359 GLUquadricObj * sphere = gluNewQuadric();
00360 gluQuadricOrientation(sphere, GLU_OUTSIDE);
00361 gluSphere(sphere,0.3,20,20);
00362 glPopMatrix();
00363 glEnable(GL_TEXTURE_2D);
00364 }
|
|
||||||||||||
|
Definition at line 27 of file bsp.cpp. References BSP_node::backnode, ClassifyPoint(), CrossVector(), BSP_node::frontnode, BSP_node::leaf, BSP_node::nodeid, numcurrentportals, BSP_node::numportals, BSP_node::partition, POLYGON::Vertex, VERTEX::x, VECTOR::x, VERTEX::y, VECTOR::y, VERTEX::z, and VECTOR::z. Referenced by DrawGLScene().
00028 {
00029 if (node->leaf == true)
00030 {
00031 numcurrentportals = node->numportals;
00032 return node->nodeid;
00033 }
00034
00035 VECTOR edge1, edge2, planeNormal, temp;
00036 // get the partitioning planes normal
00037 edge1.x = node->partition.Vertex[1].x - node->partition.Vertex[0].x;
00038 edge1.y = node->partition.Vertex[1].y - node->partition.Vertex[0].y;
00039 edge1.z = node->partition.Vertex[1].z - node->partition.Vertex[0].z;
00040 edge2.x = node->partition.Vertex[2].x - node->partition.Vertex[0].x;
00041 edge2.y = node->partition.Vertex[2].y - node->partition.Vertex[0].y;
00042 edge2.z = node->partition.Vertex[2].z - node->partition.Vertex[0].z;
00043 planeNormal = CrossVector(edge1, edge2);
00044 temp.x = node->partition.Vertex[0].x;
00045 temp.y = node->partition.Vertex[0].y;
00046 temp.z = node->partition.Vertex[0].z;
00047
00048 int side = ClassifyPoint(Position, temp, planeNormal);
00049
00050 if (side == 1 || side == 0)
00051 {
00052 return FindCurrentLeaf(Position, node->frontnode);
00053 }
00054 else
00055 {
00056 return FindCurrentLeaf(Position, node->backnode);
00057 }
00058 }
|
|
|
Definition at line 200 of file bsp.cpp. References BSP_node::backnode, ClassifyPoint(), CrossVector(), currentCamera, currentleaf, BSP_node::frontnode, LinkedList< PORTAL >::Get(), BSP_node::leaf, BSP_node::nodeid, BSP_node::nodelightmaplist, BSP_node::nodepolylist, BSP_node::numpolys, BSP_node::numportals, PORTAL::numVertices, VERTEX::nx, BSP_node::partition, BSP_node::portallist, POLYGON::Rotate, POLYGON::Scale, POLYGON::Shift, SphereSector, TEXTURE::TexID, Lightmap::Texture, POLYGON::Texture, VERTEX::u, VERTEX::v, PORTAL::Vertex, POLYGON::Vertex, Lightmap::vertex_u, Lightmap::vertex_v, BSP_node::visible, VERTEX::x, VECTOR::x, VERTEX::y, VECTOR::y, VERTEX::z, and VECTOR::z. Referenced by DrawWorld().
00201 {
00202 int Side;
00203 VECTOR Position, edge1, edge2, planeNormal, temp;
00204
00205 //The current position of the player/viewpoint
00206 Position.x = camera[currentCamera].Position.x;
00207 Position.y = camera[currentCamera].Position.y;
00208 Position.z = camera[currentCamera].Position.z;
00209
00210 if (!node->leaf)
00211 {
00212 // get the partitioning planes normal
00213 edge1.x = node->partition.Vertex[1].x - node->partition.Vertex[0].x;
00214 edge1.y = node->partition.Vertex[1].y - node->partition.Vertex[0].y;
00215 edge1.z = node->partition.Vertex[1].z - node->partition.Vertex[0].z;
00216 edge2.x = node->partition.Vertex[2].x - node->partition.Vertex[0].x;
00217 edge2.y = node->partition.Vertex[2].y - node->partition.Vertex[0].y;
00218 edge2.z = node->partition.Vertex[2].z - node->partition.Vertex[0].z;
00219 planeNormal = CrossVector(edge1, edge2);
00220 temp.x = node->partition.Vertex[0].x;
00221 temp.y = node->partition.Vertex[0].y;
00222 temp.z = node->partition.Vertex[0].z;
00223 Side = ClassifyPoint(Position, temp, planeNormal);
00224
00225 if (Side == -1)
00226 {
00227 RenderBSP(node->frontnode);
00228 RenderBSP(node->backnode);
00229 }
00230 else
00231 {
00232 RenderBSP(node->backnode);
00233 RenderBSP(node->frontnode);
00234 }
00235 }
00236
00237 if (node->leaf && node->visible)
00238 {
00239 node->visible = false;
00240 //Draw polygons that are in the leaf
00241 for (int loop = 0; loop < node->numpolys; loop++)
00242 {
00243 glMatrixMode(GL_TEXTURE);
00244 glPushMatrix();
00245
00246 glScalef(node->nodepolylist[loop].Scale[0], node->nodepolylist[loop].Scale[1], 1.0f);
00247 glTranslatef(node->nodepolylist[loop].Shift[0], node->nodepolylist[loop].Shift[1], 0.0f);
00248 glRotatef(node->nodepolylist[loop].Rotate, 0.0f, 0.0f, 1.0f);
00249 glBindTexture(GL_TEXTURE_2D, node->nodepolylist[loop].Texture);
00250 glBegin(GL_TRIANGLES);
00251 glNormal3fv(&node->nodepolylist[loop].Vertex[0].nx);
00252 glTexCoord2f(node->nodepolylist[loop].Vertex[0].u, node->nodepolylist[loop].Vertex[0].v);
00253 glVertex3fv(&node->nodepolylist[loop].Vertex[0].x);
00254 glTexCoord2f(node->nodepolylist[loop].Vertex[1].u, node->nodepolylist[loop].Vertex[1].v);
00255 glVertex3fv(&node->nodepolylist[loop].Vertex[1].x);
00256 glTexCoord2f(node->nodepolylist[loop].Vertex[2].u, node->nodepolylist[loop].Vertex[2].v);
00257 glVertex3fv(&node->nodepolylist[loop].Vertex[2].x);
00258 glEnd();
00259 glPopMatrix();
00260 glMatrixMode(GL_MODELVIEW);
00261
00262 glEnable(GL_BLEND);
00263 glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
00264
00265 glBindTexture(GL_TEXTURE_2D, node->nodelightmaplist[loop].Texture.TexID);
00266 glBegin(GL_TRIANGLES);
00267 glNormal3fv(&node->nodepolylist[loop].Vertex[0].nx);
00268 glTexCoord2f(node->nodelightmaplist[loop].vertex_u[0], node->nodelightmaplist[loop].vertex_v[0]);
00269 glVertex3fv(&node->nodepolylist[loop].Vertex[0].x);
00270 glTexCoord2f(node->nodelightmaplist[loop].vertex_u[1], node->nodelightmaplist[loop].vertex_v[1]);
00271 glVertex3fv(&node->nodepolylist[loop].Vertex[1].x);
00272 glTexCoord2f(node->nodelightmaplist[loop].vertex_u[2], node->nodelightmaplist[loop].vertex_v[2]);
00273 glVertex3fv(&node->nodepolylist[loop].Vertex[2].x);
00274 glEnd();
00275 glDisable(GL_BLEND);
00276 }
00277
00278 if (showportals)
00279 {
00280 // Draw the leaf portals
00281 glDisable(GL_TEXTURE_2D);
00282 glDisable(GL_LIGHTING);
00283 glEnable(GL_BLEND);
00284 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00285 glEnable(GL_ALPHA_TEST);
00286 glAlphaFunc(GL_GREATER, 0);
00287 glColor4f(1.0, 1.0, 0.0, 0.2);
00288
00289 if (currentleaf == node->nodeid)
00290 {
00291 for (int loop = 1; loop <= node->numportals; loop++)
00292 {
00293 PORTAL* tempportal = node->portallist.Get(loop);
00294 glBegin(GL_POLYGON);
00295 glNormal3fv(&tempportal->Vertex[0].nx);
00296 for (int innerloop = 0; innerloop < tempportal->numVertices; innerloop++)
00297 glVertex3f(tempportal->Vertex[innerloop].x, tempportal->Vertex[innerloop].y, tempportal->Vertex[innerloop].z);
00298 glEnd();
00299 }
00300 }
00301 glDisable(GL_BLEND);
00302 glDisable(GL_ALPHA_TEST);
00303 glEnable(GL_TEXTURE_2D);
00304 glEnable(GL_LIGHTING);
00305 }
00306
00307 if (SphereSector == node->nodeid)
00308 {
00309 // Draw sphere at sound position
00310 float mat_ambient[] = { 0.2, 1.0, 0.1, 1.0 };
00311 float mat_diffuse[] = { 0.2, 1.0, 0.1, 1.0 };
00312 glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
00313 glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
00314 glDisable(GL_TEXTURE_2D);
00315 glPushMatrix();
00316 glTranslatef(SpherePosition.x, SpherePosition.y, SpherePosition.z);
00317 GLUquadricObj * sphere = gluNewQuadric();
00318 gluQuadricOrientation(sphere, GLU_OUTSIDE);
00319 gluSphere(sphere,0.3,20,20);
00320 glPopMatrix();
00321 glEnable(GL_TEXTURE_2D);
00322 }
00323 }
00324 return 1;
00325 }
|
|
||||||||||||||||||||
|
Definition at line 60 of file bsp.cpp. References Back, Front, OneFrontOneBack, OneFrontTwoBack, SplitPolygon(), and TwoFrontOneBack. Referenced by BuildBSP().
00061 {
00062 int count = 0, result, absdifference = 1000000000, bestplane = 0, front, back, potentialplane, polytoclassify;
00063 VECTOR temp;
00064
00065 // Loop through all the polygons and find the best splitting plane
00066 for(potentialplane = 0; potentialplane < numpolys; potentialplane++)
00067 {
00068 front = back = 0;
00069 for (polytoclassify = 0; polytoclassify < numpolys; polytoclassify++)
00070 {
00071 result = SplitPolygon(nodepolylist[polytoclassify], nodepolylist[potentialplane], NULL);
00072 switch (result)
00073 {
00074 case Front:
00075 front++;
00076 break;
00077
00078 case Back:
00079 back++;
00080 break;
00081
00082 case TwoFrontOneBack:
00083 front += 2;
00084 back++;
00085 break;
00086
00087 case OneFrontTwoBack:
00088 front++;
00089 back += 2;
00090 break;
00091
00092 case OneFrontOneBack:
00093 front++;
00094 back++;
00095 break;
00096 }
00097 }
00098 if (abs(front - back) < absdifference)
00099 {
00100 absdifference = abs(front - back);
00101 bestplane = potentialplane;
00102 *bestfront = front;
00103 *bestback = back;
00104 }
00105 if (front == 0 || back == 0)
00106 count++;
00107 }
00108 if (count == numpolys)
00109 return -1;
00110 else
00111 return bestplane;
00112 }
|
|
||||||||||||||||
|
Definition at line 385 of file polygon.cpp.
00386 {
00387 VECTOR planeNormal, polysNormal, pointOnPlane, edge1, edge2, temp;
00388 VERTEX ptA, ptB, outpts[4], inpts[4], intersection;
00389 int count = 0, out_c = 0, in_c = 0, sideA, sideB, outputFlag;
00390 VERTEX texvert1, texvert2; // texture calculation variables
00391 VECTOR t1, t2;
00392 float scale;
00393
00394 // get a point on the plane
00395 pointOnPlane.x = planeTriangle.Vertex[0].x;
00396 pointOnPlane.y = planeTriangle.Vertex[0].y;
00397 pointOnPlane.z = planeTriangle.Vertex[0].z;
00398
00399 // get the splitting planes normal
00400 edge1.x = planeTriangle.Vertex[1].x - planeTriangle.Vertex[0].x;
00401 edge1.y = planeTriangle.Vertex[1].y - planeTriangle.Vertex[0].y;
00402 edge1.z = planeTriangle.Vertex[1].z - planeTriangle.Vertex[0].z;
00403 edge2.x = planeTriangle.Vertex[2].x - planeTriangle.Vertex[0].x;
00404 edge2.y = planeTriangle.Vertex[2].y - planeTriangle.Vertex[0].y;
00405 edge2.z = planeTriangle.Vertex[2].z - planeTriangle.Vertex[0].z;
00406 planeNormal = CrossVector(edge1, edge2);
00407
00408 // get the normal of the triangle to split
00409 edge1.x = triangleToSplit.Vertex[1].x - triangleToSplit.Vertex[0].x;
00410 edge1.y = triangleToSplit.Vertex[1].y - triangleToSplit.Vertex[0].y;
00411 edge1.z = triangleToSplit.Vertex[1].z - triangleToSplit.Vertex[0].z;
00412 edge2.x = triangleToSplit.Vertex[2].x - triangleToSplit.Vertex[0].x;
00413 edge2.y = triangleToSplit.Vertex[2].y - triangleToSplit.Vertex[0].y;
00414 edge2.z = triangleToSplit.Vertex[2].z - triangleToSplit.Vertex[0].z;
00415 polysNormal = CrossVector(edge1, edge2);
00416
00417 // check if the triangle lies on the plane
00418 for (int loop = 0; loop < 3; loop++)
00419 {
00420 temp.x = triangleToSplit.Vertex[loop].x;
00421 temp.y = triangleToSplit.Vertex[loop].y;
00422 temp.z = triangleToSplit.Vertex[loop].z;
00423 if (ClassifyPoint(temp, pointOnPlane, planeNormal) == 0)
00424 count++;
00425 else
00426 break;
00427 }
00428 if (count == 3)
00429 {
00430 if (ClassifyPoint(polysNormal, pointOnPlane, planeNormal) == 1)
00431 return Front;
00432 if (ClassifyPoint(polysNormal, pointOnPlane, planeNormal) == -1)
00433 return Back;
00434 }
00435
00436 // find if all of the points are infront of or behind the plane
00437 int frontcount = 0, backcount = 0;
00438 for (int loop = 0; loop < 3; loop++)
00439 {
00440 temp.x = triangleToSplit.Vertex[loop].x;
00441 temp.y = triangleToSplit.Vertex[loop].y;
00442 temp.z = triangleToSplit.Vertex[loop].z;
00443 if (ClassifyPoint(temp, pointOnPlane, planeNormal) == 0)
00444 {
00445 frontcount++;
00446 backcount++;
00447 }
00448 else if (ClassifyPoint(temp, pointOnPlane, planeNormal) == 1)
00449 frontcount++;
00450 else if (ClassifyPoint(temp, pointOnPlane, planeNormal) == -1)
00451 backcount++;
00452 }
00453 if (frontcount == 3)
00454 return Front;
00455 if (backcount == 3)
00456 return Back;
00457
00458 // try to split the triangle
00459 ptA = triangleToSplit.Vertex[2];
00460 temp.x = ptA.x;
00461 temp.y = ptA.y;
00462 temp.z = ptA.z;
00463 sideA = ClassifyPoint(temp, pointOnPlane, planeNormal);
00464 for (int i = -1; ++i < 3;)
00465 {
00466 ptB = triangleToSplit.Vertex[i];
00467 temp.x = ptB.x;
00468 temp.y = ptB.y;
00469 temp.z = ptB.z;
00470 sideB = ClassifyPoint(temp, pointOnPlane, planeNormal);
00471 if (sideB > 0)
00472 {
00473 if (sideA < 0)
00474 {
00475 // find intersection
00476 edge1.x = ptA.x;
00477 edge1.y = ptA.y;
00478 edge1.z = ptA.z;
00479 edge2.x = ptB.x;
00480 edge2.y = ptB.y;
00481 edge2.z = ptB.z;
00482
00483 temp = GetEdgeIntersection(edge1, edge2, planeTriangle);
00484 intersection.x = temp.x;
00485 intersection.y = temp.y;
00486 intersection.z = temp.z;
00487
00488 // find the new texture coordinates
00489 texvert1.x = ptB.x - ptA.x;
00490 texvert1.y = ptB.y - ptA.y;
00491 texvert1.z = ptB.z - ptA.z;
00492 texvert2.x = intersection.x - ptA.x;
00493 texvert2.y = intersection.y - ptA.y;
00494 texvert2.z = intersection.z - ptA.z;
00495 texvert1.u = ptA.u;
00496 texvert2.u = ptB.u;
00497 texvert1.v = ptA.v;
00498 texvert2.v = ptB.v;
00499 t1.x = texvert1.x;
00500 t1.y = texvert1.y;
00501 t1.z = texvert1.z;
00502 t2.x = texvert2.x;
00503 t2.y = texvert2.y;
00504 t2.z = texvert2.z;
00505 scale = sqrt(t2.x*t2.x+t2.y*t2.y+t2.z*t2.z)/sqrt(t1.x*t1.x+t1.y*t1.y+t1.z*t1.z);
00506 intersection.u = texvert1.u + (texvert2.u - texvert1.u) * scale;
00507 intersection.v = texvert1.v + (texvert2.v - texvert1.v) * scale;
00508
00509 outpts[out_c++] = inpts[in_c++] = intersection;
00510 }
00511 inpts[in_c++] = ptB;
00512 }
00513 else if (sideB < 0)
00514 {
00515 if (sideA > 0)
00516 {
00517 // find intersection
00518 edge1.x = ptA.x;
00519 edge1.y = ptA.y;
00520 edge1.z = ptA.z;
00521 edge2.x = ptB.x;
00522 edge2.y = ptB.y;
00523 edge2.z = ptB.z;
00524
00525 temp = GetEdgeIntersection(edge1, edge2, planeTriangle);
00526 intersection.x = temp.x;
00527 intersection.y = temp.y;
00528 intersection.z = temp.z;
00529
00530 // find the new texture coordinates
00531 texvert1.x = ptB.x - ptA.x;
00532 texvert1.y = ptB.y - ptA.y;
00533 texvert1.z = ptB.z - ptA.z;
00534 texvert2.x = intersection.x - ptA.x;
00535 texvert2.y = intersection.y - ptA.y;
00536 texvert2.z = intersection.z - ptA.z;
00537 texvert1.u = ptA.u;
00538 texvert2.u = ptB.u;
00539 texvert1.v = ptA.v;
00540 texvert2.v = ptB.v;
00541 t1.x = texvert1.x;
00542 t1.y = texvert1.y;
00543 t1.z = texvert1.z;
00544 t2.x = texvert2.x;
00545 t2.y = texvert2.y;
00546 t2.z = texvert2.z;
00547 scale = sqrt(t2.x*t2.x+t2.y*t2.y+t2.z*t2.z)/sqrt(t1.x*t1.x+t1.y*t1.y+t1.z*t1.z);
00548 intersection.u = texvert1.u + (texvert2.u - texvert1.u) * scale;
00549 intersection.v = texvert1.v + (texvert2.v - texvert1.v) * scale;
00550
00551 outpts[out_c++] = inpts[in_c++] = intersection;
00552 }
00553 outpts[out_c++] = ptB;
00554 }
00555 else
00556 outpts[out_c++] = inpts[in_c++] = ptB;
00557 ptA = ptB;
00558 sideA = sideB;
00559 }
00560
00561 if (in_c == 4) // two triangles are infront, one behind
00562 {
00563 outputFlag = TwoFrontOneBack;
00564 if (triangles)
00565 {
00566 triangles[0].Vertex[0] = inpts[0];
00567 triangles[0].Vertex[1] = inpts[1];
00568 triangles[0].Vertex[2] = inpts[2];
00569 triangles[0].numVertices = 3;
00570 triangles[0].SetNormal();
00571 triangles[1].Vertex[0] = inpts[0];
00572 triangles[1].Vertex[1] = inpts[2];
00573 triangles[1].Vertex[2] = inpts[3];
00574 triangles[1].numVertices = 3;
00575 triangles[1].SetNormal();
00576 triangles[2].Vertex[0] = outpts[0];
00577 triangles[2].Vertex[1] = outpts[1];
00578 triangles[2].Vertex[2] = outpts[2];
00579 triangles[2].numVertices = 3;
00580 triangles[2].SetNormal();
00581 }
00582 }
00583 else if (out_c == 4) // one triangle is infront, two behind
00584 {
00585 outputFlag = OneFrontTwoBack;
00586 if (triangles)
00587 {
00588 triangles[0].Vertex[0] = inpts[0];
00589 triangles[0].Vertex[1] = inpts[1];
00590 triangles[0].Vertex[2] = inpts[2];
00591 triangles[0].numVertices = 3;
00592 triangles[0].SetNormal();
00593 triangles[1].Vertex[0] = outpts[0];
00594 triangles[1].Vertex[1] = outpts[1];
00595 triangles[1].Vertex[2] = outpts[2];
00596 triangles[1].numVertices = 3;
00597 triangles[1].SetNormal();
00598 triangles[2].Vertex[0] = outpts[0];
00599 triangles[2].Vertex[1] = outpts[2];
00600 triangles[2].Vertex[2] = outpts[3];
00601 triangles[2].numVertices = 3;
00602 triangles[2].SetNormal();
00603 }
00604 }
00605 else if (in_c == 3 && out_c == 3) // plane bisects the triangle
00606 {
00607 outputFlag = OneFrontOneBack;
00608 if (triangles)
00609 {
00610 triangles[0].Vertex[0] = inpts[0];
00611 triangles[0].Vertex[1] = inpts[1];
00612 triangles[0].Vertex[2] = inpts[2];
00613 triangles[0].numVertices = 3;
00614 triangles[0].SetNormal();
00615 triangles[1].Vertex[0] = outpts[0];
00616 triangles[1].Vertex[1] = outpts[1];
00617 triangles[1].Vertex[2] = outpts[2];
00618 triangles[1].numVertices = 3;
00619 triangles[1].SetNormal();
00620 }
00621 }
00622 else // then triangle must be totally infront of or behind the plane
00623 {
00624 int side;
00625
00626 for (int loop = 0; loop < 3; loop++)
00627 {
00628 temp.x = triangleToSplit.Vertex[loop].x;
00629 temp.y = triangleToSplit.Vertex[loop].y;
00630 temp.z = triangleToSplit.Vertex[loop].z;
00631 side = ClassifyPoint(temp, pointOnPlane, planeNormal);
00632 if (side == 1)
00633 {
00634 outputFlag = Front;
00635 break;
00636 }
00637 else if (side == -1)
00638 {
00639 outputFlag = Back;
00640 break;
00641 }
00642 }
00643 }
00644 return outputFlag;
00645 }
|
1.2.15