/** Rotates a point counter clockwise by the angle around a pivot * @param v is the point to rotate * @param pivot is the pivot, naturally * @param angle is the angle of rotation cw in radians * @returns the rotated point * @since v0.99.1 */ public static CCPoint RotateByAngle(CCPoint v, CCPoint pivot, float angle) { CCPoint r = v.Sub(pivot); float cosa = (float)Math.Cos(angle), sina = (float)Math.Sin(angle); float t = r.x; r.x = t * cosa - r.y * sina + pivot.x; r.y = t * sina + r.y * cosa + pivot.y; return(r); }
public virtual CCActionInterval reverse() { CCPointArray copyConfig = (CCPointArray)m_pPoints.copy(); // // convert "absolutes" to "diffs" // CCPoint p = copyConfig.getControlPointAtIndex(0); for (int i = 1; i < copyConfig.count(); ++i) { CCPoint current = copyConfig.getControlPointAtIndex(i); CCPoint diff = current.Sub(p); copyConfig.replaceControlPoint(diff, i); p = current; } // convert to "diffs" to "reverse absolute" CCPointArray pReverse = copyConfig.reverse(); // 1st element (which should be 0,0) should be here too p = pReverse.getControlPointAtIndex(pReverse.count() - 1); pReverse.removeControlPointAtIndex(pReverse.count() - 1); p = p.Neg(); pReverse.insertControlPoint(p, 0); for (int i = 1; i < pReverse.count(); ++i) { CCPoint current = pReverse.getControlPointAtIndex(i); current = current.Neg(); CCPoint abs = current.Add(p); pReverse.replaceControlPoint(abs, i); p = abs; } return(CCCardinalSplineBy.create(m_fDuration, pReverse, m_fTension)); }
public static float Distance(CCPoint v1, CCPoint v2) { return(Length(v1.Sub(v2))); }