public static bool IntersectSphereOBB(Sphere s1, OBB obb, ref Geometry.Geometric_Queries.Distance_Query_Result result) { var closer = obb.Closest_W_Point_On_OBB_To(s1.Position, 0); var res = s1.What_Faces(closer); if (res.Signed_Dist > 0.1f) { return(false); } result = new Geometry.Geometric_Queries.Distance_Query_Result(); var Extreme_Point_In_Normal_Of_Body_2 = closer; var Extreme_Point_In_Normal_Of_Body_1 = s1.Radius * res.Normal; result.signed_distance = res.Signed_Dist; result.first_has_normal = true; result.double_contact = false; result.Point_W_0 = closer; result.Normal_W = res.Normal; return(true); }
public static bool IntersectSphereTriangle(Sphere sphere, Triangle trig, ref Geometry.Geometric_Queries.Distance_Query_Result result) { var mink_sph = new Minkowski_Description(); mink_sph.HalfAxis = new Vector4(sphere.Radius, sphere.Radius, sphere.Radius, 1); mink_sph.Position_LM = sphere.Position - trig.Bary_center; var sphere_from_trig = trig.What_Faces(mink_sph); if (sphere_from_trig.Signed_Dist > 0.0f) { return(false); } result = new Geometry.Geometric_Queries.Distance_Query_Result(); result.first_has_normal = false; result.Normal_W = trig.Normals[sphere_from_trig.Normal_Code]; var Extreme_Point_In_Normal_Of_Body_1 = trig.Points[sphere_from_trig.Normal_Code] - Intersection_Grid.current_pair_element_2.Rigid.Position; var Extreme_Point_In_Normal_Of_Body_2 = -result.Normal_W * sphere.Radius; result.signed_distance = sphere_from_trig.Signed_Dist; result.double_contact = false; result.Point_W_0 = Extreme_Point_In_Normal_Of_Body_2 + sphere.Position; return(true); }
//*************************************************** //INTERSECTIONS public static bool IntersectOBBOBB(OBB obb1, OBB obb2, ref Geometry.Geometric_Queries.Distance_Query_Result result) { var mink2 = Minkowski.Minkowskize_OBB_In_OBB(obb2, obb1); var mink1 = Minkowski.Minkowskize_OBB_In_OBB(obb1, obb2); var dist_of_2_from_1 = obb1.What_Faces(mink2); var dist_of_1_from_2 = obb2.What_Faces(mink1); if (Math.Max(dist_of_1_from_2.Signed_Dist, dist_of_2_from_1.Signed_Dist) > 0) { return(false); } Minkowski_Description mink; Facing_Point_Result data; //pernoume os normal owning afto pou exei to allo pio exo bool normal_owning_first = dist_of_2_from_1.Signed_Dist > dist_of_1_from_2.Signed_Dist; var normal_owning_obb = (normal_owning_first) ? obb1 : obb2; var selected_obb = (!normal_owning_first) ? obb1 : obb2; mink = (normal_owning_first) ? mink2 : mink1; data = (normal_owning_first) ? dist_of_2_from_1 : dist_of_1_from_2; Vector3 p0; Vector3 p1; float d_0, d_1; var normal = normal_owning_obb.Normal(data.Normal_Code); OBB.Extraction_of_inner_contact_points2(normal_owning_obb, selected_obb, normal, data.Normal_Code, out p0, out p1, out d_0, out d_1); var test = p0 - p1; result = new Geometry.Geometric_Queries.Distance_Query_Result(); result.first_has_normal = normal_owning_first; result.Normal_W = normal; result.signed_distance = normal_owning_first ? dist_of_2_from_1.Signed_Dist : dist_of_1_from_2.Signed_Dist; result.double_contact = (Math.Abs(d_1 - d_0) < 0.3f); GELib.Debug.Debug_Drawing.double_edge = result.double_contact; result.Point_W_0 = p0; result.Point_W_1 = p1; return(true); }
public static bool IntersectOBBTriangle(OBB obb, Triangle trig, ref Geometry.Geometric_Queries.Distance_Query_Result result) { var minked_tri = Minkowski.Minkowskize_Triangle_In_OBB(trig, obb); var minked_obb = Minkowski.Minkowskize_OBB_In_Triangle(obb, trig); var tr_from_obb = obb.What_Faces(minked_tri); var obb_from_tr = trig.What_Faces(minked_obb); if (Math.Max(tr_from_obb.Signed_Dist, obb_from_tr.Signed_Dist) > 0.0f) { return(false); } //pernoume os normal owning afto pou exei to allo pio exo bool normal_owning_tr = obb_from_tr.Signed_Dist > tr_from_obb.Signed_Dist; if (normal_owning_tr) { result = new Geometry.Geometric_Queries.Distance_Query_Result(); result.first_has_normal = !normal_owning_tr; result.Normal_W = trig.Normals[obb_from_tr.Normal_Code]; var Extreme_Point_In_Normal_Of_Body_1 = trig.Points[obb_from_tr.Normal_Code] - Intersection_Grid.current_pair_element_2.Rigid.Position; var Extreme_Point_In_Normal_Of_Body_2 = obb.Vertex(obb.Extreme_In(-result.Normal_W).code) - obb.Position; result.signed_distance = obb_from_tr.Signed_Dist; result.double_contact = false; result.Point_W_0 = Extreme_Point_In_Normal_Of_Body_2 + obb.Position; } else { result = new Geometry.Geometric_Queries.Distance_Query_Result(); result.first_has_normal = !normal_owning_tr; result.Normal_W = obb.Normal(tr_from_obb.Normal_Code); var Extreme_Point_In_Normal_Of_Body_1 = obb.Vertex(tr_from_obb.Normal_Code) - obb.parent_tmp.Position; var Extreme_Point_In_Normal_Of_Body_2 = trig.Points[(trig.Extreme_In(-result.Normal_W).code)] - Intersection_Grid.current_pair_element_2.Rigid.Position; result.signed_distance = tr_from_obb.Signed_Dist; result.Point_W_0 = Extreme_Point_In_Normal_Of_Body_2 + Intersection_Grid.current_pair_element_2.Rigid.Position; } return(true); }
public static bool IntersectSphereTriangle(Sphere sphere, Triangle trig, ref Geometry.Geometric_Queries.Distance_Query_Result result) { var mink_sph = new Minkowski_Description(); mink_sph.HalfAxis = new Vector4(sphere.Radius, sphere.Radius, sphere.Radius,1); mink_sph.Position_LM = sphere.Position - trig.Bary_center; var sphere_from_trig = trig.What_Faces(mink_sph); if (sphere_from_trig.Signed_Dist > 0.0f) return false; result = new Geometry.Geometric_Queries.Distance_Query_Result(); result.first_has_normal = false; result.Normal_W = trig.Normals[sphere_from_trig.Normal_Code]; var Extreme_Point_In_Normal_Of_Body_1 = trig.Points[sphere_from_trig.Normal_Code] - Intersection_Grid.current_pair_element_2.Rigid.Position; var Extreme_Point_In_Normal_Of_Body_2 = -result.Normal_W * sphere.Radius; result.signed_distance = sphere_from_trig.Signed_Dist; result.double_contact=false; result.Point_W_0 = Extreme_Point_In_Normal_Of_Body_2 + sphere.Position; return true; }
public static bool IntersectSphereOBB(Sphere s1, OBB obb, ref Geometry.Geometric_Queries.Distance_Query_Result result) { var closer = obb.Closest_W_Point_On_OBB_To(s1.Position, 0); var res = s1.What_Faces(closer); if (res.Signed_Dist>0.1f) return false; result = new Geometry.Geometric_Queries.Distance_Query_Result(); var Extreme_Point_In_Normal_Of_Body_2 = closer; var Extreme_Point_In_Normal_Of_Body_1 = s1.Radius * res.Normal; result.signed_distance = res.Signed_Dist; result.first_has_normal = true; result.double_contact = false; result.Point_W_0 = closer; result.Normal_W = res.Normal; return true; }
public static bool IntersectOBBTriangle(OBB obb, Triangle trig, ref Geometry.Geometric_Queries.Distance_Query_Result result) { var minked_tri = Minkowski.Minkowskize_Triangle_In_OBB(trig, obb); var minked_obb = Minkowski.Minkowskize_OBB_In_Triangle(obb, trig); var tr_from_obb = obb.What_Faces(minked_tri); var obb_from_tr = trig.What_Faces(minked_obb); if (Math.Max(tr_from_obb.Signed_Dist, obb_from_tr.Signed_Dist) > 0.0f) return false; //pernoume os normal owning afto pou exei to allo pio exo bool normal_owning_tr = obb_from_tr.Signed_Dist>tr_from_obb.Signed_Dist; if (normal_owning_tr) { result = new Geometry.Geometric_Queries.Distance_Query_Result(); result.first_has_normal = !normal_owning_tr; result.Normal_W = trig.Normals[obb_from_tr.Normal_Code]; var Extreme_Point_In_Normal_Of_Body_1 = trig.Points[obb_from_tr.Normal_Code]-Intersection_Grid.current_pair_element_2.Rigid.Position; var Extreme_Point_In_Normal_Of_Body_2 = obb.Vertex(obb.Extreme_In(-result.Normal_W).code)-obb.Position; result.signed_distance = obb_from_tr.Signed_Dist; result.double_contact = false; result.Point_W_0 = Extreme_Point_In_Normal_Of_Body_2+obb.Position; } else { result = new Geometry.Geometric_Queries.Distance_Query_Result(); result.first_has_normal = !normal_owning_tr; result.Normal_W = obb.Normal(tr_from_obb.Normal_Code); var Extreme_Point_In_Normal_Of_Body_1 = obb.Vertex(tr_from_obb.Normal_Code)-obb.parent_tmp.Position; var Extreme_Point_In_Normal_Of_Body_2 = trig.Points[(trig.Extreme_In(-result.Normal_W).code)] - Intersection_Grid.current_pair_element_2.Rigid.Position; result.signed_distance = tr_from_obb.Signed_Dist; result.Point_W_0 = Extreme_Point_In_Normal_Of_Body_2+Intersection_Grid.current_pair_element_2.Rigid.Position; } return true; }
//*************************************************** //INTERSECTIONS public static bool IntersectOBBOBB(OBB obb1, OBB obb2, ref Geometry.Geometric_Queries.Distance_Query_Result result) { var mink2 = Minkowski.Minkowskize_OBB_In_OBB(obb2, obb1); var mink1 = Minkowski.Minkowskize_OBB_In_OBB(obb1, obb2); var dist_of_2_from_1 = obb1.What_Faces(mink2); var dist_of_1_from_2 = obb2.What_Faces(mink1); if (Math.Max(dist_of_1_from_2.Signed_Dist, dist_of_2_from_1.Signed_Dist) > 0) return false; Minkowski_Description mink; Facing_Point_Result data; //pernoume os normal owning afto pou exei to allo pio exo bool normal_owning_first = dist_of_2_from_1.Signed_Dist > dist_of_1_from_2.Signed_Dist; var normal_owning_obb = (normal_owning_first) ? obb1 : obb2; var selected_obb = (!normal_owning_first) ? obb1 : obb2; mink = (normal_owning_first) ? mink2 : mink1; data = (normal_owning_first) ? dist_of_2_from_1 : dist_of_1_from_2; Vector3 p0; Vector3 p1; float d_0, d_1; var normal = normal_owning_obb.Normal(data.Normal_Code); OBB.Extraction_of_inner_contact_points2(normal_owning_obb, selected_obb, normal, data.Normal_Code,out p0, out p1, out d_0, out d_1 ); var test = p0 - p1; result = new Geometry.Geometric_Queries.Distance_Query_Result(); result.first_has_normal = normal_owning_first; result.Normal_W = normal; result.signed_distance = normal_owning_first ? dist_of_2_from_1.Signed_Dist : dist_of_1_from_2.Signed_Dist; result.double_contact = (Math.Abs(d_1-d_0) < 0.3f); GELib.Debug.Debug_Drawing.double_edge = result.double_contact; result.Point_W_0 = p0; result.Point_W_1 = p1; return true; }