public void Merge(ref AABB box) { m_min.X = BoxCollision.BT_MIN(m_min.X, box.m_min.X); m_min.Y = BoxCollision.BT_MIN(m_min.Y, box.m_min.Y); m_min.Z = BoxCollision.BT_MIN(m_min.Z, box.m_min.Z); m_max.X = BoxCollision.BT_MAX(m_max.X, box.m_max.X); m_max.Y = BoxCollision.BT_MAX(m_max.Y, box.m_max.Y); m_max.Z = BoxCollision.BT_MAX(m_max.Z, box.m_max.Z); }
//! transcache is the transformation cache from box to this AABB public bool OverlappingTransCache(ref AABB box, ref BT_BOX_BOX_TRANSFORM_CACHE transcache, bool fulltest) { //Taken from OPCODE IndexedVector3 ea, eb;//extends IndexedVector3 ca, cb;//extends GetCenterExtend(out ca, out ea); box.GetCenterExtend(out cb, out eb); IndexedVector3 T = new IndexedVector3(0, 0, 0); float t, t2; int i; // Class I : A's basis vectors for (i = 0; i < 3; i++) { T[i] = transcache.m_R1to0[i].Dot(ref cb) + transcache.m_T1to0[i] - ca[i]; t = transcache.m_AR[i].Dot(ref eb) + ea[i]; if (BoxCollision.BT_GREATER(T[i], t)) { return false; } } // Class II : B's basis vectors for (i = 0; i < 3; i++) { t = Mat3DotCol(ref transcache.m_R1to0, ref T, i); t2 = Mat3DotCol(ref transcache.m_AR, ref ea, i) + eb[i]; if (BoxCollision.BT_GREATER(t, t2)) { return false; } } // Class III : 9 cross products if (fulltest) { // check to see if these need to be restored back or are read-only float[,] m_R1to0 = MathUtil.BasisMatrixToFloatArray(ref transcache.m_R1to0); float[,] m_AR = MathUtil.BasisMatrixToFloatArray(ref transcache.m_AR); int j, m, n, o, p, q, r; for (i = 0; i < 3; i++) { m = (i + 1) % 3; n = (i + 2) % 3; o = i == 0 ? 1 : 0; p = i == 2 ? 1 : 2; for (j = 0; j < 3; j++) { q = j == 2 ? 1 : 2; r = j == 0 ? 1 : 0; t = T[n] * m_R1to0[m, j] - T[m] * m_R1to0[n, j]; t2 = ea[o] * m_AR[p, j] + ea[p] * m_AR[o, j] + eb[r] * m_AR[i, q] + eb[q] * m_AR[i, r]; if (BoxCollision.BT_GREATER(t, t2)) return false; } } } return true; }
public bool OverlappingTransConservative2(ref AABB box, BT_BOX_BOX_TRANSFORM_CACHE trans1_to_0) { AABB tbox = box; tbox.ApplyTransformTransCache(ref trans1_to_0); return HasCollision(ref tbox); }
public void GetTrianglesIntersectingSphere(ref BoundingSphere sphere, Vector3? referenceNormalVector, float? maxAngle, List<MyTriangle_Vertex_Normals> retTriangles, int maxNeighbourTriangles) { var aabb = BoundingBoxHelper.InitialBox; BoundingBoxHelper.AddSphere(ref sphere, ref aabb); AABB gi_aabb = new AABB(ref aabb.Min, ref aabb.Max); m_overlappedTriangles.Clear(); if (m_bvh.BoxQuery(ref gi_aabb, m_overlappedTriangles)) { // temporary variable for storing tirngle boundingbox info BoundingBox triangleBoundingBox = new BoundingBox(); for (int i = 0; i < m_overlappedTriangles.Count; i++) { var triangleIndex = m_overlappedTriangles[i]; // If we reached end of the buffer of neighbour triangles, we stop adding new ones. This is better behavior than throwing exception because of array overflow. if (retTriangles.Count == maxNeighbourTriangles) return; m_model.GetTriangleBoundingBox(triangleIndex, ref triangleBoundingBox); // First test intersection of triangleVertexes's bounding box with bounding sphere. And only if they overlap or intersect, do further intersection tests. if (MyUtils.IsBoxIntersectingSphere(triangleBoundingBox, ref sphere) == true) { //if (m_triangleIndices[value] != ignoreTriangleWithIndex) { // See that we swaped vertex indices!! MyTriangle_Vertexes triangle; MyTriangle_Normals triangleNormals; MyTriangle_Normals triangleBinormals; MyTriangle_Normals triangleTangents; MyTriangleVertexIndices triangleIndices = m_model.Triangles[triangleIndex]; m_model.GetVertex(triangleIndices.I0, triangleIndices.I2, triangleIndices.I1, out triangle.Vertex0, out triangle.Vertex1, out triangle.Vertex2); /* triangle.Vertex0 = m_model.GetVertex(triangleIndices.I0); triangle.Vertex1 = m_model.GetVertex(triangleIndices.I2); triangle.Vertex2 = m_model.GetVertex(triangleIndices.I1); */ triangleNormals.Normal0 = m_model.GetVertexNormal(triangleIndices.I0); triangleNormals.Normal1 = m_model.GetVertexNormal(triangleIndices.I2); triangleNormals.Normal2 = m_model.GetVertexNormal(triangleIndices.I1); if (MinerWars.AppCode.Game.Render.MyRenderConstants.RenderQualityProfile.ForwardRender) { triangleBinormals.Normal0 = triangleNormals.Normal0; triangleBinormals.Normal1 = triangleNormals.Normal1; triangleBinormals.Normal2 = triangleNormals.Normal2; triangleTangents.Normal0 = triangleNormals.Normal0; triangleTangents.Normal1 = triangleNormals.Normal1; triangleTangents.Normal2 = triangleNormals.Normal2; } else { triangleBinormals.Normal0 = m_model.GetVertexBinormal(triangleIndices.I0); triangleBinormals.Normal1 = m_model.GetVertexBinormal(triangleIndices.I2); triangleBinormals.Normal2 = m_model.GetVertexBinormal(triangleIndices.I1); triangleTangents.Normal0 = m_model.GetVertexTangent(triangleIndices.I0); triangleTangents.Normal1 = m_model.GetVertexTangent(triangleIndices.I2); triangleTangents.Normal2 = m_model.GetVertexTangent(triangleIndices.I1); } MyPlane trianglePlane = new MyPlane(ref triangle); if (MyUtils.GetSphereTriangleIntersection(ref sphere, ref trianglePlane, ref triangle) != null) { Vector3 triangleNormal = MyUtils.GetNormalVectorFromTriangle(ref triangle); if ((referenceNormalVector.HasValue == false) || (maxAngle.HasValue == false) || ((MyUtils.GetAngleBetweenVectors(referenceNormalVector.Value, triangleNormal) <= maxAngle))) { MyTriangle_Vertex_Normals retTriangle; retTriangle.Vertexes = triangle; retTriangle.Normals = triangleNormals; retTriangle.Binormals = triangleBinormals; retTriangle.Tangents = triangleTangents; retTriangles.Add(retTriangle); } } } } } } }
protected void GImpactTrimeshpartVsPlaneCollision( CollisionObject body0, CollisionObject body1, GImpactMeshShapePart shape0, StaticPlaneShape shape1, bool swapped) { IndexedMatrix orgtrans0 = body0.GetWorldTransform(); IndexedMatrix orgtrans1 = body1.GetWorldTransform(); IndexedVector4 plane; PlaneShape.GetPlaneEquationTransformed(shape1,ref orgtrans1, out plane); //test box against plane AABB tribox = new AABB(); shape0.GetAabb(ref orgtrans0, out tribox.m_min, out tribox.m_max); tribox.IncrementMargin(shape1.GetMargin()); if (tribox.PlaneClassify(ref plane) != BT_PLANE_INTERSECTION_TYPE.BT_CONST_COLLIDE_PLANE) return; shape0.LockChildShapes(); float margin = shape0.GetMargin() + shape1.GetMargin(); IndexedVector3 vertex; int vi = shape0.GetVertexCount(); while (vi-- != 0) { shape0.GetVertex(vi, out vertex); vertex = orgtrans0 * vertex; float distance = IndexedVector3.Dot(vertex, MathUtil.Vector4ToVector3(ref plane)) - plane.W - margin; if (distance < 0.0f)//add contact { if (swapped) { AddContactPoint(body1, body0, vertex, MathUtil.Vector4ToVector3(-plane), distance); } else { AddContactPoint(body0, body1, vertex, MathUtil.Vector4ToVector3(ref plane), distance); } } } shape0.UnlockChildShapes(); }
protected void GImpactVsGImpactFindPairs( ref IndexedMatrix trans0, ref IndexedMatrix trans1, GImpactShapeInterface shape0, GImpactShapeInterface shape1, PairSet pairset) { if (shape0.HasBoxSet() && shape1.HasBoxSet()) { GImpactQuantizedBvh.FindCollision(shape0.GetBoxSet(), ref trans0, shape1.GetBoxSet(), ref trans1, pairset); } else { AABB boxshape0 = new AABB(); AABB boxshape1 = new AABB(); int i = shape0.GetNumChildShapes(); while (i-- != 0) { shape0.GetChildAabb(i, ref trans0, out boxshape0.m_min, out boxshape0.m_max); int j = shape1.GetNumChildShapes(); while (j-- != 0) { shape1.GetChildAabb(i, ref trans1, out boxshape1.m_min, out boxshape1.m_max); if (boxshape1.HasCollision(ref boxshape0)) { pairset.PushPair(i, j); } } } } if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactAlgo) { BulletGlobals.g_streamWriter.WriteLine("GImpactAglo::GImpactVsGImpactFindPairs [{0}]", pairset.Count); } }
//! Merges a Box public void Merge(AABB box) { Merge(ref box); }
public void GetTrianglesIntersectingSphere(ref BoundingSphereD sphere, List<MyTriangle_Vertex_Normal> retTriangles, int maxNeighbourTriangles) { Vector3? referenceNormalVector = null; float? maxAngle = null; var aabb = BoundingBox.CreateInvalid(); BoundingSphere sphereF = (BoundingSphere)sphere; aabb.Include(ref sphereF); AABB gi_aabb = new AABB(aabb.Min.ToBullet(), aabb.Max.ToBullet()); m_overlappedTriangles.Clear(); // VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("m_bvh.BoxQuery"); // This code is called recursively and cause profiler to lag bool res = m_bvh.BoxQuery(ref gi_aabb, m_overlappedTriangles); // VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); if (res) { //VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("m_overlappedTriangles"); // This code is called recursively and cause profiler to lag // temporary variable for storing tirngle boundingbox info BoundingBox triangleBoundingBox = new BoundingBox(); for (int i = 0; i < m_overlappedTriangles.Count; i++) { var triangleIndex = m_overlappedTriangles[i]; // If we reached end of the buffer of neighbour triangles, we stop adding new ones. This is better behavior than throwing exception because of array overflow. if (retTriangles.Count == maxNeighbourTriangles) return; m_model.GetTriangleBoundingBox(triangleIndex, ref triangleBoundingBox); //gi_aabb.CollideTriangleExact // First test intersection of triangleVertexes's bounding box with bounding sphere. And only if they overlap or intersect, do further intersection tests. if (triangleBoundingBox.Intersects(ref sphere)) { //if (m_triangleIndices[value] != ignoreTriangleWithIndex) { // See that we swaped vertex indices!! MyTriangle_Vertices triangle; MyTriangleVertexIndices triangleIndices = m_model.Triangles[triangleIndex]; triangle.Vertex0 = m_model.GetVertex(triangleIndices.I0); triangle.Vertex1 = m_model.GetVertex(triangleIndices.I2); triangle.Vertex2 = m_model.GetVertex(triangleIndices.I1); Vector3 calculatedTriangleNormal = MyUtils.GetNormalVectorFromTriangle(ref triangle); PlaneD trianglePlane = new PlaneD(triangle.Vertex0, triangle.Vertex1, triangle.Vertex2); if (MyUtils.GetSphereTriangleIntersection(ref sphere, ref trianglePlane, ref triangle) != null) { Vector3 triangleNormal = MyUtils.GetNormalVectorFromTriangle(ref triangle); if ((referenceNormalVector.HasValue == false) || (maxAngle.HasValue == false) || ((MyUtils.GetAngleBetweenVectors(referenceNormalVector.Value, triangleNormal) <= maxAngle))) { MyTriangle_Vertex_Normal retTriangle; retTriangle.Vertexes = triangle; retTriangle.Normal = calculatedTriangleNormal; retTriangles.Add(retTriangle); } } } } } //VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); } }
public AABB(ref AABB other) { m_max = other.m_max; m_min = other.m_min; }
public override void ProcessAllTriangles(ITriangleCallback callback, ref IndexedVector3 aabbMin, ref IndexedVector3 aabbMax) { LockChildShapes(); AABB box = new AABB(); box.m_min = aabbMin; box.m_max = aabbMax; ObjectArray<int> collided = new ObjectArray<int>(); m_box_set.BoxQuery(ref box, collided); if (collided.Count == 0) { UnlockChildShapes(); return; } int part = GetPart(); PrimitiveTriangle triangle = new PrimitiveTriangle(); int i = collided.Count; while (i-- != 0) { GetPrimitiveTriangle(collided[i], triangle); callback.ProcessTriangle(triangle.m_vertices, part, collided[i]); } UnlockChildShapes(); }
public virtual void GetPrimitiveBox(int prim_index, out AABB primbox) { PrimitiveTriangle triangle = new PrimitiveTriangle(); GetPrimitiveTriangle(prim_index, triangle); primbox = new AABB(); primbox.CalcFromTriangleMargin( ref triangle.m_vertices[0], ref triangle.m_vertices[1], ref triangle.m_vertices[2], triangle.m_margin); }
public virtual void GetPrimitiveBox(int prim_index, out AABB primbox) { IndexedMatrix prim_trans; if (m_compoundShape.ChildrenHasTransform()) { prim_trans = m_compoundShape.GetChildTransform(prim_index); } else { prim_trans = IndexedMatrix.Identity; } CollisionShape shape = m_compoundShape.GetChildShape(prim_index); shape.GetAabb(prim_trans, out primbox.m_min, out primbox.m_max); }
protected GImpactQuantizedBvh m_box_set = new GImpactQuantizedBvh();// optionally boxset //! declare Quantized trees, (you can change to float based trees) //typedef btGImpactQuantizedBvh btGImpactBoxSet; //! Base class for gimpact shapes //class btGImpactShapeInterface : public ConcaveShape //{ //protected: // btAABB m_localAABB; // bool m_needs_update; // btVector3 localScaling; // btGImpactBoxSet m_box_set;// optionally boxset //! use this function for perfofm refit in bounding boxes //! use this function for perfofm refit in bounding boxes protected virtual void CalcLocalAABB() { LockChildShapes(); if (m_box_set.GetNodeCount() == 0) { m_box_set.BuildSet(); } else { m_box_set.Update(); } UnlockChildShapes(); m_localAABB = m_box_set.GetGlobalBox(); }
public virtual void GetAabb(ref IndexedMatrix t, ref IndexedVector3 aabbMin, ref IndexedVector3 aabbMax) { IndexedVector3 tv0 = t * m_vertices1[0]; IndexedVector3 tv1 = t * m_vertices1[1]; IndexedVector3 tv2 = t * m_vertices1[2]; AABB trianglebox = new AABB(ref tv0, ref tv1, ref tv2, m_collisionMargin); aabbMin = trianglebox.m_min; aabbMax = trianglebox.m_max; }
public void GetTrianglesIntersectingSphere(ref BoundingSphereD sphere, Vector3? referenceNormalVector, float? maxAngle, List<MyTriangle_Vertex_Normals> retTriangles, int maxNeighbourTriangles) { var aabb = BoundingBox.CreateInvalid(); BoundingSphere sphereF = (BoundingSphere)sphere; aabb.Include(ref sphereF); AABB gi_aabb = new AABB(aabb.Min.ToBullet(), aabb.Max.ToBullet()); m_overlappedTriangles.Clear(); if (m_bvh.BoxQuery(ref gi_aabb, m_overlappedTriangles)) { // temporary variable for storing tirngle boundingbox info BoundingBox triangleBoundingBox = new BoundingBox(); for (int i = 0; i < m_overlappedTriangles.Count; i++) { var triangleIndex = m_overlappedTriangles[i]; // If we reached end of the buffer of neighbour triangles, we stop adding new ones. This is better behavior than throwing exception because of array overflow. if (retTriangles.Count == maxNeighbourTriangles) return; m_model.GetTriangleBoundingBox(triangleIndex, ref triangleBoundingBox); // First test intersection of triangleVertexes's bounding box with bounding sphere. And only if they overlap or intersect, do further intersection tests. if (triangleBoundingBox.Intersects(ref sphere)) { //if (m_triangleIndices[value] != ignoreTriangleWithIndex) { // See that we swaped vertex indices!! MyTriangle_Vertices triangle; MyTriangle_Normals triangleNormals; //MyTriangle_Normals triangleTangents; MyTriangleVertexIndices triangleIndices = m_model.Triangles[triangleIndex]; m_model.GetVertex(triangleIndices.I0, triangleIndices.I2, triangleIndices.I1, out triangle.Vertex0, out triangle.Vertex1, out triangle.Vertex2); /* triangle.Vertex0 = m_model.GetVertex(triangleIndices.I0); triangle.Vertex1 = m_model.GetVertex(triangleIndices.I2); triangle.Vertex2 = m_model.GetVertex(triangleIndices.I1); */ triangleNormals.Normal0 = m_model.GetVertexNormal(triangleIndices.I0); triangleNormals.Normal1 = m_model.GetVertexNormal(triangleIndices.I2); triangleNormals.Normal2 = m_model.GetVertexNormal(triangleIndices.I1); PlaneD trianglePlane = new PlaneD(triangle.Vertex0, triangle.Vertex1, triangle.Vertex2); if (MyUtils.GetSphereTriangleIntersection(ref sphere, ref trianglePlane, ref triangle) != null) { Vector3 triangleNormal = MyUtils.GetNormalVectorFromTriangle(ref triangle); if ((referenceNormalVector.HasValue == false) || (maxAngle.HasValue == false) || ((MyUtils.GetAngleBetweenVectors(referenceNormalVector.Value, triangleNormal) <= maxAngle))) { MyTriangle_Vertex_Normals retTriangle; retTriangle.Vertices = triangle; retTriangle.Normals = triangleNormals; retTriangles.Add(retTriangle); } } } } } } }
public bool GetIntersectionWithSphere(IMyEntity entity, ref BoundingSphereD sphere) { // Transform sphere from world space to object space MatrixD worldInv = entity.PositionComp.WorldMatrixNormalizedInv; Vector3 positionInObjectSpace = (Vector3)Vector3D.Transform(sphere.Center, ref worldInv); BoundingSphereD sphereInObjectSpace = new BoundingSphereD(positionInObjectSpace, (float)sphere.Radius); var aabb = BoundingBox.CreateInvalid(); BoundingSphere sphereF = (BoundingSphere)sphereInObjectSpace; aabb.Include(ref sphereF); AABB gi_aabb = new AABB(aabb.Min.ToBullet(), aabb.Max.ToBullet()); m_overlappedTriangles.Clear(); if (m_bvh.BoxQuery(ref gi_aabb, m_overlappedTriangles)) { // temporary variable for storing tirngle boundingbox info BoundingBox triangleBoundingBox = new BoundingBox(); // Triangles that are directly in this node for (int i = 0; i < m_overlappedTriangles.Count; i++) { var triangleIndex = m_overlappedTriangles[i]; m_model.GetTriangleBoundingBox(triangleIndex, ref triangleBoundingBox); // First test intersection of triangleVertexes's bounding box with bounding sphere. And only if they overlap or intersect, do further intersection tests. if (triangleBoundingBox.Intersects(ref sphereInObjectSpace)) { // See that we swaped vertex indices!! MyTriangle_Vertices triangle; MyTriangleVertexIndices triangleIndices = m_model.Triangles[triangleIndex]; triangle.Vertex0 = m_model.GetVertex(triangleIndices.I0); triangle.Vertex1 = m_model.GetVertex(triangleIndices.I2); triangle.Vertex2 = m_model.GetVertex(triangleIndices.I1); PlaneD trianglePlane = new PlaneD(triangle.Vertex0, triangle.Vertex1, triangle.Vertex2); if (MyUtils.GetSphereTriangleIntersection(ref sphereInObjectSpace, ref trianglePlane, ref triangle) != null) { // If we found intersection we can stop and dont need to look further return true; } } } } return false; }
public AABB(ref AABB other, float margin) { m_max = other.m_max; m_min = other.m_min; m_min.X -= margin; m_min.Y -= margin; m_min.Z -= margin; m_max.X += margin; m_max.Y += margin; m_max.Z += margin; }
public void GetTrianglesIntersectingAABB(ref BoundingBoxD aabb, List<MyTriangle_Vertex_Normal> retTriangles, int maxNeighbourTriangles) { BoundingBox boxF = (BoundingBox)aabb; IndexedVector3 min = boxF.Min.ToBullet(); IndexedVector3 max = boxF.Max.ToBullet(); AABB gi_aabb = new AABB(ref min, ref max); m_overlappedTriangles.Clear(); VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("m_bvh.BoxQuery"); bool res = m_bvh.BoxQuery(ref gi_aabb, m_overlappedTriangles); VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); if (res) { VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("m_overlappedTriangles"); //foreach (var triangleIndex in m_overlappedTriangles) for (int i = 0; i < m_overlappedTriangles.Count; i++) { var triangleIndex = m_overlappedTriangles[i]; // If we reached end of the buffer of neighbour triangles, we stop adding new ones. This is better behavior than throwing exception because of array overflow. if (retTriangles.Count == maxNeighbourTriangles) { VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); return; } MyTriangleVertexIndices triangle = m_model.Triangles[triangleIndex]; MyTriangle_Vertices triangleVertices = new MyTriangle_Vertices(); m_model.GetVertex(triangle.I0, triangle.I1, triangle.I2, out triangleVertices.Vertex0, out triangleVertices.Vertex1, out triangleVertices.Vertex2); IndexedVector3 iv0 = triangleVertices.Vertex0.ToBullet(); IndexedVector3 iv1 = triangleVertices.Vertex1.ToBullet(); IndexedVector3 iv2 = triangleVertices.Vertex2.ToBullet(); MyTriangle_Vertex_Normal retTriangle; retTriangle.Vertexes = triangleVertices; retTriangle.Normal = Vector3.Forward; retTriangles.Add(retTriangle); } VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); } }
public void CopyWithMargin(ref AABB other, float margin) { m_min.X = other.m_min.X - margin; m_min.Y = other.m_min.Y - margin; m_min.Z = other.m_min.Z - margin; m_max.X = other.m_max.X + margin; m_max.Y = other.m_max.Y + margin; m_max.Z = other.m_max.Z + margin; }
//! Finds the intersecting box between this box and the other. public void FindIntersection(ref AABB other, ref AABB intersection) { intersection.m_min.X = BoxCollision.BT_MAX(other.m_min.X, m_min.X); intersection.m_min.Y = BoxCollision.BT_MAX(other.m_min.Y, m_min.Y); intersection.m_min.Z = BoxCollision.BT_MAX(other.m_min.Z, m_min.Z); intersection.m_max.X = BoxCollision.BT_MIN(other.m_max.X, m_max.X); intersection.m_max.Y = BoxCollision.BT_MIN(other.m_max.Y, m_max.Y); intersection.m_max.Z = BoxCollision.BT_MIN(other.m_max.Z, m_max.Z); }
public bool HasCollision(ref AABB other) { if (m_min.X > other.m_max.X || m_max.X < other.m_min.X || m_min.Y > other.m_max.Y || m_max.Y < other.m_min.Y || m_min.Z > other.m_max.Z || m_max.Z < other.m_min.Z) { return false; } return true; }
protected void GImpactVsShapeFindPairs( ref IndexedMatrix trans0, ref IndexedMatrix trans1, GImpactShapeInterface shape0, CollisionShape shape1, ObjectArray<int> collided_primitives) { AABB boxshape = new AABB(); if (shape0.HasBoxSet()) { IndexedMatrix trans1to0 = trans0.Inverse(); //trans1to0 *= trans1; trans1to0 = trans1to0 * trans1; //trans1to0 = MathUtil.BulletMatrixMultiply(trans1,trans1to0); shape1.GetAabb(ref trans1to0, out boxshape.m_min, out boxshape.m_max); if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactAlgo) { MathUtil.PrintMatrix(BulletGlobals.g_streamWriter, "GImpactAglo::GImpactVsShapeFindPairs trans1to0", trans1to0); MathUtil.PrintVector3(BulletGlobals.g_streamWriter, "box min", boxshape.m_min); MathUtil.PrintVector3(BulletGlobals.g_streamWriter, "box max", boxshape.m_max); } shape0.GetBoxSet().BoxQuery(ref boxshape, collided_primitives); } else { shape1.GetAabb(ref trans1, out boxshape.m_min, out boxshape.m_max); AABB boxshape0 = new AABB(); int i = shape0.GetNumChildShapes(); while (i-- != 0) { shape0.GetChildAabb(i, ref trans0, out boxshape0.m_min, out boxshape0.m_max); if (boxshape.HasCollision(ref boxshape0)) { collided_primitives.Add(i); } } } }
public bool OverlappingTransConservative(ref AABB box, ref IndexedMatrix trans1_to_0) { AABB tbox = box; tbox.ApplyTransform(ref trans1_to_0); return HasCollision(ref tbox); }
void IPrimitiveManagerBase.GetPrimitiveBox(int prim_index, out AABB primbox) { BoundingBox bbox = BoundingBox.CreateInvalid(); Vector3 v1 = GetVertex(Triangles[prim_index].I0); Vector3 v2 = GetVertex(Triangles[prim_index].I1); Vector3 v3 = GetVertex(Triangles[prim_index].I2); bbox.Include( ref v1, ref v2, ref v3); primbox = new AABB() { m_min = bbox.Min.ToBullet(), m_max = bbox.Max.ToBullet() }; }
public bool GetIntersectionWithSphere(MyEntity physObject, ref BoundingSphere sphere) { // Transform sphere from world space to object space Matrix worldInv = physObject.GetWorldMatrixInverted(); Vector3 positionInObjectSpace = MyUtils.GetTransform(sphere.Center, ref worldInv); BoundingSphere sphereInObjectSpace = new BoundingSphere(positionInObjectSpace, sphere.Radius); var aabb = BoundingBoxHelper.InitialBox; BoundingBoxHelper.AddSphere(ref sphereInObjectSpace, ref aabb); AABB gi_aabb = new AABB(ref aabb.Min, ref aabb.Max); m_overlappedTriangles.Clear(); if (m_bvh.BoxQuery(ref gi_aabb, m_overlappedTriangles)) { // temporary variable for storing tirngle boundingbox info BoundingBox triangleBoundingBox = new BoundingBox(); // Triangles that are directly in this node for (int i = 0; i < m_overlappedTriangles.Count; i++) { var triangleIndex = m_overlappedTriangles[i]; m_model.GetTriangleBoundingBox(triangleIndex, ref triangleBoundingBox); // First test intersection of triangleVertexes's bounding box with bounding sphere. And only if they overlap or intersect, do further intersection tests. if (MyUtils.IsBoxIntersectingSphere(triangleBoundingBox, ref sphereInObjectSpace) == true) { // See that we swaped vertex indices!! MyTriangle_Vertexes triangle; MyTriangleVertexIndices triangleIndices = m_model.Triangles[triangleIndex]; triangle.Vertex0 = m_model.GetVertex(triangleIndices.I0); triangle.Vertex1 = m_model.GetVertex(triangleIndices.I2); triangle.Vertex2 = m_model.GetVertex(triangleIndices.I1); MyPlane trianglePlane = new MyPlane(ref triangle); if (MyUtils.GetSphereTriangleIntersection(ref sphereInObjectSpace, ref trianglePlane, ref triangle) != null) { // If we found intersection we can stop and dont need to look further return true; } } } } return false; }