public static bool Intersects(ref ProjectionRectangle rect, ref ViewClipShape shape) { int min, max; Project(rect.Axis[0], shape, out min, out max); if (rect.MinimumAxis[0] > max || rect.MaximumAxis[0] < min) { return(false); } Project(rect.Axis[1], shape, out min, out max); if (rect.MinimumAxis[1] > max || rect.MaximumAxis[1] < min) { return(false); } for (int i = 0; i < shape.Count; i++) { Project(shape.GetAxis(i), rect, out min, out max); if (shape.GetMinimumScalar(i) > max || shape.GetMaximumScalar(i) < min) { return(false); } } return(true); }
internal void Update(GameTime gameTime, ICamera Camera) { ViewFrustrum.Matrix = Camera.ViewProjection; CameraPosition = Camera.Position; //Corners 0-3 = near plane clockwise, Corners 4-7 = far plane clockwise ViewFrustrum.GetCorners(VFCorners); var clip = ClippingFrustrum.FromFrustrumCorners(VFCorners, CameraPosition); ClipShape = clip.ProjectToTargetY(_position.Y); _lastCameraPosition = _cameraPosition; IndexCount = 0; _rootNode.Merge(); _rootNode.EnforceMinimumDepth(); _activeNode = _rootNode.DeepestNodeWithPoint(ClipShape.ViewPoint); if (_activeNode != null) { _activeNode.Split(); } _rootNode.SetActiveVertices(); _buffers.UpdateIndexBuffer(Indices, IndexCount); _buffers.SwapBuffer(); }
private void AddCameraPosition(ref ViewClipShape inputShape) { var cam = new Vector2(CameraPosition.X, CameraPosition.Z); var closest = 0; var closeDist = Vector2.Distance(cam, inputShape.Point1); //find closest point for (var i = 1; i < inputShape.Count; i++) { var dist = Vector2.Distance(cam, inputShape[i]); if (dist <= closeDist) closest = i; } //Find the adjacent points int adj1, adj2; if (closest == 0) { adj1 = inputShape.Count - 1; adj2 = closest + 1; } else if (closest == inputShape.Count - 1) { adj1 = closest - 1; adj2 = 0; } else { adj1 = closest - 1; adj2 = closest + 1; } var angle1 = Utils.LineAngle(inputShape[closest] - cam, inputShape[adj1] - cam); var angle2 = Utils.LineAngle(inputShape[closest] - cam, inputShape[adj2] - cam); if (angle1 < 90 && angle2 < 90) { //point will be inside the shape, replace it with camera position inputShape.ReplacePoint(closest, cam); } else { //use the angles to determine what points it is between if (angle1 >= 90) { inputShape.InsertPointAt(closest, cam); } else { inputShape.InsertPointAt(adj2, cam); } } }
internal static void Project(Vector2 axis, ref ViewClipShape shape, out int min, out int max) { min = GenerateScalar(shape.Point1, ref axis); max = min; var current = GenerateScalar(shape.Point2, ref axis); if (current <= min) min = current; else if (current > max) max = current; current = GenerateScalar(shape.Point3, ref axis); if (current <= min) min = current; else if (current > max) max = current; if (shape.Count < 4) return; current = GenerateScalar(shape.Point4, ref axis); if (current <= min) min = current; else if (current > max) max = current; if (shape.Count < 5) return; current = GenerateScalar(shape.Point5, ref axis); if (current <= min) min = current; else if (current > max) max = current; if (shape.Count < 6) return; current = GenerateScalar(shape.Point6, ref axis); if (current <= min) min = current; else if (current > max) max = current; }
internal static bool Intersects(ref Rectangle shape1, ref ViewClipShape shape2) { int min, max; //Check against rectangle axis Project(shape1.Axis1, ref shape2, out min, out max); if (shape1.A1Min > max || shape1.A1Max < min) return false; Project(shape1.Axis2, ref shape2, out min, out max); if (shape1.A2Min > max || shape1.A2Max < min) return false; //Check against the viewclipshape axis - thre are at least 3 for (var i = 0; i < shape2.Count; i++) { Project(shape2.GetAxis(i), ref shape1, out min, out max); if (shape2.GetMinScalar(i) > max || shape2.GetMaxScalar(i) < min) return false; } return true; }
public bool Intersects(ViewClipShape shape) { return Intersection.Intersects(ref this, ref shape); }