/// <summary> /// Create a Bound from a top-left position, and a width-height /// </summary> /// <param name="position">The top-left position of the bounds</param> /// <param name="size">The width-height of the bounds, in terms of X and Y</param> /// <param name="rotation">The rotation of the Bound, in radians</param> public Bounds(Vector position, Vector size, float rotation) { this.position = position; this.size = size; this.rotation = rotation; float width = size.X; float height = size.Y; float widthBar = width / 2; float heightBar = height / 2; convex = new Convex(position + size / 2, rotation, new VectorSet( new Vector(-widthBar, -heightBar), new Vector(widthBar, -heightBar), new Vector(widthBar, heightBar), new Vector(-widthBar, heightBar))); }
public ObjectController(ObjectManager manager) : base(manager) { Sprite = new Sprite(); Unselect = false; convex = new Convex(Vector.Zero, 0, VectorSet.Dodecahedren); ControlPointLightRadius = new ObjectControlPoint(manager); ControlPointRight = new ObjectControlPoint(manager); ControlPointRightTop = new ObjectControlPoint(manager); ControlPointTop = new ObjectControlPoint(manager); ControlPointLeftTop = new ObjectControlPoint(manager); ControlPointLeft = new ObjectControlPoint(manager); ControlPointLeftBot = new ObjectControlPoint(manager); ControlPointBot = new ObjectControlPoint(manager); ControlPointRightBot = new ObjectControlPoint(manager); ControlPoints = new ObjectControlPoint[] { ControlPointRight, ControlPointRightTop, ControlPointTop, ControlPointLeftTop, ControlPointLeft, ControlPointLeftBot, ControlPointBot, ControlPointRightBot }; }
public ConvexHull(Convex convex, Color color) : this(convex.Vectors.rotate(convex.Rotation).toArray(), color, convex.Origin) { }
public Boolean isWithin(Convex conv) { return(getCollisionInfo(conv) != null); }
/// <summary> /// Run an SAT test against the other convex object /// </summary> /// <param name="conv"></param> /// <returns></returns> public CollisionInfo getCollisionInfo(Convex conv) { List <Vector> axisSet = new List <Vector>(); VectorSet aSet = calculateTrans(); VectorSet bSet = conv.calculateTrans(); Vector mtv = Vector.One * 10000; bool colliding = true; aSet.forEachEdge(e => axisSet.Add(e.Normal)); bSet.forEachEdge(e => axisSet.Add(e.Normal)); foreach (Vector a in axisSet) { //create the axis Vector axis = a.Unit; float aMin = float.MaxValue, aMax = float.MinValue; float bMin = float.MaxValue, bMax = float.MinValue; //project conv, a, onto axis aSet.forEachVector(v => { float p = (v).dot(axis); if (p < aMin) { aMin = p; } if (p > aMax) { aMax = p; } }); //project conv, b, onto axis bSet.forEachVector(v => { float p = (v).dot(axis); if (p < bMin) { bMin = p; } if (p > bMax) { bMax = p; } }); //are a and b overlapping? if ((aMin > bMin && aMin < bMax) || (aMax > bMin && aMax < bMax) || (bMin > aMin && bMin < aMax) || (bMax > aMin && bMax < aMax) ) { //they are overlapping //calculate overlap vector float overlap = Math.Min(aMax, bMax) - Math.Max(aMin, bMin); if (aMax < bMax) { overlap *= -1; } if (Math.Abs(overlap) < mtv.Length) { mtv = axis * overlap; } } else { //they are not overlapping. no collision can be occuring. colliding = false; break; } } CollisionInfo collInfo = new CollisionInfo(mtv); if (!colliding) { return(null); } else { return(collInfo); } }