public static BEPUutilities.BoundingBox Convert(BoundingBox boundingBox) { BEPUutilities.BoundingBox toReturn; Convert(ref boundingBox.Min, out toReturn.Min); Convert(ref boundingBox.Max, out toReturn.Max); return(toReturn); }
public static VoxelHandle GetValidVoxelNear(ChunkManager chunks, Microsoft.Xna.Framework.Vector3 pos) { Microsoft.Xna.Framework.BoundingBox bounds = chunks.Bounds; bounds.Max = new Microsoft.Xna.Framework.Vector3(bounds.Max.X, VoxelConstants.ChunkSizeY, bounds.Max.Z); var clampedPos = MathFunctions.Clamp(pos, chunks.Bounds) + Microsoft.Xna.Framework.Vector3.Down * 0.05f; return(new VoxelHandle(chunks.ChunkData, GlobalVoxelCoordinate.FromVector3(clampedPos))); }
/// <summary> /// <see cref="Contains(Rectangle)"/> checks whether or not a <see cref="Microsoft.Xna.Framework.Rectangle"/> is contained within the <see cref="BoundingBox"/> of the CameraComponent. /// </summary> public ContainmentType Contains(Rectangle rectangle) { var max = new Vector3(rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height, 0.5f); var min = new Vector3(rectangle.X, rectangle.Y, 0.5f); var boundingBox = new BoundingBox(min.MonoGameVector, max.MonoGameVector); return(BoundingFrustum.Contains(boundingBox)); }
/// <summary> /// Performs an AABB AABB collision check. /// </summary> /// <param name="a">First AABB.</param> /// <param name="b">Second AABB.</param> /// <returns></returns> private static Collision AABBAABB(BoundingBox a, BoundingBox b) { // Minimum Translation Vector // ========================== float minimumTranslationVectorDistance = float.MaxValue; // Set current minimum distance (max float value so next value is always less) Vector3 minimumTranslationVectorAxis = new Vector3(); // Axis along which to travel with the minimum distance var containment = a.Contains(b); var normal = Vector3.Zero; float penetrationDepth = 0f; if (containment == ContainmentType.Disjoint) { return(new Collision(false, normal, penetrationDepth)); } // Axes of potential separation // ============================ // - Each shape must be projected on these axes to test for intersection: // // (1, 0, 0) A0 (= B0) [X Axis] // (0, 1, 0) A1 (= B1) [Y Axis] // (0, 0, 1) A1 (= B2) [Z Axis] // [X Axis] if (!SAT(Vector3.Right, a.Min.X, a.Max.X, b.Min.X, b.Max.X, ref minimumTranslationVectorAxis, ref minimumTranslationVectorDistance)) { return(new Collision(false, normal, penetrationDepth)); } // [Y Axis] if (!SAT(Vector3.Up, a.Min.Y, a.Max.Y, b.Min.Y, b.Max.Y, ref minimumTranslationVectorAxis, ref minimumTranslationVectorDistance)) { return(new Collision(false, normal, penetrationDepth)); } // [Z Axis] if (!SAT(Vector3.Back, a.Min.Z, a.Max.Z, b.Min.Z, b.Max.Z, ref minimumTranslationVectorAxis, ref minimumTranslationVectorDistance)) { return(new Collision(false, normal, penetrationDepth)); } // Calculate Minimum Translation Vector (MTV) [normal * penetration] normal = Vector3.Normalize(minimumTranslationVectorAxis); // Multiply the penetration depth by itself plus a small increment // When the penetration is resolved using MTV, it will no longer intersect penetrationDepth = MathF.Sqrt(minimumTranslationVectorDistance) * 1.001f; return(new Collision(true, normal, penetrationDepth)); }
/// <summary> /// TODO: write tests for boundingbox calculation /// </summary> /// <param name="mesh"></param> /// <returns></returns> public static BoundingBox CalculateBoundingBox(IMesh mesh) { var ret = new XnaBoundingBox(); foreach (var part in mesh.GetCoreData().Parts) { var positions = part.MeshPart.GetGeometryData().GetSourceVector3(MeshPartGeometryData.Semantic.Position); if (positions.Length == 0) { continue; } //TODO: check this! XnaVector3.Transform(positions, ref part.ObjectMatrix, positions); ret = ret.MergeWith(XnaBoundingBox.CreateFromPoints(positions)); } return(ret.dx()); }
/// <summary> /// Gets collision data between a <see cref="Microsoft.Xna.Framework.BoundingSphere"/> and a <see cref="Microsoft.Xna.Framework.BoundingBox"/>. /// </summary> /// <param name="sphere">Sphere to check.</param> /// <param name="box">Box to check.</param> /// <returns><see cref="Komodo.Core.Physics.Collision"/> information between the sphere and box.</returns> private static Collision GetCollision(BoundingSphere sphere, BoundingBox box) { var containment = sphere.Contains(box); var normal = Vector3.Zero; float penetrationDepth = 0f; if (containment != ContainmentType.Disjoint) { var closestPoint = Microsoft.Xna.Framework.Vector3.Clamp(sphere.Center, box.Min, box.Max); var toClosest = new Vector3(sphere.Center - closestPoint); var closestPointDistance = toClosest.Length(); if (closestPointDistance < sphere.Radius) { penetrationDepth = sphere.Radius - closestPointDistance; normal = Vector3.Normalize(toClosest); } } return(new Collision(containment != ContainmentType.Disjoint, normal, penetrationDepth)); }
public TestCullObject(Vector3 pos, float radius) { boundingBox = new BoundingBox(pos - MathHelper.One * radius, pos + MathHelper.One * radius).xna(); }
public Group(byte[] bytes) { Stream s = new MemoryStream(bytes); BinaryReader br = new BinaryReader(s); s.Seek(4, SeekOrigin.Begin); ShaderIndex = br.ReadInt16(); IndiceStart = br.ReadInt16(); IndiceCount = br.ReadInt16(); s.Seek(4 + 2 + 16, SeekOrigin.Current); Quaternion = new Microsoft.Xna.Framework.Quaternion(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); float[] f = new float[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle() }; BoundingBox = new Microsoft.Xna.Framework.BoundingBox(new Microsoft.Xna.Framework.Vector3(f[0], f[2], f[4]), new Microsoft.Xna.Framework.Vector3(f[1], f[3], f[5])); }
private BoundingBox(BoundBox b) { _boundingBox = b; }
/// <summary> /// Gets collision data between a <see cref="Microsoft.Xna.Framework.BoundingBox"/> and a <see cref="Microsoft.Xna.Framework.BoundingSphere"/>. /// </summary> /// <param name="box">Box to check.</param> /// <param name="sphere">Sphere to check.</param> /// <returns><see cref="Komodo.Core.Physics.Collision"/> information between the box and sphere.</returns> private static Collision GetCollision(BoundingBox box, BoundingSphere sphere) { var collision = GetCollision(sphere, box); return(new Collision(collision.IsColliding, -collision.Normal, collision.PenetrationDepth)); }
public static void Convert(ref BoundingBox boundingBox, out BEPUutilities.BoundingBox bepuBoundingBox) { Convert(ref boundingBox.Min, out bepuBoundingBox.Min); Convert(ref boundingBox.Max, out bepuBoundingBox.Max); }
public static SlimDX.BoundingBox dx(this Microsoft.Xna.Framework.BoundingBox v) { return(new SlimDX.BoundingBox(v.Min.dx(), v.Max.dx())); }
public override bool Collide(Microsoft.Xna.Framework.BoundingBox b) { return(false); }
public void FindAll(ref Microsoft.Xna.Framework.BoundingBox boundingBox, ICollection <ISpatialQueryable> result) { throw new NotImplementedException(); }
public Section(Tag tag, CompressionInfo boundingBox) { BinaryReader br = new BinaryReader(tag.TagStream); int StartOffset = (int)tag.TagStream.Position; buffer = br.ReadBytes(Size); tag.TagStream.Position = StartOffset; VertexType = (VertexType)br.ReadInt32(); VertexCount = br.ReadInt16(); TriangleCount = br.ReadInt16(); tag.TagStream.Position = StartOffset + 26; CompressionFlags = (Compression)br.ReadInt32(); tag.TagStream.Position = StartOffset + 56; RawOffset = br.ReadInt32(); RawSize = br.ReadInt32(); br.ReadInt32(); RawDataSize = br.ReadInt32(); tag.TagStream.Position = StartOffset + 72; int Count = br.ReadInt32(); if (Count > 0) { int Offset = br.ReadInt32(); Resources = new Resource[Count]; for (int i = 0; i < Count; i++) { tag.TagStream.Position = Offset + (i * Resource.Size); Resources[i] = new Resource(tag.TagStream); } } if (Globals.IsExternalResource(RawOffset)) { return; } tag.ResourceStream.Position = tag.ResourceInformation[RawOffset].Address; mesh = new Mesh(tag.ResourceStream, Resources, this, boundingBox); Microsoft.Xna.Framework.Vector3[] points = new Microsoft.Xna.Framework.Vector3[mesh.Vertices.Length]; for (int i = 0; i < points.Length; i++) points[i] = mesh.Vertices[i].Position; BoundingBox = Microsoft.Xna.Framework.BoundingBox.CreateFromPoints(points); }
public TestCullObject(BoundingBox bb) { boundingBox = bb.xna(); }
/// <summary> /// Gets collision data between two <see cref="Microsoft.Xna.Framework.BoundingBox"/>es. /// </summary> /// <param name="box">First box to check.</param> /// <param name="otherBox">Second box to check.</param> /// <returns><see cref="Komodo.Core.Physics.Collision"/> information between the two boxes.</returns> private static Collision GetCollision(BoundingBox box, BoundingBox otherBox) { return(AABBAABB(box, otherBox)); }