// Returns the point where the bolt is at a given fraction of the way through the bolt. Passing // zero will return the start of the bolt, and passing 1 will return the end. private CCPoint GetPoint(BoltStatus b, float position) { var start = b.Bolt.Start; float length = CCPoint.Distance(start, b.Bolt.End); CCPoint dir = (b.Bolt.End - start) / length; position *= length; for (int i = 0; i < b.Segments.Count; i += 2) { if (CCPoint.Dot(b.Segments[i] - start, dir) >= position) { float lineStartPos = CCPoint.Dot(b.Segments[i] - start, dir); float lineEndPos = CCPoint.Dot(b.Segments[i + 1] - start, dir); float linePos = (position - lineStartPos) / (lineEndPos - lineStartPos); return(CCPoint.Lerp(b.Segments[i], b.Segments[i + 1], linePos)); } } return(CCPoint.Zero); }
// Returns the point where the bolt is at a given fraction of the way through the bolt. Passing // zero will return the start of the bolt, and passing 1 will return the end. private CCPoint GetPoint(BoltStatus b, float position) { var start = b.Bolt.Start; float length = CCPoint.Distance(start, b.Bolt.End); CCPoint dir = (b.Bolt.End - start) / length; position *= length; for (int i = 0; i < b.Segments.Count; i += 2) { if (CCPoint.Dot(b.Segments[i] - start, dir) >= position) { float lineStartPos = CCPoint.Dot(b.Segments[i] - start, dir); float lineEndPos = CCPoint.Dot(b.Segments[i + 1] - start, dir); float linePos = (position - lineStartPos) / (lineEndPos - lineStartPos); return CCPoint.Lerp(b.Segments[i], b.Segments[i + 1], linePos); } } return (CCPoint.Zero); }