Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Checks - and resolves - collisions with worldlines.
- /// Returns a list of vectors it has resolved upon.
- /// </summary>
- public virtual List<Vector2> CheckResolveCollision(BaseWorld world)
- {
- List<Vector2> resolveNormal = new List<Vector2>();
- foreach (Line worldLine in world.lines)
- {
- int numOverlaps = 0;
- float currentOverlapMagnitude = 0;
- Vector2 currentOverlapAxis = Vector2.Zero;
- bool minSet = false;
- Vector2 wLNormal = worldLine.normal;
- Tuple<float, float> minmaxPolyUseCheck = ProjectToAxis(wLNormal);
- float minPolyUC = minmaxPolyUseCheck.Item1;
- float maxPolyUC = minmaxPolyUseCheck.Item2;
- float wLinePoint = worldLine.ProjectToAxis(wLNormal).Item1; //these are always going to be the same.
- float checkMagnitude = 0;
- if ((wLinePoint > minPolyUC && wLinePoint < maxPolyUC))
- {
- checkMagnitude = MathHelper.Min(Math.Abs(Math.Abs(minPolyUC) - Math.Abs(wLinePoint)), Math.Abs(Math.Abs(maxPolyUC) - Math.Abs(wLinePoint)));
- }
- else continue;
- foreach (Line polyLine in lines)
- {
- Vector2 currentNormal = polyLine.normal;
- Tuple<float, float> minmaxPoly = ProjectToAxis(currentNormal);
- float minPoly = minmaxPoly.Item1;
- float maxPoly = minmaxPoly.Item2;
- Tuple<float, float> minmaxWLine = worldLine.ProjectToAxis(currentNormal);
- float minWLine = minmaxWLine.Item1;
- float maxWLine = minmaxWLine.Item2;
- if (((maxWLine > minPoly && maxWLine >= maxPoly) && (minWLine <= minPoly && minWLine < maxPoly)) || ((minWLine > minPoly && minWLine < maxPoly) || (maxWLine >= minPoly && maxWLine <= maxPoly)))
- { //I have absolutely no idea why the above line works. Changing one little thing breaks it
- if (checkMagnitude < currentOverlapMagnitude || !minSet)
- {
- currentOverlapMagnitude = checkMagnitude;
- currentOverlapAxis = worldLine.normal;
- minSet = true;
- }
- numOverlaps++;
- }
- else break;
- }
- if (numOverlaps >= lines.Count()) //Lines.count should also be = to number of distinct vertices.
- {
- Move(worldLine.normal * currentOverlapMagnitude);
- resolveNormal.Add(worldLine.normal);
- }
- }
- return resolveNormal;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement