public void render(GraphicsDevice graphicsDevice, Matrix transform, RenderHints hints) { PrimitiveBatch primBatch = PrimitiveBatch.getInstance(graphicsDevice); primBatch.Transform = transform; primBatch.Begin(hints.PrimitiveType); VectorSet vSet = calculateTrans(); vSet.forEachVector(v => { primBatch.AddVertex(v, hints.Color); }); primBatch.End(); }
/// <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); } }