MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / ClipEdge

Function ClipEdge

editor/Erooms.cpp:1504–1539  ·  view source on GitHub ↗

Clips on edge of a polygon against another edge Parameters: normal - defines the plane in which these edgs lie v0,v1 - the edge to be clipped v2,v3 - is the edge clipped against newv - filled in with the intersection point

Source from the content-addressed store, hash-verified

1502// v2,v3 - is the edge clipped against
1503// newv - filled in with the intersection point
1504void ClipEdge(vector *normal, vertex *v0, vertex *v1, vector *v2, vector *v3, vertex *newv) {
1505 float *vv0, *vv1, *vv2, *vv3;
1506 float k;
1507 int ii, jj;
1508
1509 // Get the vertices for projection
1510 GetIJ(normal, &ii, &jj);
1511
1512 // Get pointers to elements of our vectors
1513 vv0 = (float *)&v0->vec;
1514 vv1 = (float *)&v1->vec;
1515 vv2 = (float *)v2;
1516 vv3 = (float *)v3;
1517
1518 k = ((vv2[jj] - vv0[jj]) * (vv3[ii] - vv2[ii]) - (vv2[ii] - vv0[ii]) * (vv3[jj] - vv2[jj])) /
1519 ((vv1[jj] - vv0[jj]) * (vv3[ii] - vv2[ii]) - (vv1[ii] - vv0[ii]) * (vv3[jj] - vv2[jj]));
1520
1521 // Deal w/ precision problems
1522 if (k < 0.0) {
1523 ASSERT((vm_VectorDistance(&v1->vec, &v0->vec) * -k) < POINT_TO_EDGE_EPSILON);
1524 k = 0.0;
1525 }
1526 if (k > 1.0) {
1527 ASSERT((vm_VectorDistance(&v1->vec, &v0->vec) * (k - 1.0)) < POINT_TO_EDGE_EPSILON);
1528 k = 1.0;
1529 }
1530
1531 // Check for valid values of k
1532 ASSERT((k >= 0) && (k <= 1.0));
1533
1534 newv->vec = v0->vec + (v1->vec - v0->vec) * k;
1535
1536 newv->uvl.u = v0->uvl.u + (v1->uvl.u - v0->uvl.u) * k;
1537 newv->uvl.v = v0->uvl.v + (v1->uvl.v - v0->uvl.v) * k;
1538 newv->uvl.alpha = v0->uvl.alpha + ((v1->uvl.alpha - v0->uvl.alpha) * k);
1539}
1540
1541// Finds a shared edge, if one exists, between two faces in the same room
1542// Parameters: fp0,fp1 - pointers to the two faces

Callers 1

ClipAgainstEdgeFunction · 0.70

Calls 2

GetIJFunction · 0.85
vm_VectorDistanceFunction · 0.50

Tested by

no test coverage detected