public static BoundingSphere Convert(Microsoft.Xna.Framework.BoundingSphere boundingSphere) { BoundingSphere toReturn; Convert(ref boundingSphere.Center, out toReturn.Center); toReturn.Radius = boundingSphere.Radius; return(toReturn); }
public IEnumerable <Intersection <TObject> > AllIntersections(Microsoft.Xna.Framework.BoundingSphere sphere) { if (!this.treeReady) { this.UpdateTree(); } return(this.GetIntersection(sphere)); }
static public void AddSphere(Microsoft.Xna.Framework.BoundingSphere sphere, ref BoundingBox bb) { Vector3 radius = new Vector3(sphere.Radius); Vector3 minSphere = sphere.Center; Vector3 maxSphere = sphere.Center; Vector3.Subtract(ref minSphere, ref radius, out minSphere); Vector3.Add(ref maxSphere, ref radius, out maxSphere); Vector3.Min(ref bb.Min, ref minSphere, out bb.Min); Vector3.Max(ref bb.Max, ref maxSphere, out bb.Max); }
public void GetEntries(Microsoft.Xna.Framework.BoundingSphere boundingShape, IList <BroadPhaseEntry> overlaps) { //Create a bounding box based on the bounding sphere. //Compute the min and max of the bounding box. //Loop through the cells and select bounding boxes which overlap the x axis. #if !WINDOWS Vector3 offset = new Vector3(); #else Vector3 offset; #endif offset.X = boundingShape.Radius; offset.Y = offset.X; offset.Z = offset.Y; BoundingBox box; Vector3.Add(ref boundingShape.Center, ref offset, out box.Max); Vector3.Subtract(ref boundingShape.Center, ref offset, out box.Min); Int2 min, max; Grid2DSortAndSweep.ComputeCell(ref box.Min, out min); Grid2DSortAndSweep.ComputeCell(ref box.Max, out max); for (int i = min.Y; i <= max.Y; i++) { for (int j = min.Z; j <= max.Z; j++) { //Grab the cell that we are currently in. Int2 cellIndex; cellIndex.Y = i; cellIndex.Z = j; GridCell2D cell; if (owner.cellSet.TryGetCell(ref cellIndex, out cell)) { //To fully accelerate this, the entries list would need to contain both min and max interval markers. //Since it only contains the sorted min intervals, we can't just start at a point in the middle of the list. //Consider some giant bounding box that spans the entire list. for (int k = 0; k < cell.entries.count && cell.entries.Elements[k].item.boundingBox.Min.X <= box.Max.X; k++) //TODO: Try additional x axis pruning? A bit of optimization potential due to overlap with AABB test. { bool intersects; var item = cell.entries.Elements[k].item; boundingShape.Intersects(ref item.boundingBox, out intersects); if (intersects && !overlaps.Contains(item)) { overlaps.Add(item); } } } } } }
public Intersection <CubeBounds> Intersects(Microsoft.Xna.Framework.BoundingSphere intersectionSphere) { if (BoundingBox.Max != BoundingBox.Min) { if (BoundingBox.Contains(intersectionSphere) != ContainmentType.Disjoint) { return(new Intersection <CubeBounds>(this)); } } else if (BoundingSphere.Radius != 0f) { if (BoundingSphere.Contains(intersectionSphere) != ContainmentType.Disjoint) { return(new Intersection <CubeBounds>(this)); } } return(null); }
private IEnumerable <Intersection <TObject> > GetIntersection(Microsoft.Xna.Framework.BoundingSphere sphere) { if (this.objects.Count == 0 && this.HasChildren == false) { return(NoIntersections); } List <Intersection <TObject> > ret = new List <Intersection <TObject> >(); foreach (TObject obj in this.objects) { Intersection <TObject> ir = obj.Intersects(sphere); if (ir != null) { ret.Add(ir); } } for (int a = 0; a < 8; a++) { if (this.octants[a] == null) { continue; } BoundingBox octantRegion = this.octants[a].region; ContainmentType sphereContains = sphere.Contains(octantRegion); if ((sphereContains == ContainmentType.Intersects || sphereContains == ContainmentType.Contains)) { IEnumerable <Intersection <TObject> > hitList = this.octants[a].GetIntersection(sphere); ret.AddRange(hitList); } } return(ret); }
public BillboardResource(GraphicsDevice device) { this._VertexDeclaration = new Microsoft.Xna.Framework.Graphics.VertexDeclaration(device, BillboardResource.BillboardVertex.VertexElements); this._VertexBuffer = new Microsoft.Xna.Framework.Graphics.VertexBuffer(device, typeof(BillboardResource.BillboardVertex), 4, BufferUsage.WriteOnly); this._IndexBuffer = new Microsoft.Xna.Framework.Graphics.IndexBuffer(device, typeof(short), 6, BufferUsage.WriteOnly); short[] indices = new short[] { 0, 1, 2, 2, 1, 3 }; Vector3[] positions = new Vector3[] { new Vector3(0.5f, 1f, 0f), new Vector3(-0.5f, 1f, 0f), new Vector3(0.5f, 0f, 0f), new Vector3(-0.5f, 0f, 0f) }; Vector2[] uvs = new Vector2[] { new Vector2(0f, 0f), new Vector2(1f, 0f), new Vector2(0f, 1f), new Vector2(1f, 1f) }; Vector3[] tangents = new Vector3[4]; Vector3[] binormals = new Vector3[4]; this.BuildTangentSpaceDataForTriangleList(indices, positions, uvs, tangents, binormals); BillboardResource.BillboardVertex[] verts = new BillboardResource.BillboardVertex[4]; verts[0].Position = positions[0]; verts[0].TextureCoordinate = uvs[0]; verts[0].Normal = Vector3.Forward; verts[0].Tangent = tangents[0]; verts[0].Binormal = binormals[0]; verts[1].Position = positions[1]; verts[1].TextureCoordinate = uvs[1]; verts[1].Normal = Vector3.Forward; verts[1].Tangent = tangents[1]; verts[1].Binormal = binormals[1]; verts[2].Position = positions[2]; verts[2].TextureCoordinate = uvs[2]; verts[2].Normal = Vector3.Forward; verts[2].Tangent = tangents[2]; verts[2].Binormal = binormals[2]; verts[3].Position = positions[3]; verts[3].TextureCoordinate = uvs[3]; verts[3].Normal = Vector3.Forward; verts[3].Tangent = tangents[3]; verts[3].Binormal = binormals[3]; this._VertexBuffer.SetData<BillboardResource.BillboardVertex>(verts); this._IndexBuffer.SetData<short>(indices); this._BoundingSphere = Microsoft.Xna.Framework.BoundingSphere.CreateFromPoints(positions); }
public static void CreateFromSphere(ref BoundingSphere sphere, out BoundingBox result) { result = BoundingBox.CreateFromSphere(sphere); }
public static void Convert(ref BoundingSphere boundingSphere, out Microsoft.Xna.Framework.BoundingSphere xnaBoundingSphere) { Convert(ref boundingSphere.Center, out xnaBoundingSphere.Center); xnaBoundingSphere.Radius = boundingSphere.Radius; }
public static void Convert(ref Microsoft.Xna.Framework.BoundingSphere boundingSphere, out BoundingSphere bepuBoundingSphere) { Convert(ref boundingSphere.Center, out bepuBoundingSphere.Center); bepuBoundingSphere.Radius = boundingSphere.Radius; }
public void Intersects(ref BoundingSphere sphere, out PlaneIntersectionType result) { result = Intersects(sphere); }
/// <summary> /// Update The System /// </summary> public void Update() { this._boundingsphere = new Microsoft.Xna.Framework.BoundingSphere(new Vector3(this.img.Position.X + (this.img.Size.X / 2), this.img.Position.Y + (this.img.Size.Y / 2), 0), this.img.Size.X / 2); }
public void Intersects(ref BoundingSphere sphere, out PlaneIntersectionType result) { sphere.Intersects(ref this, out result); }
public ContainmentType Contains(BoundingSphere sphere) { if (sphere.Center.X - Min.X >= sphere.Radius && sphere.Center.Y - Min.Y >= sphere.Radius && sphere.Center.Z - Min.Z >= sphere.Radius && Max.X - sphere.Center.X >= sphere.Radius && Max.Y - sphere.Center.Y >= sphere.Radius && Max.Z - sphere.Center.Z >= sphere.Radius) { return(ContainmentType.Contains); } double dmin = 0; double e = sphere.Center.X - Min.X; if (e < 0) { if (e < -sphere.Radius) { return(ContainmentType.Disjoint); } dmin += e * e; } else { e = sphere.Center.X - Max.X; if (e > 0) { if (e > sphere.Radius) { return(ContainmentType.Disjoint); } dmin += e * e; } } e = sphere.Center.Y - Min.Y; if (e < 0) { if (e < -sphere.Radius) { return(ContainmentType.Disjoint); } dmin += e * e; } else { e = sphere.Center.Y - Max.Y; if (e > 0) { if (e > sphere.Radius) { return(ContainmentType.Disjoint); } dmin += e * e; } } e = sphere.Center.Z - Min.Z; if (e < 0) { if (e < -sphere.Radius) { return(ContainmentType.Disjoint); } dmin += e * e; } else { e = sphere.Center.Z - Max.Z; if (e > 0) { if (e > sphere.Radius) { return(ContainmentType.Disjoint); } dmin += e * e; } } if (dmin <= sphere.Radius * sphere.Radius) { return(ContainmentType.Intersects); } return(ContainmentType.Disjoint); }
public void Contains(ref BoundingSphere sphere, out ContainmentType result) { float val; ContainmentType contained; // We first check if the sphere is inside the frustum this.Contains(ref sphere.Center, out contained); // The sphere is inside. Now we need to check if it's fully contained or not // So we see if the perpendicular distance to each plane is less than or equal to the sphere's radius. // If the perpendicular distance is less, just return Intersects. if (contained == ContainmentType.Contains) { val = PlaneHelper.PerpendicularDistance(ref sphere.Center, ref this.bottom); if (val < sphere.Radius) { result = ContainmentType.Intersects; return; } val = PlaneHelper.PerpendicularDistance(ref sphere.Center, ref this.far); if (val < sphere.Radius) { result = ContainmentType.Intersects; return; } val = PlaneHelper.PerpendicularDistance(ref sphere.Center, ref this.left); if (val < sphere.Radius) { result = ContainmentType.Intersects; return; } val = PlaneHelper.PerpendicularDistance(ref sphere.Center, ref this.near); if (val < sphere.Radius) { result = ContainmentType.Intersects; return; } val = PlaneHelper.PerpendicularDistance(ref sphere.Center, ref this.right); if (val < sphere.Radius) { result = ContainmentType.Intersects; return; } val = PlaneHelper.PerpendicularDistance(ref sphere.Center, ref this.top); if (val < sphere.Radius) { result = ContainmentType.Intersects; return; } // If we get here, the sphere is fully contained result = ContainmentType.Contains; return; } //duff idea : test if all corner is in same side of a plane if yes and outside it is disjoint else intersect // issue is that we can have some times when really close aabb // If we're here, the the sphere's centre was outside of the frustum. This makes things hard :( // We can't use perpendicular distance anymore. I'm not sure how to code this. throw new NotImplementedException(); }
public PlaneIntersectionType Intersects(BoundingSphere sphere) { return(sphere.Intersects(this)); }
/// <summary> /// Initialize The System /// </summary> /// <param name="img">Image</param> public void Initialize(Graphics.Image img) { this.img = img; this._boundingsphere = new Microsoft.Xna.Framework.BoundingSphere(new Vector3(this.img.Position.X + (this.img.Size.X / 2), this.img.Position.Y + (this.img.Size.Y / 2), 0), this.img.Size.X / 2); }
public bool Intersects(BoundingSphere sphere) { throw new NotImplementedException(); }
public static BoundingBox CreateFromSphere(BoundingSphere sphere) { Vector3 vector1 = new Vector3(sphere.Radius); return(new BoundingBox(sphere.Center - vector1, sphere.Center + vector1)); }
public void Contains(ref BoundingSphere sphere, out ContainmentType result) { result = this.Contains(sphere); }
public void Intersects(ref BoundingSphere sphere, out bool result) { throw new NotImplementedException(); }
public void Intersects(ref BoundingSphere sphere, out bool result) { result = Intersects(sphere); }
public void Contains(ref BoundingSphere sphere, out ContainmentType result) { result = ContainmentType.Contains; float result1; Vector3.Dot(ref this.bottom.Normal, ref sphere.Center, out result1); float result2 = result1 + this.bottom.D; if ((double)result2 > (double)sphere.Radius) { result = ContainmentType.Disjoint; } else { if ((double)Math.Abs(result2) < (double)sphere.Radius) { result = ContainmentType.Intersects; } Vector3.Dot(ref this.top.Normal, ref sphere.Center, out result2); float result3 = result2 + this.top.D; if ((double)result3 > (double)sphere.Radius) { result = ContainmentType.Disjoint; } else { if ((double)Math.Abs(result3) < (double)sphere.Radius) { result = ContainmentType.Intersects; } Vector3.Dot(ref this.near.Normal, ref sphere.Center, out result3); float result4 = result3 + this.near.D; if ((double)result4 > (double)sphere.Radius) { result = ContainmentType.Disjoint; } else { if ((double)Math.Abs(result4) < (double)sphere.Radius) { result = ContainmentType.Intersects; } Vector3.Dot(ref this.far.Normal, ref sphere.Center, out result4); float result5 = result4 + this.far.D; if ((double)result5 > (double)sphere.Radius) { result = ContainmentType.Disjoint; } else { if ((double)Math.Abs(result5) < (double)sphere.Radius) { result = ContainmentType.Intersects; } Vector3.Dot(ref this.left.Normal, ref sphere.Center, out result5); float result6 = result5 + this.left.D; if ((double)result6 > (double)sphere.Radius) { result = ContainmentType.Disjoint; } else { if ((double)Math.Abs(result6) < (double)sphere.Radius) { result = ContainmentType.Intersects; } Vector3.Dot(ref this.right.Normal, ref sphere.Center, out result6); float num = result6 + this.right.D; if ((double)num > (double)sphere.Radius) { result = ContainmentType.Disjoint; } else { if ((double)Math.Abs(num) >= (double)sphere.Radius) { return; } result = ContainmentType.Intersects; } } } } } } }