00001 #include "sysdep.h" 00002 #include "mytritri.h" 00003 00004 Vector3D my_tri_tri_intersect(const Triangle& t1, const Triangle& t2) 00005 { 00006 Plane p1(t1.v1,t1.v2,t1.v3); 00007 int other_side=0; 00008 { 00009 float f1=p1.Classify(t2.v1); 00010 float f2=p1.Classify(t2.v2); 00011 float f3=p1.Classify(t2.v3); 00012 float f12=f1*f2; 00013 float f23=f2*f3; 00014 if (f12>0.0f && f23>0.0f) return Vector3D::Zero; 00015 other_side=(f12<0.0f?(f23<0.0f?1:0):2); 00016 } 00017 Plane p2(t2.v1,t2.v2,t2.v3); 00018 Vector3D n12(p1.normal+p2.normal); 00019 TriangleDesc td2(t2,p2); 00020 const Vector3D& a2=td2[other_side+1]; 00021 const Vector3D& b2=td2[other_side]; 00022 const Vector3D& c2=td2[other_side+2]; 00023 float t21=-(p1.d+p2.d+a2*n12)/((b2-a2)*n12); 00024 TriangleDesc td1(t1,p1); 00025 Vector3D P21(a2+t21*(b2-a2)); 00026 if (td1.pointInTri(P21)) return P21; 00027 float t22=-(p1.d+p2.d+c2*n12)/((b2-c2)*n12); 00028 Vector3D P22(c2+t22*(b2-c2)); 00029 if (td1.pointInTri(P22)) return P22; 00030 00031 { 00032 float f1=p2.Classify(t1.v1); 00033 float f2=p2.Classify(t1.v2); 00034 float f3=p2.Classify(t1.v3); 00035 float f12=f1*f2; 00036 float f23=f2*f3; 00037 if (f12>0.0f && f23>0.0f) return Vector3D::Zero; 00038 other_side=(f12<0.0f?(f23<0.0f?1:0):2); 00039 } 00040 const Vector3D& a1=td1[other_side+1]; 00041 const Vector3D& b1=td1[other_side]; 00042 const Vector3D& c1=td1[other_side+2]; 00043 float t11=-(p1.d+p2.d+a1*n12)/((b1-a1)*n12); 00044 Vector3D P11(a1+t11*(b1-a1)); 00045 if (td2.pointInTri(P11)) return P11; 00046 float t12=-(p1.d+p2.d+c1*n12)/((b1-c1)*n12); 00047 Vector3D P12(c1+t12*(b1-c1)); 00048 if (td2.pointInTri(P12)) return P12; 00049 return Vector3D::Zero; 00050 }