/// <param name="depth">Number of iterations.</param> /// <param name="clipModels">Adds the ClipModel instances to this list.</param> private static List<ClipModel> _getClipModels(IRenderable entity, Model model, IList<IPortal> portalList, Vector2 centerPoint, IPortal portalEnter, Matrix4 modelMatrix, int depth, int count) { List<ClipModel> clipModels = new List<ClipModel>(); if (depth <= 0) { return clipModels; } List<IPortal> collisions = Portal.GetCollisions( centerPoint, Vector2Ext.Transform(model.GetWorldConvexHull(), entity.GetWorldTransform().GetMatrix() * modelMatrix), portalList, PORTAL_CLIP_MARGIN); List<LineF> clipLines = new List<LineF>(); foreach (IPortal portal in collisions) { Vector2[] pv = Portal.GetWorldVerts(portal); LineF clipLine = new LineF(pv); LineF portalLine = new LineF(pv); Vector2 normal = portal.WorldTransform.GetRight(); if (portal.WorldTransform.MirrorX) { normal = -normal; } Vector2 portalNormal = portal.WorldTransform.Position + normal; if (portalLine.GetSideOf(centerPoint) != portalLine.GetSideOf(portalNormal)) { normal *= Portal.EnterMinDistance; } else { clipLine = clipLine.Reverse(); normal *= -Portal.EnterMinDistance; } clipLines.Add(clipLine); if (portalEnter == null || portal != portalEnter.Linked) { Vector2 centerPointNext = Vector2Ext.Transform(portal.WorldTransform.Position + normal, Portal.GetLinkedMatrix(portal)); clipModels.AddRange(_getClipModels(entity, model, portalList, centerPointNext, portal, modelMatrix * Portal.GetLinkedMatrix(portal), depth - 1, count + 1)); } } clipModels.Add(new ClipModel(entity, model, clipLines.ToArray(), modelMatrix)); return clipModels; }
public static List<ClipModel> GetClipModels(IRenderable entity, IList<IPortal> portalList, int depth) { List<ClipModel> clipModels = new List<ClipModel>(); if (entity.IsPortalable && !entity.DrawOverPortals) { foreach (Model m in entity.GetModels()) { clipModels.AddRange(_getClipModels(entity, m, portalList, entity.GetWorldTransform().Position, null, Matrix4.Identity, depth, 0)); } } else { foreach (Model m in entity.GetModels()) { clipModels.Add(new ClipModel(entity, m, new LineF[0], Matrix4.Identity)); } } return clipModels; }