12     (((A).x < 0) ? 4 : 0 | ((A).y < 0) ? 2 : 0 | ((A).z < 0) ? 1 : 0)    16     ((((A).x < EPS) ? 4 : 0) | (((A).x > -EPS) ? 32 : 0) | \    17      (((A).y < EPS) ? 2 : 0) | (((A).y > -EPS) ? 16 : 0) | \    18      (((A).z < EPS) ? 1 : 0) | (((A).z > -EPS) ? 8 : 0))    21 #define CROSS(A, B, C)                          \    23         (C).x = (A).y * (B).z - (A).z * (B).y;  \    24         (C).y = -(A).x * (B).z + (A).z * (B).x; \    25         (C).z = (A).x * (B).y - (A).y * (B).x;  \    27 #define SUB(A, B, C)           \    29         (C).x = (A).x - (B).x; \    30         (C).y = (A).y - (B).y; \    31         (C).z = (A).z - (B).z; \    33 #define LERP(A, B, C) ((B) + (A) * ((C) - (B)))    34 #define MIN3(a, b, c) \    35     ((((a) < (b)) && ((a) < (c))) ? (a) : (((b) < (c)) ? (b) : (c)))    36 #define MAX3(a, b, c) \    37     ((((a) > (b)) && ((a) > (c))) ? (a) : (((b) > (c)) ? (b) : (c)))    57 long face_plane(
Point3 p) {
   104     if (-p.y + p.z > 1.0)
   106     if (-p.y - p.z > 1.0)
   119     if ((p.x + p.y + p.z) > 1.5)
   121     if ((p.x + p.y - p.z) > 1.5)
   123     if ((p.x - p.y + p.z) > 1.5)
   125     if ((p.x - p.y - p.z) > 1.5)
   127     if ((-p.x + p.y + p.z) > 1.5)
   129     if ((-p.x + p.y - p.z) > 1.5)
   131     if ((-p.x - p.y + p.z) > 1.5)
   133     if ((-p.x - p.y - p.z) > 1.5)
   144 long check_point(
Point3 p1, 
Point3 p2, 
float alpha, 
long mask) {
   147     plane_point.x = LERP(alpha, p1.x, p2.x);
   148     plane_point.y = LERP(alpha, p1.y, p2.y);
   149     plane_point.z = LERP(alpha, p1.z, p2.z);
   150     return (face_plane(plane_point) & mask);
   160 long check_line(
Point3 p1, 
Point3 p2, 
long outcode_diff) {
   161     if ((0x01 & outcode_diff) != 0)
   162         if (check_point(p1, p2, (.5 - p1.x) / (p2.x - p1.x), 0x3e) == INSIDE)
   164     if ((0x02 & outcode_diff) != 0)
   165         if (check_point(p1, p2, (-.5 - p1.x) / (p2.x - p1.x), 0x3d) == INSIDE)
   167     if ((0x04 & outcode_diff) != 0)
   168         if (check_point(p1, p2, (.5 - p1.y) / (p2.y - p1.y), 0x3b) == INSIDE)
   170     if ((0x08 & outcode_diff) != 0)
   171         if (check_point(p1, p2, (-.5 - p1.y) / (p2.y - p1.y), 0x37) == INSIDE)
   173     if ((0x10 & outcode_diff) != 0)
   174         if (check_point(p1, p2, (.5 - p1.z) / (p2.z - p1.z), 0x2f) == INSIDE)
   176     if ((0x20 & outcode_diff) != 0)
   177         if (check_point(p1, p2, (-.5 - p1.z) / (p2.z - p1.z), 0x1f) == INSIDE)
   187     long sign12, sign23, sign31;
   188     Point3 vect12, vect23, vect31, vect1h, vect2h, vect3h;
   189     Point3 cross12_1p, cross23_2p, cross31_3p;
   194     if (p.x > MAX3(t.v1.x, t.v2.x, t.v3.x))
   196     if (p.y > MAX3(t.v1.y, t.v2.y, t.v3.y))
   198     if (p.z > MAX3(t.v1.z, t.v2.z, t.v3.z))
   200     if (p.x < MIN3(t.v1.x, t.v2.x, t.v3.x))
   202     if (p.y < MIN3(t.v1.y, t.v2.y, t.v3.y))
   204     if (p.z < MIN3(t.v1.z, t.v2.z, t.v3.z))
   214     SUB(t.v1, t.v2, vect12)
   215     SUB(t.v1, p, vect1h);
   216     CROSS(vect12, vect1h, cross12_1p)
   220     SUB(t.v2, t.v3, vect23)
   221     SUB(t.v2, p, vect2h);
   222     CROSS(vect23, vect2h, cross23_2p)
   223     sign23 = SIGN3(cross23_2p);
   225     SUB(t.v3, t.v1, vect31)
   226     SUB(t.v3, p, vect3h);
   227     CROSS(vect31, vect3h, cross31_3p)
   228     sign31 = SIGN3(cross31_3p);
   237     if ((sign12 == sign23) && (sign23 == sign31))
   242     return ((sign12 & sign23 & sign31) == 0) ? OUTSIDE : INSIDE;
   257     long v1_test, v2_test, v3_test;
   260     Point3 vect12, vect13, norm;
   261     Point3 hitpp, hitpn, hitnp, hitnn;
   266     if ((v1_test = face_plane(t.v1)) == INSIDE)
   268     if ((v2_test = face_plane(t.v2)) == INSIDE)
   270     if ((v3_test = face_plane(t.v3)) == INSIDE)
   276     if ((v1_test & v2_test & v3_test) != 0)
   281     v1_test |= bevel_2d(t.v1) << 8;
   282     v2_test |= bevel_2d(t.v2) << 8;
   283     v3_test |= bevel_2d(t.v3) << 8;
   284     if ((v1_test & v2_test & v3_test) != 0)
   289     v1_test |= bevel_3d(t.v1) << 24;
   290     v2_test |= bevel_3d(t.v2) << 24;
   291     v3_test |= bevel_3d(t.v3) << 24;
   292     if ((v1_test & v2_test & v3_test) != 0)
   302     if ((v1_test & v2_test) == 0)
   303         if (check_line(t.v1, t.v2, v1_test | v2_test) == INSIDE)
   305     if ((v1_test & v3_test) == 0)
   306         if (check_line(t.v1, t.v3, v1_test | v3_test) == INSIDE)
   308     if ((v2_test & v3_test) == 0)
   309         if (check_line(t.v2, t.v3, v2_test | v3_test) == INSIDE)
   324     SUB(t.v1, t.v2, vect12);
   325     SUB(t.v1, t.v3, vect13);
   326     CROSS(vect12, vect13, norm)
   337     d = norm.x * t.v1.x + norm.y * t.v1.y + norm.z * t.v1.z;
   341     if (fabs(denom = (norm.x + norm.y + norm.z)) > EPS)
   344         hitpp.x = hitpp.y = hitpp.z = d / denom;
   345         if (fabs(hitpp.x) <= 0.5)
   346             if (point_triangle_intersection(hitpp, t) == INSIDE)
   349     if (fabs(denom = (norm.x + norm.y - norm.z)) > EPS) {
   350         hitpn.z = -(hitpn.x = hitpn.y = d / denom);
   351         if (fabs(hitpn.x) <= 0.5)
   352             if (point_triangle_intersection(hitpn, t) == INSIDE)
   355     if (fabs(denom = (norm.x - norm.y + norm.z)) > EPS) {
   356         hitnp.y = -(hitnp.x = hitnp.z = d / denom);
   357         if (fabs(hitnp.x) <= 0.5)
   358             if (point_triangle_intersection(hitnp, t) == INSIDE)
   361     if (fabs(denom = (norm.x - norm.y - norm.z)) > EPS) {
   362         hitnn.y = hitnn.z = -(hitnn.x = d / denom);
   363         if (fabs(hitnn.x) <= 0.5)
   364             if (point_triangle_intersection(hitnn, t) == INSIDE)
 Definition: tri_cube_c.h:41
Definition: tri_cube_c.h:47