public static void ContainsInclusive(Vector2D[] vertexes, ref Vector2D point, out ContainmentType result) { if (vertexes == null) { throw new ArgumentNullException("vertexes"); } if (vertexes.Length < 3) { throw new ArgumentOutOfRangeException("vertexes"); } int count = 0; // the crossing count Vector2D v1 = vertexes[vertexes.Length - 1]; Vector2D v2; for (int index = 0; index < vertexes.Length; index++, v1 = v2) { v2 = vertexes[index]; if (((v1.Y <= point.Y) ^ (v2.Y <= point.Y)) || (v1.Y == point.Y) || (v2.Y == point.Y)) { Scalar xIntersection = (v1.X + ((point.Y - v1.Y) / (v2.Y - v1.Y)) * (v2.X - v1.X)); if (point.X < xIntersection) // P.X < intersect { ++count; } else if (xIntersection == point.X) { result = ContainmentType.Contains; return; } } } result = ((count & 1) != 0) ? (ContainmentType.Contains) : (ContainmentType.Disjoint); //true if odd. }
public void Contains(BoundingSphere other, out ContainmentType ct) { if (other == null) ct = ContainmentType.Disjoint; else ct = sbf.Contains(ref other.sSphere); }
/// <summary> /// Determines the containment type of another rectangle to the bounding rectangle /// </summary> /// <param name="rectangle">Rectangle that will be checked for containment</param> /// <param name="result"> /// The containment type of the other rectangle in the rectangle /// </param> public void Contains(ref BoundingRectangle rectangle, out ContainmentType result) { bool outside = (rectangle.Max.X <= this.Min.X) || (rectangle.Min.X > this.Max.X) || (rectangle.Max.Y <= this.Min.Y) || (rectangle.Min.Y > this.Max.Y); if(outside) { result = ContainmentType.Disjoint; return; } bool contained = (rectangle.Min.X >= this.Min.X) && (rectangle.Max.X < this.Max.X) && (rectangle.Min.Y >= this.Min.Y) && (rectangle.Max.Y < this.Max.Y); if(contained) { result = ContainmentType.Contains; return; } result = ContainmentType.Intersects; return; }
public static void ContainsExclusive(Vector2D[] vertexes, ref Vector2D point, out ContainmentType result) { if (vertexes == null) { throw new ArgumentNullException("vertexes"); } if (vertexes.Length < 3) { throw new ArgumentOutOfRangeException("vertexes"); } int count = 0; //intersection count bool t1; Vector2D v1, v2; Scalar temp; v1 = vertexes[vertexes.Length - 1]; for (int index = 0; index < vertexes.Length; ++index, v1 = v2) { v2 = vertexes[index]; t1 = (v1.Y <= point.Y); if (t1 ^ (v2.Y <= point.Y)) { temp = ((point.Y - v1.Y) * (v2.X - v1.X) - (point.X - v1.X) * (v2.Y - v1.Y)); if (t1) { if (temp > 0) { count++; } } else { if (temp < 0) { count--; } } } } result = (count != 0) ? (ContainmentType.Contains) : (ContainmentType.Disjoint); }
private IEnumerable <Intersection <TObject> > GetIntersection(BoundingFrustum frustum) { 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(frustum); 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 frustumContains = frustum.Contains(octantRegion); if ((frustumContains == ContainmentType.Intersects || frustumContains == ContainmentType.Contains)) { IEnumerable <Intersection <TObject> > hitList = this.octants[a].GetIntersection(frustum); ret.AddRange(hitList); } } return(ret); }
/// <summary> /// Draws a billboard in world space facing the +Z direction of the matrix given. Units in meters, /// matrix transform notwithstanding. Dont forget to compensate for perspective scaling! /// </summary public void Draw(ref CroppedBox box, MatrixD[] matrixRef) { ContainmentType containment = ContainmentType.Contains; if (box.mask != null) { box.mask.Value.Contains(ref box.bounds, out containment); } if (containment != ContainmentType.Disjoint) { if (updateMatFit && matFrame.Material != Material.Default) { Vector2 boxSize = box.bounds.Size; minBoard.materialData.texBounds = matFrame.GetMaterialAlignment(boxSize.X / boxSize.Y); updateMatFit = false; } if (containment != ContainmentType.Disjoint) { minBoard.Draw(ref box, matrixRef); } } }
public void Contains(ref BoundingPolygon polygon, out ContainmentType result) { if (polygon == null) { throw new ArgumentNullException("polygon"); } Vector2D[] vertexes = polygon.Vertexes; result = ContainmentType.Unknown; for (int index = 0; index < vertexes.Length && result != ContainmentType.Intersects; ++index) { ContainmentType con; Contains(ref vertexes[index], out con); result |= con; } if (result == ContainmentType.Disjoint) { bool test; polygon.Intersects(ref this, out test); if (test) { result = ContainmentType.Intersects; } } }
public void Draw(Texture2D texture, IEnumerable <Quad> quads, BlendState blendState, BoundingBox bbox, SamplerState sampler = null) { if (texture != null && !texture.IsDisposed) { //necessário para que os objetos "3D" sejam desenhados na ordem correta GDevice.DepthStencilState = DepthStencilState.Default; GDevice.BlendState = blendState; basicEffect.Texture = texture; if (sampler != null) { gDevice.SamplerStates[0] = sampler; } else { gDevice.SamplerStates[0] = this.sampler; } foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes) { pass.Apply(); foreach (Quad quad in quads) { ContainmentType containment = ContainmentType.Intersects; if (!DEFAULT_BOX.Equals(bbox)) { containment = cam.ViewFrustum.Contains(bbox); } bool visibleToCamera = containment != ContainmentType.Disjoint; if (visibleToCamera) { drawQuad(quad); } } } } }
public void Contains(ref Vector3 point, out ContainmentType result) { throw new NotImplementedException(); }
/// <summary> /// Tests whether the BoundingBox contains a BoundingBox. /// </summary> /// <param name="box">The BoundingBox to test for overlap.</param><param name="result">[OutAttribute] Enumeration indicating the extent of overlap.</param> public void Contains(ref BoundingBox box, out ContainmentType result) { //test if all corner is in the same side of a face by just checking min and max if (box.Max.X < Min.X || box.Min.X > Max.X || box.Max.Y < Min.Y || box.Min.Y > Max.Y || box.Max.Z < Min.Z || box.Min.Z > Max.Z) { result = ContainmentType.Disjoint; return; } if (box.Min.X >= Min.X && box.Max.X <= Max.X && box.Min.Y >= Min.Y && box.Max.Y <= Max.Y && box.Min.Z >= Min.Z && box.Max.Z <= Max.Z) { result = ContainmentType.Contains; return; } result = ContainmentType.Intersects; }
/// <summary> /// Gets a value indicating whether this <see cref="BoundingSphere"/> contains the specified point. /// </summary> /// <param name="point">A <see cref="Vector3"/> which represents the point to evaluate.</param> /// <param name="result">A <see cref="ContainmentType"/> value representing the relationship between this sphere and the evaluated point.</param> public void Contains(ref Vector3 point, out ContainmentType result) { Vector3.DistanceSquared(ref point, ref Center, out Single distanceSquared); result = distanceSquared < Radius * Radius ? ContainmentType.Contains : ContainmentType.Disjoint; }
internal void ReadContentRange(ref MyVoxelDataRequest req) { if (Closed) { return; } float lodVoxelSize = (1 << req.Lod) * MyVoxelConstants.VOXEL_SIZE_IN_METRES; Vector3I min = req.minInLod; Vector3I max = req.maxInLod; ProfilerShort.Begin("Distance field computation"); try { Vector3I v = min; Vector3 localPos = v * lodVoxelSize - m_translation; Vector3 localPosStart = localPos; BoundingBox request = new BoundingBox(localPos, localPos + (max - min) * lodVoxelSize); request.Inflate(lodVoxelSize); MyVoxelRequestFlags flags = 0; ContainmentType cont = ContainmentType.Intersects; bool intersects; if (!req.Flags.HasFlags(MyVoxelRequestFlags.DoNotCheck)) { BoundingSphere sphere = new BoundingSphere( Vector3.Zero, OuterRadius + lodVoxelSize); sphere.Intersects(ref request, out intersects); if (!intersects) { cont = ContainmentType.Disjoint; goto end; } sphere.Radius = InnerRadius - lodVoxelSize; ContainmentType ct; sphere.Contains(ref request, out ct); if (ct == ContainmentType.Contains) { cont = ct; goto end; } cont = IntersectBoundingBoxInternal(ref request, lodVoxelSize); if (cont != ContainmentType.Intersects) { goto end; } } bool hit = false; // store request history EnqueueHistory(req); // Setup cache for current map; PrepareCache(); var writeOffsetLoc = req.Offset - min; for (v.Z = min.Z; v.Z <= max.Z; ++v.Z) { for (v.Y = min.Y; v.Y <= max.Y; ++v.Y) { v.X = min.X; var write2 = v + writeOffsetLoc; var write = req.Target.ComputeLinear(ref write2); for (; v.X <= max.X; ++v.X) { float signedDist = SignedDistanceLocal(localPos, lodVoxelSize) / lodVoxelSize; var fillRatio = MathHelper.Clamp(-signedDist, -1f, 1f) * 0.5f + 0.5f; byte content = (byte)(fillRatio * MyVoxelConstants.VOXEL_CONTENT_FULL); if (content != 0) { hit = true; } req.Target.Content(write, content); write += req.Target.StepLinear; localPos.X += lodVoxelSize; } localPos.Y += lodVoxelSize; localPos.X = localPosStart.X; } localPos.Z += lodVoxelSize; localPos.Y = localPosStart.Y; } if (!hit) { PruningStats.Miss(); } else { PruningStats.Hit(); } CullStats.Miss(); return; end :; CullStats.Hit(); if (cont == ContainmentType.Disjoint) { if (req.RequestFlags.HasFlags(MyVoxelRequestFlags.ContentChecked)) { flags |= MyVoxelRequestFlags.EmptyContent | MyVoxelRequestFlags.ContentCheckedDeep | MyVoxelRequestFlags.ContentChecked; } else { req.Target.BlockFillContent(req.Offset, req.Offset + max - min, MyVoxelConstants.VOXEL_CONTENT_EMPTY); } } else if (cont == ContainmentType.Contains) { if (req.RequestFlags.HasFlags(MyVoxelRequestFlags.ContentChecked)) { flags |= MyVoxelRequestFlags.FullContent | MyVoxelRequestFlags.ContentCheckedDeep | MyVoxelRequestFlags.ContentChecked; } else { req.Target.BlockFillContent(req.Offset, req.Offset + max - min, MyVoxelConstants.VOXEL_CONTENT_FULL); } } req.Flags = flags; PruningStats.Hit(); } finally { ProfilerShort.End(); } }
void DrawGameObjects(Effect effectToUse, String technique) { ContainmentType contains = new ContainmentType(); //if (technique == "ShadowedScene_Obj") // DebugSystem.Instance.TimeRuler.BeginMark("PLAYER", Color.Blue); #region PLAYER GameObject obj = LV.Player; boundFrustum.Contains(ref obj.boundSphere, out contains); if (contains == ContainmentType.Contains || contains == ContainmentType.Intersects) DrawModel(effectToUse, obj.model, obj.textures, obj.worldMatrix, technique, false); #endregion #region AVATAR #endregion //if (technique == "ShadowedScene_Obj") // DebugSystem.Instance.TimeRuler.EndMark("PLAYER"); //if (technique == "ShadowedScene_Obj") // DebugSystem.Instance.TimeRuler.BeginMark("MISSILES", Color.Blue); #region MISSILES foreach (Missile missile in BulletList) { if (!missile.isDestroyed) { obj = missile; boundFrustum.Contains(ref obj.boundSphere, out contains); #if !XBOX if(contains == ContainmentType.Contains || contains == ContainmentType.Intersects) DrawModel(effectToUse, obj.model, obj.textures, (missile).GetWorldMatrix(), technique, false); #endif //LM.Add(GetMatrix(limbs[(int)LimbId.Torso].PhysicsBody, SCALE)); //BONES[14] = missile.RagdollTransforms[0]; //LM.Add(GetMatrix(limbs[(int)LimbId.Head].PhysicsBody, SCALE)); BONES[19] = missile.RagdollTransforms[1]; //LM.Add(GetMatrix(limbs[(int)LimbId.UpperLegLeft].PhysicsBody, SCALE)); BONES[2] = missile.RagdollTransforms[2]; //LM.Add(GetMatrix(limbs[(int)LimbId.UpperLegRight].PhysicsBody, SCALE)); BONES[3] = missile.RagdollTransforms[3]; //LM.Add(GetMatrix(limbs[(int)LimbId.LowerLegLeft].PhysicsBody, SCALE)); BONES[11] = missile.RagdollTransforms[4]; //LM.Add(GetMatrix(limbs[(int)LimbId.LowerLegRight].PhysicsBody, SCALE)); BONES[15] = missile.RagdollTransforms[5]; //LM.Add(GetMatrix(limbs[(int)LimbId.UpperArmLeft].PhysicsBody, SCALE)); BONES[20] = missile.RagdollTransforms[6]; //LM.Add(GetMatrix(limbs[(int)LimbId.UpperArmRight].PhysicsBody, SCALE)); BONES[22] = missile.RagdollTransforms[7]; //LM.Add(GetMatrix(limbs[(int)LimbId.LowerArmLeft].PhysicsBody, SCALE)); BONES[25] = missile.RagdollTransforms[8]; //LM.Add(GetMatrix(limbs[(int)LimbId.LowerArmRight].PhysicsBody, SCALE)); BONES[28] = missile.RagdollTransforms[9]; #if XBOX parentGame.avatarRenderer.Projection = projectionMatrix; parentGame.avatarRenderer.View = viewMatrix; parentGame.avatarRenderer.World = missile.rgob.GetWorld();// GetWorldMatrixScale(5f); if (contains == ContainmentType.Contains || contains == ContainmentType.Intersects) parentGame.avatarRenderer.Draw(BONES, new Microsoft.Xna.Framework.GamerServices.AvatarExpression()); #endif //VertexPositionColor[] wrFrm; //foreach (JigLibX.Objects.PhysicObject lim in missile.rgob.limbs) //{ // wrFrm = lim.PhysicsSkin.GetLocalSkinWireframe(); // lim.PhysicsBody.TransformWireframe(wrFrm); // debugDrawer.DrawShape(wrFrm); //} //VertexPositionColor[] // wrFrm = missile.Skin.GetLocalSkinWireframe(); // missile.Body.TransformWireframe(wrFrm); // debugDrawer.DrawShape(wrFrm); } } #endregion //if (technique == "ShadowedScene_Obj") // DebugSystem.Instance.TimeRuler.EndMark("MISSILES"); //if (technique == "ShadowedScene_Obj") // DebugSystem.Instance.TimeRuler.BeginMark("BUILDINGS", Color.Blue); #region BUILDINGS foreach (Building building in BuildingList) { obj = building; boundFrustum.Contains(ref obj.boundSphere, out contains); if (building.Type == "RING") { if (!building.isDestroyed) { if (contains == ContainmentType.Contains || contains == ContainmentType.Intersects) DrawModel(effectToUse, obj.model, obj.textures, (building).GetWorldMatrix(), technique, false); } //VertexPositionColor[] wrFrm = building.Skin.GetLocalSkinWireframe(); //building.Body.TransformWireframe(wrFrm); //debugDrawer.DrawShape(wrFrm); } else { if (contains == ContainmentType.Contains || contains == ContainmentType.Intersects) DrawModel(effectToUse, obj.model, obj.textures, (building).GetWorldMatrix(), technique, false); //VertexPositionColor[] wrFrm = building.Skin.GetLocalSkinWireframe(); //building.Body.TransformWireframe(wrFrm); //debugDrawer.DrawShape(wrFrm); } } #endregion //if (technique == "ShadowedScene_Obj") // DebugSystem.Instance.TimeRuler.EndMark("BUILDINGS"); //if (technique == "ShadowedScene_Obj") // DebugSystem.Instance.TimeRuler.BeginMark("PIECES", Color.Blue); #region PIECES pieceList = new List<string>(); foreach (BuildingPiece piece in PieceList) { obj = piece; boundFrustum.Contains(ref obj.boundSphere, out contains); if (contains == ContainmentType.Contains || contains == ContainmentType.Intersects) DrawModelP(effectToUse, obj.model, obj.textures, (piece).GetWorldMatrix(), technique, false); //VertexPositionColor[] wrFrm = piece.Skin.GetLocalSkinWireframe(); //piece.Body.TransformWireframe(wrFrm); //debugDrawer.DrawShape(wrFrm); } #endregion //if (technique == "ShadowedScene_Obj") // DebugSystem.Instance.TimeRuler.EndMark("PIECES"); }
public void Contains(ref Vector3 point, out ContainmentType result) { result = Contains(point); }
public static void Contains(ref BoundingBox boundingBox1, ref BoundingBox boundingBox2, out ContainmentType result) { if (boundingBox2.Max.X < boundingBox1.Min.X || boundingBox2.Min.X > boundingBox1.Max.X || boundingBox2.Max.Y < boundingBox1.Min.Y || boundingBox2.Min.Y > boundingBox1.Max.Y || boundingBox2.Max.Z < boundingBox1.Min.Z || boundingBox2.Min.Z > boundingBox1.Max.Z) { result = ContainmentType.Disjoint; } else if ( boundingBox2.Min.X >= boundingBox1.Min.X && boundingBox2.Max.X <= boundingBox1.Max.X && boundingBox2.Min.Y >= boundingBox1.Min.Y && boundingBox2.Max.Y <= boundingBox1.Max.Y && boundingBox2.Min.Z >= boundingBox1.Min.Z && boundingBox2.Max.Z <= boundingBox1.Max.Z) { result = ContainmentType.Contains; } else { result = ContainmentType.Intersects; } }
public void Contains(ref BoundingCircle circle, out ContainmentType result) { Scalar distance; GetDistance(ref circle.Position, out distance); distance += circle.Radius; if (distance <= 0) { result = ContainmentType.Contains; } else if (distance <= circle.Radius) { result = ContainmentType.Intersects; } else { result = ContainmentType.Disjoint; } }
public static void Contains(ref BoundingSphere boundingSphere, ref BoundingFrustum boundingFrustum, out ContainmentType result) => Contains(ref boundingFrustum, ref boundingSphere, out result);
public static void Contains(ref BoundingFrustum boundingFrustum, ref BoundingSphere boundingSphere, out ContainmentType result) { result = ContainmentType.Contains; var planes = boundingFrustum.GetPlanes(); for (var i = 0; i < BoundingFrustum.PlaneCount; ++i) { var planeIntersectionType = default(PlaneIntersectionType); Intersects(ref boundingSphere, ref planes[i], out planeIntersectionType); if (planeIntersectionType == PlaneIntersectionType.Front) { result = ContainmentType.Disjoint; break; } else if (planeIntersectionType == PlaneIntersectionType.Intersecting) { result = ContainmentType.Intersects; break; } } }
public static void Contains(ref BoundingFrustum boundingFrustum, ref BoundingBox boundingBox, out ContainmentType result) { var planes = boundingFrustum.GetPlanes(); var intersects = false; for (var i = 0; i < BoundingFrustum.PlaneCount; ++i) { var planeIntersectionType = boundingBox.Contains(planes[i]); switch (planeIntersectionType) { case PlaneIntersectionType.Front: result = ContainmentType.Disjoint; return; case PlaneIntersectionType.Intersecting: intersects = true; break; } } result = intersects ? ContainmentType.Intersects : ContainmentType.Contains; }
public static void Contains(ref BoundingBox boundingBox, ref BoundingSphere boundingSphere, out ContainmentType result) { var min = boundingBox.Min; var max = boundingBox.Max; if ((boundingSphere.Center.X - min.X) >= boundingSphere.Radius && (boundingSphere.Center.Y - min.Y) >= boundingSphere.Radius && (boundingSphere.Center.Z - min.Z) >= boundingSphere.Radius && (max.X - boundingSphere.Center.X) >= boundingSphere.Radius && (max.Y - boundingSphere.Center.Y) >= boundingSphere.Radius && (max.Z - boundingSphere.Center.Z) >= boundingSphere.Radius) { result = ContainmentType.Contains; } else { double dmin = 0.0; double e = boundingSphere.Center.X - min.X; if (e < 0) { if (e < -boundingSphere.Radius) { result = ContainmentType.Disjoint; return; } dmin += e * e; } else { e = boundingSphere.Center.X - max.X; if (e > 0) { if (e > boundingSphere.Radius) { result = ContainmentType.Disjoint; return; } dmin += e * e; } } e = boundingSphere.Center.Y - min.Y; if (e < 0) { if (e < -boundingSphere.Radius) { result = ContainmentType.Disjoint; return; } dmin += e * e; } else { e = boundingSphere.Center.Y - max.Y; if (e > 0) { if (e > boundingSphere.Radius) { result = ContainmentType.Disjoint; return; } dmin += e * e; } } e = boundingSphere.Center.Z - min.Z; if (e < 0) { if (e < -boundingSphere.Radius) { result = ContainmentType.Disjoint; return; } dmin += e * e; } else { e = boundingSphere.Center.Z - max.Z; if (e > 0) { if (e > boundingSphere.Radius) { result = ContainmentType.Disjoint; return; } dmin += e * e; } } result = (dmin <= boundingSphere.Radius * boundingSphere.Radius) ? ContainmentType.Intersects : ContainmentType.Disjoint; } }
public static void Contains(ref BoundingSphere boundingSphere, ref BoundingBox boundingBox, out ContainmentType result) => Contains(ref boundingBox, ref boundingSphere, out result);
/// <summary> /// Tests whether the BoundingBox contains a BoundingSphere. /// </summary> /// <param name="sphere">The BoundingSphere to test for overlap.</param><param name="result">[OutAttribute] Enumeration indicating the extent of overlap.</param> public void Contains(ref BoundingSphere sphere, out ContainmentType result) { 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) { result = ContainmentType.Contains; return; } double dmin = 0; double e = sphere.Center.X - Min.X; if (e < 0) { if (e < -sphere.Radius) { result = ContainmentType.Disjoint; return; } dmin += e * e; } else { e = sphere.Center.X - Max.X; if (e > 0) { if (e > sphere.Radius) { result = ContainmentType.Disjoint; return; } dmin += e * e; } } e = sphere.Center.Y - Min.Y; if (e < 0) { if (e < -sphere.Radius) { result = ContainmentType.Disjoint; return; } dmin += e * e; } else { e = sphere.Center.Y - Max.Y; if (e > 0) { if (e > sphere.Radius) { result = ContainmentType.Disjoint; return; } dmin += e * e; } } e = sphere.Center.Z - Min.Z; if (e < 0) { if (e < -sphere.Radius) { result = ContainmentType.Disjoint; return; } dmin += e * e; } else { e = sphere.Center.Z - Max.Z; if (e > 0) { if (e > sphere.Radius) { result = ContainmentType.Disjoint; return; } dmin += e * e; } } if (dmin <= sphere.Radius * sphere.Radius) { result = ContainmentType.Intersects; return; } result = ContainmentType.Disjoint; }
public static void Contains(ref BoundingSphere boundingSphere1, ref BoundingSphere boundingSphere2, out ContainmentType result) { var distance = Vector3.Distance(boundingSphere1.Center, boundingSphere2.Center); if (distance > boundingSphere1.Radius + boundingSphere2.Radius) { result = ContainmentType.Disjoint; } else { result = (distance <= boundingSphere1.Radius - boundingSphere2.Radius) ? ContainmentType.Contains : ContainmentType.Intersects; } }
/// <summary> /// Check the intersection between two <see cref="OrientedBoundingBox" /> /// </summary> /// <param name="obb">The OrientedBoundingBox to test.</param> /// <returns>The type of containment the two objects have.</returns> /// <remarks> /// For accuracy, The transformation matrix for both <see cref="OrientedBoundingBox" /> must not have any scaling applied /// to it. /// Anyway, scaling using Scale method will keep this method accurate. /// </remarks> public ContainmentType Contains(ref OrientedBoundingBox obb) { ContainmentType cornersCheck = Contains(obb.GetCorners()); if (cornersCheck != ContainmentType.Disjoint) { return(cornersCheck); } //http://www.3dkingdoms.com/weekly/bbox.cpp Vector3 SizeA = Extents; Vector3 SizeB = obb.Extents; Vector3[] RotA = GetRows(ref Transformation); Vector3[] RotB = GetRows(ref obb.Transformation); var R = new Matrix(); // Rotation from B to A var AR = new Matrix(); // absolute values of R matrix, to use with box extents float ExtentA, ExtentB, Separation; int i, k; // Calculate B to A rotation matrix for (i = 0; i < 3; i++) { for (k = 0; k < 3; k++) { R[i, k] = Vector3.Dot(RotA[i], RotB[k]); AR[i, k] = Math.Abs(R[i, k]); } } // Vector separating the centers of Box B and of Box A Vector3 vSepWS = obb.Center - Center; // Rotated into Box A's coordinates var vSepA = new Vector3(Vector3.Dot(vSepWS, RotA[0]), Vector3.Dot(vSepWS, RotA[1]), Vector3.Dot(vSepWS, RotA[2])); // Test if any of A's basis vectors separate the box for (i = 0; i < 3; i++) { ExtentA = SizeA[i]; ExtentB = Vector3.Dot(SizeB, new Vector3(AR[i, 0], AR[i, 1], AR[i, 2])); Separation = Math.Abs(vSepA[i]); if (Separation > ExtentA + ExtentB) { return(ContainmentType.Disjoint); } } // Test if any of B's basis vectors separate the box for (k = 0; k < 3; k++) { ExtentA = Vector3.Dot(SizeA, new Vector3(AR[0, k], AR[1, k], AR[2, k])); ExtentB = SizeB[k]; Separation = Math.Abs(Vector3.Dot(vSepA, new Vector3(R[0, k], R[1, k], R[2, k]))); if (Separation > ExtentA + ExtentB) { return(ContainmentType.Disjoint); } } // Now test Cross Products of each basis vector combination ( A[i], B[k] ) for (i = 0; i < 3; i++) { for (k = 0; k < 3; k++) { int i1 = (i + 1) % 3, i2 = (i + 2) % 3; int k1 = (k + 1) % 3, k2 = (k + 2) % 3; ExtentA = SizeA[i1] * AR[i2, k] + SizeA[i2] * AR[i1, k]; ExtentB = SizeB[k1] * AR[i, k2] + SizeB[k2] * AR[i, k1]; Separation = Math.Abs(vSepA[i2] * R[i1, k] - vSepA[i1] * R[i2, k]); if (Separation > ExtentA + ExtentB) { return(ContainmentType.Disjoint); } } } // No separating axis found, the boxes overlap return(ContainmentType.Intersects); }
public static void Contains(ref BoundingFrustum boundingFrustum1, ref BoundingFrustum boundingFrustum2, out ContainmentType result) { // TODO: Contains, BoundingFrustum. throw new NotImplementedException(); }
public void Contains(ref BoundingPolygon polygon, out ContainmentType result) { if (polygon == null) { throw new ArgumentNullException("polygon"); } Contains(polygon.vertexes, out result); }
public static void Contains(ref BoundingRectangle boundingRectangle1, ref BoundingRectangle boundingRectangle2, out ContainmentType result) { if (boundingRectangle1.X > boundingRectangle2.Right || boundingRectangle1.Y > boundingRectangle2.Bottom || boundingRectangle1.Right < boundingRectangle2.X || boundingRectangle1.Bottom < boundingRectangle2.Y) { result = ContainmentType.Disjoint; } else if ( boundingRectangle1.X <= boundingRectangle2.X && boundingRectangle1.Y <= boundingRectangle2.Y && boundingRectangle1.Right >= boundingRectangle2.Right && boundingRectangle1.Bottom >= boundingRectangle2.Bottom) { result = ContainmentType.Contains; } else { result = ContainmentType.Intersects; } }
/// <summary> /// Determines the containment type of a point to the bounding rectangle /// </summary> /// <param name="point">Point that will be checked for containment</param> /// <param name="result">The containment type of the point in the rectangle</param> public void Contains(ref Vector2 point, out ContainmentType result) { result = containsPoint(ref point) ? ContainmentType.Contains : ContainmentType.Disjoint; }
// проверяем курсор на пересечения с объектами среды и меняем вид курсора private void CursorStateChecker() { bool checkIfAnyIntersects = new bool(); bool[] checkCurrent = new bool[AvateeringXNA.AllEnvironmentItems.Count]; for (int i = 0; i < AvateeringXNA.AllEnvironmentItems.Count; i++) { collideResults1 = boundingBox.Contains(AvateeringXNA.AllEnvironmentItems[i].BoundingBox); checkCurrent[i] = collideResults1 == ContainmentType.Intersects; checkIfAnyIntersects = checkIfAnyIntersects || checkCurrent[i]; } if (checkIfAnyIntersects) { OnIntersect = true; scale = 1.2f; } else { OnIntersect = false; scale = 1.0f; } }
public static void SetVisibility(ref FrustumVisibilityStatus frustumVisibilityStatus, ContainmentType newVisibility) { frustumVisibilityStatus._visibility = newVisibility; }
/// /// Draws the octree. /// /// The viewing frustum used to determine if the octree is in view. /// The viewing matrix. /// The projection matrix. /// Determines how much of the octree is visible. /// The objects in the octree. /// The number of octrees drawn. private int Draw(BoundingFrustum frustum, Matrix view, Matrix projection, ContainmentType containment, List objects) { int count = 0; if (containment != ContainmentType.Contains) { containment = frustum.Contains(this.bounds); } // Draw the octree only if it is atleast partially in view. if (containment != ContainmentType.Disjoint) { // Draw the octree's bounds if there are objects in the octree. if (this.objects.Count > 0) { if (DebugDraw != null) DebugDraw.AddShape(new DebugBox(this.bounds, Color.White)); objects.AddRange(this.objects); count++; } // Draw the octree's children. if (this.children != null) { foreach (Octree child in this.children) { count += child.Draw(frustum, view, projection, containment, objects); } } } return count; }
/// <summary> /// Gets a value indicating whether this <see cref="BoundingSphere"/> contains the specified frustum. /// </summary> /// <param name="frustum">A <see cref="BoundingFrustum"/> which represents the frustum to evaluate.</param> /// <param name="result">A <see cref="ContainmentType"/> value representing the relationship between this sphere and the evaluated frustum.</param> public void Contains(BoundingFrustum frustum, out ContainmentType result) { result = Contains(frustum); }
private static void TestClipSpheres(ref MyCellCoord cell, ref BoundingSphereD nearClipSphere, ref BoundingSphereD farClipSphere, out ContainmentType nearClipRes, out ContainmentType farClipRes) { BoundingBoxD localAabb; MyVoxelCoordSystems.RenderCellCoordToLocalAABB(ref cell, out localAabb); localAabb.Inflate(MyVoxelConstants.VOXEL_SIZE_IN_METRES * (1 << cell.Lod)); nearClipSphere.Contains(ref localAabb, out nearClipRes); farClipSphere.Contains(ref localAabb, out farClipRes); }
private unsafe ContainmentType IntersectBoundingBoxCornerCase(ref BoundingBox box, uint faces, Vector3 *vertices, float minHeight, float maxHeight) { BoundingBox query = new BoundingBox(new Vector3(float.PositiveInfinity, float.PositiveInfinity, minHeight), new Vector3(float.NegativeInfinity, float.NegativeInfinity, maxHeight)); query.Min.Z = ((query.Min.Z - m_radius - m_detailScale) - m_minHillHeight) * m_heightRatioRecip; query.Max.Z = ((query.Max.Z - m_radius) - m_minHillHeight) * m_heightRatioRecip; var invalid = (ContainmentType)(-1); ContainmentType ct = invalid; for (int i = 0; i <= 5; ++i) { if ((faces & (1 << i)) == 0) { continue; } query.Min.X = float.PositiveInfinity; query.Min.Y = float.PositiveInfinity; query.Max.X = float.NegativeInfinity; query.Max.Y = float.NegativeInfinity; for (int j = 0; j < 8; ++j) { Vector2 tex; MyCubemapHelpers.TexcoordCalculators[i](ref vertices[j], out tex); if (tex.X < query.Min.X) { query.Min.X = tex.X; } if (tex.X > query.Max.X) { query.Max.X = tex.X; } if (tex.Y < query.Min.Y) { query.Min.Y = tex.Y; } if (tex.Y > query.Max.Y) { query.Max.Y = tex.Y; } } var cont = m_heightmap.Faces[i].QueryHeight(ref query); if (cont != ct) { if (ct == invalid) { ct = cont; } else { return(ContainmentType.Intersects); } } } return(ct); }
public void Contains(ref BoundingRectangle rect, out ContainmentType result) { Contains(rect.Corners(), out result); }
public void Contains(ref BoundingBox box, out ContainmentType result) { throw new NotImplementedException(); }
/// <summary> /// Tests whether the BoundingBox contains a point. /// </summary> /// <param name="point">The point to test for overlap.</param><param name="result">[OutAttribute] Enumeration indicating the extent of overlap.</param> public void Contains(ref Vector3 point, out ContainmentType result) { //first we get if point is out of box if (point.X < Min.X || point.X > Max.X || point.Y < Min.Y || point.Y > Max.Y || point.Z < Min.Z || point.Z > Max.Z) { result = ContainmentType.Disjoint; return; } //or if point is on box because coordonate of point is lesser or equal // ReSharper disable CompareOfFloatsByEqualityOperator if (point.X == Min.X || point.X == Max.X || point.Y == Min.Y || point.Y == Max.Y || point.Z == Min.Z || point.Z == Max.Z) // ReSharper restore CompareOfFloatsByEqualityOperator result = ContainmentType.Intersects; else result = ContainmentType.Contains; }
//Draws the world to each viewport public void Draw(GameTime gameTime) { int cam = 0; foreach (Viewport v in ports) { basicEffect.View = cameras[cam]; frustums[cam].Matrix = basicEffect.View * basicEffect.Projection; ContainmentType currentContainmentType = ContainmentType.Disjoint; //Generate HUD data Weapon equipDebug = core.players[cam].equipped; core.GraphicsDevice.Viewport = v; core.GraphicsDevice.Clear(voidColor); core.GraphicsDevice.VertexDeclaration = vertexDecl; //Pass parameters per viewport core.lighting.Parameters["World"].SetValue(Matrix.Identity); core.lighting.Parameters["View"].SetValue(cameras[cam]); core.lighting.Parameters["Projection"].SetValue(basicEffect.Projection); core.lighting.Parameters["WorldInverseTranspose"].SetValue(Matrix.Transpose(Matrix.Invert(basicEffect.World))); core.lighting.CurrentTechnique = core.lighting.Techniques["Lighting"]; //Draw each brush with effects //---------------------------------------------------------------------------------------- foreach (Brush b in core.mapEngine.brushes) { BoundingBox bb = b.boundingBox; currentContainmentType = frustums[cam].Contains(bb); if (currentContainmentType != ContainmentType.Disjoint) { foreach (Face face in b.faces) { core.lighting.Begin(); if (face.plane.texture != core.mapEngine.textures["common/caulk"]) { core.lighting.Parameters["Tex"].SetValue(face.plane.texture); foreach (EffectPass pass in core.lighting.CurrentTechnique.Passes) { pass.Begin(); VertexPositionNormalTexture[] pointList = face.getPoints(); short[] indices = new short[pointList.Length]; for (int i = 0; i < pointList.Length; i++) { indices[i] = (short)i; } core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>( PrimitiveType.TriangleFan, pointList, 0, pointList.Length, indices, 0, pointList.Length - 2); pass.End(); } } core.lighting.End(); } } } //Draw AI info //---------------------------------------------------------------------------------------------------- basicEffect.Begin(); /*Vector3 antiLift = new Vector3(0, AIEngine.nodeHeight, 0); * Vector3 renderLift = new Vector3(0, AIEngine.nodeRenderHeight, 0); * foreach (MeshNode m in core.aiEngine.mesh) { * drawLine(m.position, m.position, new Vector3(1, 1, 1)); * foreach(MeshNode m2 in m.neighbours) * drawLine(m2.position, m.position, new Vector3(1, 1, 1)); * }*/ //draw the collision grid /*for(int k = 0; k < core.physicsEngine.grid.GetLength(2); k++) * for (int j = 0; j < core.physicsEngine.grid.GetLength(1); j++) * for (int i = 0; i < core.physicsEngine.grid.GetLength(0); i++) { * if (!core.physicsEngine.grid[i, j, k].elements.Contains(core.getPlayerForIndex(PlayerIndex.One))) * continue; * Vector3 center = new Vector3((i + 0.5f) * core.physicsEngine.cellSize, * (j + 0.5f) * core.physicsEngine.cellSize, * (k + 0.5f) * core.physicsEngine.cellSize); * drawLine(new Vector3(i * core.physicsEngine.cellSize, j * core.physicsEngine.cellSize, k * core.physicsEngine.cellSize) + core.physicsEngine.gridOffset, * new Vector3((i + 1) * core.physicsEngine.cellSize, j * core.physicsEngine.cellSize, k * core.physicsEngine.cellSize) + core.physicsEngine.gridOffset, new Vector3(0, 1, 0)); * drawLine(new Vector3(i * core.physicsEngine.cellSize, j * core.physicsEngine.cellSize, k * core.physicsEngine.cellSize) + core.physicsEngine.gridOffset, * new Vector3(i * core.physicsEngine.cellSize, j * core.physicsEngine.cellSize, (k + 1) * core.physicsEngine.cellSize) + core.physicsEngine.gridOffset, new Vector3(0, 1, 0)); * drawLine(new Vector3(i * core.physicsEngine.cellSize, j * core.physicsEngine.cellSize, k * core.physicsEngine.cellSize) + core.physicsEngine.gridOffset, * new Vector3(i * core.physicsEngine.cellSize, (j + 1) * core.physicsEngine.cellSize, k * core.physicsEngine.cellSize) + core.physicsEngine.gridOffset, new Vector3(0, 1, 0)); * }*/ // basicEffect.End(); //draw the ai agents /*foreach (AIAgent a in core.aiEngine.agents) { * * if (a.spawnTime > 0) continue; * BoundingBox bb = a.getBoundingBox(); * currentContainmentType = frustums[cam].Contains(bb); * if (currentContainmentType != ContainmentType.Disjoint) * drawBoundingBox(bb, new Vector3(1, 0, 0)); * * //also draw the path * MeshNode last = null; * foreach (MeshNode m in a.path) { * if (last == null) { * last = m; * continue; * } * drawLine(m.position, last.position, new Vector3(1, 0, 0)); * last = m; * } * } * * foreach (Player p in core.players) { * * BoundingBox bb = p.getBoundingBox(); * currentContainmentType = frustums[cam].Contains(bb); * * if (p.spawnTime > 0) continue; * if (currentContainmentType != ContainmentType.Disjoint) * drawBoundingBox(p.getBoundingBox(), new Vector3(0, 1, 0)); * foreach (AIAgent a in core.aiEngine.agents) * drawLine(p.getPosition() + new Vector3(0, 32, 0), a.getPosition() + new Vector3(0, 32, 0), new Vector3(0, 0, 1)); * }*/ basicEffect.End(); //Draw each players bullets //-------------------------------------------------------------------------------------------- /*core.lighting.CurrentTechnique = core.lighting.Techniques["Texturing"]; * core.lighting.Parameters["Tex"].SetValue(core.bulletTex); * foreach(Player p in core.players){ * * VertexPositionColor[,] bVerts = new VertexPositionColor[p.bullets.Count, 1]; * int i = 0; * * foreach (Bullet b in p.bullets) { * * bVerts[i++,0].Position = b.pos; * * } * * //If bullets exist for the player * if (bVerts.Length > 0) * { * * for (int j = 0; j < bVerts.Length; ++j ) * { * VertexPositionColor[] point = new VertexPositionColor[1]; * point[0] = bVerts[j,0]; * * core.lighting.Begin(); * core.GraphicsDevice.RenderState.PointSpriteEnable = true; * core.GraphicsDevice.RenderState.AlphaBlendEnable = true; * core.GraphicsDevice.RenderState.SourceBlend = Blend.One; * core.GraphicsDevice.RenderState.DestinationBlend = Blend.One; * core.GraphicsDevice.RenderState.DepthBufferWriteEnable = false; * * core.GraphicsDevice.RenderState.PointSize = (64f * 100) / Vector3.Distance(p.position, point[0].Position); * foreach (EffectPass pass in core.lighting.CurrentTechnique.Passes) * { * pass.Begin(); * core.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>( * PrimitiveType.PointList, * point, * 0, * 1); * pass.End(); * } * * core.lighting.End(); * * } * core.GraphicsDevice.RenderState.PointSpriteEnable = false; * core.GraphicsDevice.RenderState.DepthBufferWriteEnable = true; * core.GraphicsDevice.RenderState.AlphaBlendEnable = false; * core.GraphicsDevice.RenderState.SourceBlend = Blend.One; * core.GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha; * * } * }*/ core.GraphicsDevice.RenderState.AlphaBlendEnable = true; core.GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha; core.GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha; core.GraphicsDevice.RenderState.AlphaTestEnable = true; core.GraphicsDevice.RenderState.DepthBufferWriteEnable = false; core.lighting.CurrentTechnique = core.lighting.Techniques["FadeTexturing"]; foreach (Laser l in lasers) { if (l.texture == null) { continue; } core.lighting.Parameters["Tex"].SetValue(l.texture); core.lighting.Parameters["Opacity"].SetValue(l.timeLeft / 600f); core.lighting.Begin(); foreach (EffectPass pass in core.lighting.CurrentTechnique.Passes) { pass.Begin(); core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>( PrimitiveType.TriangleList, l.horizVerts, 0, 4, l.indices, 0, 2); core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>( PrimitiveType.TriangleList, l.horizVerts, 0, 4, l.revIndices, 0, 2); core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>( PrimitiveType.TriangleList, l.vertVerts, 0, 4, l.indices, 0, 2); core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>( PrimitiveType.TriangleList, l.vertVerts, 0, 4, l.revIndices, 0, 2); pass.End(); } core.lighting.End(); } core.lighting.Parameters["Opacity"].SetValue(1); foreach (Projectile l in projectilesAndExplosions()) { if (l.texture == null) { continue; } core.lighting.Parameters["Tex"].SetValue(l.texture); core.lighting.Begin(); foreach (EffectPass pass in core.lighting.CurrentTechnique.Passes) { pass.Begin(); core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>( PrimitiveType.TriangleList, l.a, 0, 4, l.indices, 0, 2); core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>( PrimitiveType.TriangleList, l.a, 0, 4, l.revIndices, 0, 2); core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>( PrimitiveType.TriangleList, l.b, 0, 4, l.indices, 0, 2); core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>( PrimitiveType.TriangleList, l.b, 0, 4, l.revIndices, 0, 2); core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>( PrimitiveType.TriangleList, l.c, 0, 4, l.indices, 0, 2); core.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>( PrimitiveType.TriangleList, l.c, 0, 4, l.revIndices, 0, 2); pass.End(); } core.lighting.End(); } core.GraphicsDevice.RenderState.DepthBufferWriteEnable = true; core.GraphicsDevice.RenderState.AlphaBlendEnable = false; core.GraphicsDevice.RenderState.SourceBlend = Blend.One; core.GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha; core.GraphicsDevice.RenderState.AlphaTestEnable = false; //Draw item spawner locations //---------------------------------------------------------------------------------------------------- foreach (PickUpGen gen in core.pickupEngine.gens) { /*foreach (ModelMesh mesh in core.debugSphere.Meshes) { * * foreach (BasicEffect effect in mesh.Effects) { * * effect.World = Matrix.CreateScale(10) * Matrix.CreateTranslation(gen.pos); * effect.View = cameras[cam]; * effect.Projection = basicEffect.Projection; * * effect.LightingEnabled = true; * effect.AmbientLightColor = Color.Brown.ToVector3(); * * } * * mesh.Draw(); * * }*/ if (gen.held != null) { Model pickUpModel = core.arrow; switch (gen.itemType) { case PickUp.PickUpType.AMMO: pickUpModel = core.ammoUp; break; case PickUp.PickUpType.HEALTH: pickUpModel = core.medicross; break; } foreach (ModelMesh mesh in pickUpModel.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.World = Matrix.CreateScale(5) * Matrix.CreateRotationY(gen.held.rotation) * Matrix.CreateTranslation(gen.held.pos); effect.View = cameras[cam]; effect.Projection = basicEffect.Projection; effect.LightingEnabled = true; switch (gen.held.type) { case PickUp.PickUpType.AMMO: { effect.AmbientLightColor = Color.Yellow.ToVector3(); break; } case PickUp.PickUpType.HEALTH: { effect.AmbientLightColor = Color.Green.ToVector3(); break; } case PickUp.PickUpType.LEFT: { effect.AmbientLightColor = Color.DarkBlue.ToVector3(); break; } case PickUp.PickUpType.RIGHT: { effect.AmbientLightColor = Color.Red.ToVector3(); break; } } } mesh.Draw(); } } } //draw rockets foreach (Rocket gen in rockets) { foreach (ModelMesh mesh in core.debugSphere.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.World = Matrix.CreateScale(10) * Matrix.CreateTranslation(gen.position); effect.View = cameras[cam]; effect.Projection = basicEffect.Projection; effect.LightingEnabled = true; effect.AmbientLightColor = Color.Brown.ToVector3(); } mesh.Draw(); } } //draw explosions //-------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------- foreach (AIAgent ai in core.aiEngine.agents) { if (ai.spawnTime == 0) { foreach (ModelMesh mesh in core.steve.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.World = Matrix.CreateScale(1.5f) * Matrix.CreateRotationX(-MathHelper.PiOver2) * Matrix.CreateRotationY(MathHelper.PiOver2 - ai.direction.X) * Matrix.CreateTranslation(ai.getPosition() + new Vector3(0, core.steve.Meshes[0].BoundingSphere.Radius * 1.5f, 0)); effect.View = cameras[cam]; effect.Projection = basicEffect.Projection; //effect.LightingEnabled = true; //effect.AmbientLightColor = Color.Brown.ToVector3(); } mesh.Draw(); } } } foreach (Player p in core.players) { if (playerMap[p.playerIndex] != cam) { foreach (ModelMesh mesh in core.steve.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.World = Matrix.CreateScale(1.5f) * Matrix.CreateRotationX(-MathHelper.PiOver2) * Matrix.CreateRotationY(MathHelper.PiOver2 - p.direction.X) * Matrix.CreateTranslation(p.getPosition() + new Vector3(0, core.steve.Meshes[0].BoundingSphere.Radius * 1.5f, 0)); effect.View = cameras[cam]; effect.Projection = basicEffect.Projection; //effect.LightingEnabled = true; //effect.AmbientLightColor = Color.Brown.ToVector3(); } mesh.Draw(); } } } Player player = core.players[cam]; Texture2D weaponIcon = core.weaponIcons[player.equipped.GetType()]; core.spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState); Vector2 screenCenter = new Vector2(v.Width / 2, v.Height / 2); Vector2 ammoPos = new Vector2(screenCenter.X, v.Height - 80); core.spriteBatch.Draw(weaponIcon, ammoPos, Color.White); core.spriteBatch.DrawString(core.debugFont, player.ammo.ToString(), new Vector2(ammoPos.X + weaponIcon.Width, ammoPos.Y + weaponIcon.Height / 3), Color.White); Vector2 hpPos = new Vector2(screenCenter.X, v.Height - 80); core.spriteBatch.Draw(core.hudIcons["Health"], hpPos -= new Vector2(core.hudIcons["Health"].Width, 0), Color.White); core.spriteBatch.DrawString(core.debugFont, player.health.ToString(), new Vector2(hpPos.X - core.debugFont.MeasureString(player.health.ToString()).X, hpPos.Y + weaponIcon.Height / 3), Color.White); String mins = "" + Math.Floor(core.roundTime / 60); String secs = "" + Math.Round(core.roundTime % 60); core.spriteBatch.DrawString(core.debugFont, mins + ":" + secs, new Vector2(screenCenter.X, 80) - (core.debugFont.MeasureString(mins + ":" + secs) / 2), Color.White); core.spriteBatch.Draw(MenuScreen.crossHair, screenCenter, new Rectangle(0, 0, MenuScreen.crossHair.Width, MenuScreen.crossHair.Height), new Color(new Vector4(Color.White.ToVector3(), 0.65f)), 0f, new Vector2(MenuScreen.crossHair.Width / 2, MenuScreen.crossHair.Height / 2 + 25), 0.05f, SpriteEffects.None, 0); if (core.players[cam].drawUpgradePath) { //Texture2D downGradeTexture = MenuScreen.selectWheel; Vector2 wheelCenter = new Vector2(screenCenter.X, v.Height - player.currentPathsWheelHeight + MenuScreen.selectWheel.Height / 2); core.spriteBatch.Draw(MenuScreen.loadWheel, wheelCenter, new Rectangle(0, 0, MenuScreen.loadWheel.Width, MenuScreen.loadWheel.Height), Color.White, MathHelper.PiOver4, new Vector2(MenuScreen.loadWheel.Width / 2, MenuScreen.loadWheel.Height / 2 + 25), 0.5f, SpriteEffects.None, 0); core.spriteBatch.Draw(MenuScreen.ugLeft, wheelCenter, new Rectangle(0, 0, MenuScreen.ugLeft.Width, MenuScreen.ugLeft.Height), Color.White, -MathHelper.PiOver4, new Vector2(MenuScreen.ugLeft.Width / 2, MenuScreen.ugLeft.Height / 2 + 25), 0.5f, SpriteEffects.None, 0); core.spriteBatch.Draw(MenuScreen.ugRight, wheelCenter, new Rectangle(0, 0, MenuScreen.ugRight.Width, MenuScreen.ugRight.Height), Color.White, MathHelper.PiOver4, new Vector2(MenuScreen.ugRight.Width / 2, MenuScreen.ugRight.Height / 2 + 25), 0.5f, SpriteEffects.None, 0); Texture2D leftWeaponIcon = core.weaponIcons[player.equipped.upgradeLeft().GetType()]; Texture2D rightWeaponIcon = core.weaponIcons[player.equipped.upgradeRight().GetType()]; Vector2 rightPos = new Vector2(wheelCenter.X + v.Width / 4, wheelCenter.Y - 280); core.spriteBatch.Draw(rightWeaponIcon, rightPos - new Vector2(rightWeaponIcon.Width, 0), Color.White); String right = player.equipped.upgradeRight().GetType().ToString(); core.spriteBatch.DrawString(core.debugFont, right.Substring(right.LastIndexOf(".") + 1), new Vector2(rightPos.X, rightPos.Y + rightWeaponIcon.Height / 3), Color.White); Vector2 leftPos = new Vector2(wheelCenter.X - v.Width / 4, wheelCenter.Y - 280); core.spriteBatch.Draw(leftWeaponIcon, leftPos, Color.White); String left = player.equipped.upgradeLeft().GetType().ToString(); core.spriteBatch.DrawString(core.debugFont, left.Substring(left.LastIndexOf(".") + 1), new Vector2(leftPos.X - core.debugFont.MeasureString(left.Substring(left.LastIndexOf(".") + 1)).X, leftPos.Y + leftWeaponIcon.Height / 3), Color.White); } if (core.players[cam].showScoreboard) { core.spriteBatch.Draw(MenuScreen.loadWheel, screenCenter, new Rectangle(0, 0, MenuScreen.loadWheel.Width, MenuScreen.loadWheel.Height), Color.White, 0f, new Vector2(MenuScreen.loadWheel.Width / 2, MenuScreen.loadWheel.Height / 2 + 25), 0.5f, SpriteEffects.None, 1f); } if (core.players[cam].damageAlpha1 != 0 || core.players[cam].damageAlpha2 != 0) { core.spriteBatch.Draw(MenuScreen.splatter1, new Rectangle((int)screenCenter.X - v.Width / 2, (int)screenCenter.Y - v.Height / 2, v.Width, v.Height), new Rectangle(0, 0, 1024, 576), new Color((new Vector4(Color.White.ToVector3(), core.players[cam].damageAlpha1))) , 0f, Vector2.Zero, SpriteEffects.None, 1f); core.spriteBatch.Draw(MenuScreen.splatter2, new Rectangle((int)screenCenter.X - v.Width / 2, (int)screenCenter.Y - v.Height / 2, v.Width, v.Height), new Rectangle(0, 0, 1024, 576), new Color((new Vector4(Color.White.ToVector3(), core.players[cam].damageAlpha2))) , 0f, Vector2.Zero, SpriteEffects.None, 1f); } core.spriteBatch.End(); cam++; } }
/// <summary> /// Checks whether the current BoundingFrustum contains the specified point. /// </summary> /// <param name="point">The point to test for overlap.</param><param name="result">[OutAttribute] Enumeration indicating the extent of overlap.</param> public void Contains(ref Vector3 point, out ContainmentType result) { CreatePlanes(); for (var i = 0; i < PlaneCount; ++i) { if (_planes[i].Side(point) > 0) { result = ContainmentType.Disjoint; return; } } result = ContainmentType.Contains; }
public void Contains(ref Vector2D point, out ContainmentType result) { ContainsInclusive(vertexes, ref point, out result); }
/// <summary> /// Checks whether the current BoundingSphere contains the specified BoundingSphere. /// </summary> /// <param name="sphere">The BoundingSphere to test for overlap.</param><param name="result">[OutAttribute] Enumeration indicating the extent of overlap.</param> public void Contains(ref BoundingSphere sphere, out ContainmentType result) { result = Contains(Radius, sphere.Radius, Vector3.DistanceSquared(sphere.Center, Center)); }
public override void Draw() { base.Draw(); if (MySession.Static == null) { return; } if (m_showVoxelProbe) { float halfSize = m_probeSize * .5f; float lodSize = 1 << m_probeLod; if (m_moveProbe) { m_probePosition = MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * m_probeSize * 3; } BoundingBox bb; BoundingBoxD bbp; // Box used for drawing and finding the probe and drawing bb = new BoundingBox(m_probePosition - halfSize, m_probePosition + halfSize); bbp = (BoundingBoxD)bb; m_voxels.Clear(); MyGamePruningStructure.GetAllVoxelMapsInBox(ref bbp, m_voxels); MyVoxelBase map = null; double distance = double.PositiveInfinity; foreach (var vox in m_voxels) { var d = Vector3D.Distance(vox.WorldMatrix.Translation, m_probePosition); if (d < distance) { distance = d; map = vox; } } ContainmentType cont = ContainmentType.Disjoint; if (map != null) { map = map.RootVoxel; Vector3 localPos = Vector3.Transform(m_probePosition, map.PositionComp.WorldMatrixInvScaled); localPos += map.SizeInMetresHalf; // Create similar bounding box in storage space bb = new BoundingBox(localPos - halfSize, localPos + halfSize); m_probedVoxel = map; Section("Probing {1}: {0}", map.StorageName, map.GetType().Name); Text("Probe mode: {0}", m_mode); if (m_mode == ProbeMode.Intersect) { Text("Local Pos: {0}", localPos); Text("Probe Size: {0}", m_probeSize); cont = map.Storage.Intersect(ref bb, false); Text("Result: {0}", cont.ToString()); bbp = (BoundingBoxD)bb; } else { Vector3I min = Vector3I.Floor(bb.Min / lodSize + .5f); Vector3I max = min + ((int)m_probeSize >> m_probeLod) - 1; bbp = new BoundingBoxD(min << m_probeLod, (max + 1) << m_probeLod); bbp.Translate(new Vector3D(-.5)); Text("Probe Size: {0}({1})", (max - min).X + 1, m_probeSize); Text("Probe LOD: {0}", m_probeLod); var requestData = (MyStorageDataTypeEnum)(int)m_mode; MyVoxelRequestFlags flags = MyVoxelRequestFlags.ContentChecked; m_target.Resize(max - min + 1); m_target.Clear(MyStorageDataTypeEnum.Content, 0); m_target.Clear(MyStorageDataTypeEnum.Material, 0); map.Storage.ReadRange(m_target, (MyStorageDataTypeFlags)(1 << (int)requestData), m_probeLod, ref min, ref max, ref flags); if (requestData == MyStorageDataTypeEnum.Content) { if (flags.HasFlag(MyVoxelRequestFlags.EmptyContent)) { cont = ContainmentType.Disjoint; } else if (flags.HasFlag(MyVoxelRequestFlags.FullContent)) { cont = ContainmentType.Contains; } else { int val = m_target.ValueWhenAllEqual(requestData); if (val == -1) { cont = ContainmentType.Intersects; } else if (val >= MyVoxelConstants.VOXEL_ISO_LEVEL) { cont = ContainmentType.Contains; } else { cont = ContainmentType.Disjoint; } } DrawContentsInfo(m_target); } else { cont = ContainmentType.Disjoint; DrawMaterialsInfo(m_target); } Text(Color.Yellow, 1.5f, "Voxel Editing:"); Text("Value to set (Ctrl+Mousewheel): {0}", m_valueToSet); if (m_probeLod != 0) { Text(Color.Red, "Writing to storage is only possible when probe is set to LOD 0"); } else { Text("Use primary mouse button to set."); Text("Position/Extents: {0}/{1}", bbp.Min, bbp.Extents); if (MyInput.Static.IsLeftMousePressed()) { if (requestData == MyStorageDataTypeEnum.Content) { m_target.BlockFillContent(Vector3I.Zero, m_target.Size3D - Vector3I.One, m_valueToSet); } else { m_target.BlockFillMaterial(Vector3I.Zero, m_target.Size3D - Vector3I.One, m_valueToSet); } map.Storage.WriteRange(m_target, (MyStorageDataTypeFlags)(1 << (int)requestData), ref min, ref max); } } } } else { Section("No Voxel Found"); Text("Probe mode: {0}", m_mode); Text("Probe Size: {0}", m_probeSize); } Color c = ColorForContainment(cont); if (map != null) { bbp = bbp.Translate(-map.SizeInMetresHalf); MyOrientedBoundingBoxD oobb = new MyOrientedBoundingBoxD(bbp, map.WorldMatrix); MyRenderProxy.DebugDrawOBB(oobb, c, 0.5f, true, false); } else { MyRenderProxy.DebugDrawAABB(bbp, c, 0.5f, 1.0f, true); } } }
private void Contains(Vector2D[] otherVertexes, out ContainmentType result) { ContainmentType contains; result = ContainmentType.Unknown; for (int index = 0; index < vertexes.Length; ++index) { ContainsExclusive(otherVertexes, ref vertexes[index], out contains); if (contains == ContainmentType.Contains) { result = ContainmentType.Intersects; return; } } for (int index = 0; index < otherVertexes.Length && result != ContainmentType.Intersects; ++index) { ContainsInclusive(vertexes, ref otherVertexes[index], out contains); result |= contains; } if (result == ContainmentType.Disjoint) { bool test; Intersects(this.vertexes, otherVertexes, out test); if (test) { result = ContainmentType.Intersects; } } }
private Color ColorForContainment(ContainmentType cont) { return(cont == ContainmentType.Disjoint ? Color.Green : (cont == ContainmentType.Contains ? Color.Yellow : Color.Red)); }
/// <summary> /// Checks whether the current BoundingFrustum contains the specified BoundingSphere. /// </summary> /// <param name="sphere">The BoundingSphere to test for overlap.</param><param name="result">[OutAttribute] Enumeration indicating the extent of overlap.</param> public void Contains(ref BoundingSphere sphere, out ContainmentType result) { CreatePlanes(); var intersects = false; for (var i = 0; i < PlaneCount; ++i) { PlaneIntersectionType planeIntersectionType; sphere.Intersects(ref _planes[i], out planeIntersectionType); switch (planeIntersectionType) { case PlaneIntersectionType.Front: result = ContainmentType.Disjoint; return; case PlaneIntersectionType.Intersecting: intersects = true; break; } } result = intersects ? ContainmentType.Intersects : ContainmentType.Contains; }
public override void Handle() { Logging.Instance.WriteDebug("ProcessLocalYards Start"); var removeYards = new HashSet <ShipyardItem>(); foreach (ShipyardItem item in LocalYards) { //see if the shipyard has been deleted if (item.YardEntity.Closed || item.YardEntity.Physics == null || item.YardType == ShipyardType.Invalid || (item.StaticYard && !item.YardEntity.Physics.IsStatic)) { //the client shouldn't tell the server the yard is invalid //item.Disable(); removeYards.Add(item); continue; } if (item.StaticYard) { UpdateBoxLines(item); } //don't draw boxes inside active yards, it's distracting if (item.YardType != ShipyardType.Disabled) { continue; } var corners = new Vector3D[8]; item.ShipyardBox.GetCorners(corners, 0); double dist = Vector3D.DistanceSquared(corners[0], item.ShipyardBox.Center); var sphere = new BoundingSphereD(item.ShipyardBox.Center, dist); //Utilities.InvokeBlocking(()=> entities = MyAPIGateway.Entities.GetTopMostEntitiesInSphere(ref sphere)); List <IMyEntity> entities = MyAPIGateway.Entities.GetTopMostEntitiesInSphere(ref sphere); if (entities.Count == 0) { Logging.Instance.WriteDebug("Couldn't get entities in ProcessLocalYards"); continue; } var removeGrids = new HashSet <IMyCubeGrid>(); foreach (IMyEntity entity in entities) { var grid = entity as IMyCubeGrid; if (grid == null) { continue; } if (grid.EntityId == item.EntityId) { continue; } //workaround to not blind people with digi's helmet mod if (grid.Physics == null && grid.Projector() == null) { continue; } if (grid.Closed || grid.MarkedForClose) { removeGrids.Add(grid); continue; } if (LocalYards.Any(x => x.EntityId == grid.EntityId)) { continue; } //create a bounding box around the ship MyOrientedBoundingBoxD gridBox = MathUtility.CreateOrientedBoundingBox(grid); //check if the ship bounding box is completely inside the yard box ContainmentType result = item.ShipyardBox.Contains(ref gridBox); if (result == ContainmentType.Contains) { item.ContainsGrids.Add(grid); item.IntersectsGrids.Remove(grid); } else if (result == ContainmentType.Intersects) { item.IntersectsGrids.Add(grid); item.ContainsGrids.Remove(grid); } else { removeGrids.Add(grid); } } foreach (IMyCubeGrid containGrid in item.ContainsGrids) { if (!entities.Contains(containGrid)) { removeGrids.Add(containGrid); } } foreach (IMyCubeGrid intersectGrid in item.IntersectsGrids) { if (!entities.Contains(intersectGrid)) { removeGrids.Add(intersectGrid); } } foreach (IMyCubeGrid removeGrid in removeGrids) { ShipyardCore.BoxDict.Remove(removeGrid.EntityId); item.ContainsGrids.Remove(removeGrid); item.IntersectsGrids.Remove(removeGrid); } } foreach (ShipyardItem removeItem in removeYards) { foreach (IMyCubeGrid grid in removeItem.ContainsGrids) { ShipyardCore.BoxDict.Remove(grid.EntityId); } foreach (IMyCubeGrid grid in removeItem.IntersectsGrids) { ShipyardCore.BoxDict.Remove(grid.EntityId); } LocalYards.Remove(removeItem); } }
public override bool GetIntersectionWithBoundingFrustum(ref BoundingFrustum boundingFrustum) { ContainmentType con = boundingFrustum.Contains(WorldAABB); return(con == ContainmentType.Contains || con == ContainmentType.Intersects); }
public void Contains(ref BoundingBox box, out ContainmentType result) { result = Contains(box); }