/** @def ccrandom_minus1_1 returns a random float between -1 and 1 returns a random number that floats randomly between 1 and 1 */#define &NBSP;CCRANDOM_MINUS1_1 () ((2.0f* ((float) rand ()/rand_max)) /** @def ccrandom_0_1 returns a random float between 0 and 1 Returns a random number that floats randomly between 0 and 1 */#define &NBSP;CCRANDOM_0_1 () ((float) rand ()/rand_max)/** @def cc _degrees_to_radians converts degrees to radians convert degrees to radians */#define &NBSP;CC_ Degrees_to_radians (__angle__) ((__angle__) * 0.01745329252f) // pi / 180/** @def CC_RADIANS_TO_DEGREES converts radians to degrees convert radians to degrees */# Define cc_radians_to_degrees (__angle__) ((__angle__) * 57.29577951f) // PI * 180*************************************************************************************/** helper macro that creates a vec2 @return Vec2 @since v0.7.2 */cc_deprecated_attribute &NBSP;INLINE&NBSP;VEC2&NBSP;CCP (float x, float y) { return vec2 (x, y);} /** returns opposite of point. @return Vec2 @since v0.7.2 @ Deprecated please use vec2::-, for example: -v1 */cc_deprecated_attribute static inline vec2ccpneg (const vec2& v) { return -v;} /** calculates sum of two points. @return Vec2 @since v0.7.2 @deprecated &NBSP;PLEASE&NBSP;USE&NBSP;VEC2::+,&NBSP;FOR&NBSP;EXAMPLE:&NBSP;V1&NBSP;+&NBSP;V2&NBSP;*/CC_ Deprecated_attribute static inline vec2ccpadd (const vec2& v1, const VEC2&&NBSP;V2) { return v1 + v2;} /** calculates difference of two points. @return Vec2 @since v0.7.2 @deprecated please use vec2::-, for example: v1 - v2 */CC_DEPRECATED_ATTRIBUTE static inline Vec2ccpsub (const vec2& v1, const vec2& v2) { return v1 - v2;} /** returns point multiplied by given factor. @return Vec2 @since v0.7.2 @deprecated please use vec2::*, for example: v1 * v2 */cc_deprecated_attribute static inline vec2ccpmult (const vec2& v, Const float s) { return v * s;} /** calculates midpoint between two points. @return Vec2 @since v0.7.2 @deprecated please use it like (v1 + v2) / 2.0f */cc_deprecated_attribute Static inline vec2ccpmidpoint (CONST&NBSP;VEC2&&NBSP;V1,&NBSP;CONST&NBSP;VEC2&&NBSP;V2) { return v1.getmidpoint (v2);} /** calculates dot product of two points. @return float @since v0.7.2 */cc_deprecated_attribute static inline floatccpdot (const Vec2& &NBSP;V1,&NBSP;CONST&NBSP;VEC2&&NBSP;V2) { return v1.dot (v2);} /** calculates cross product of two points. @return float @since v0.7.2 */cc_deprecated_attribute static inline floatccpcross (const Vec2& &NBSP;V1,&NBSP;CONST&NBSP;VEC2&&NBSP;V2) { return v1.cross (v2);} /** calculates perpendicular of v, rotated 90 degrees Counter-clockwise -- cross (V, perp (v)) >= 0 @return Vec2 @since v0.7.2 */cc_deprecated_attribute static inline vec2ccpperp (CONST&NBSP;VEC2&&NBSP;V) { return v.getperp ();} /** calculates perpendicular of v, rotated 90 degrees clockwise - - cross (V, rperp (v)) <= 0 @return Vec2 @since v0.7.2 */cc_ Deprecated_attribute static inline vec2ccprperp (CONST&NBSP;VEC2&&NBSP;V) { return v.getrperp ();} /** calculates the projection of v1 over v2. @return vec2 @ Since v0.7.2 */cc_deprecated_attribute static inline vec2ccpproject (CONST&NBSP;VEC2 &&NBSP;V1,&NBSP;CONST&NBSP;VEC2&&NBSP;V2) { return v1.project (v2);} /** rotates two points. @return Vec2 @since v0.7.2 */cc_deprecated_ Attribute static inline vec2ccprotate (CONST&NBSP;VEC2&&NBSP;V1,&NBSP;CONST&NBSP;VEC2&&NBSP;V2) { return v1.rotate (v2);} /** unrotates two points. @return Vec2 @since v0.7.2 */cc_deprecated_ Attribute static inline vec2ccpunrotate (const vec2& v1, const vec2& &NBSP;V2) { return v1.unrotate (v2);} /** calculates the square length of a vec2 (not calling sqrt () ) @return float @since v0.7.2 */CC_DEPRECATED_ATTRIBUTE static INLINE&NBSP;FLOATCCPLENGTHSQ (const vec2& v) { return v.getlengthsq ();} /** calculates the square distance between two points (not CALLING&NBSP;SQRT () ) @return float @since v1.1 */CC_DEPRECATED_ATTRIBUTE Static inline floatccpdistancesq (const vec2 p1, const VEC2&NBSP;P2) { return (P1&NBSP;-&NBSP;P2). GETLENGTHSQ (); /** calculates distance between point an origin @return float @ Since v0.7.2 */cc_deprecated_attribute static inline float ccplength (const VEC2&&NBSP;V) { return v.getlength ();} /** calculates the distance between two points @return float @ Since v0.7.2 */cc_deprecated_attribute static inline float ccpdistance (const &NBSP;VEC2&&NBSP;V1,&NBSP;CONST&NBSP;VEC2&&NBSP;V2) { return v1.getdistance (v2);} /** returns point multiplied to a length of 1. @return &NBSP;VEC2 @since v0.7.2 */cc_deprecated_attribute static inline vec2 ccpnormalize ( CONST&NBSP;VEC2&&NBSP;V) { return v.getnormalized ();} /** converts radians to a normalized vector. Converts radians to normalized vectors. @return Vec2 @since v0.7.2 */CC_DEPRECATED_ATTRIBUTE static inline Vec2 ccpforangle (const float a) { return vec2::forangle (a);} /** converts a vector to radians. Convert vectors to radians. @return float @since v0.7.2 */CC_DEPRECATED_ATTRIBUTE static inline Float ccptoangle (const vec2& v) { return v.getangle ();} /** clamp a point between from and to. @since &NBSP;V0.99.1&NBSP;*/CC_ Deprecated_attribute static inline vec2 ccpclamp (Const vec2& p, const vec2& from, const vec2& to) { return P.getclamppoint (from, to);} /** quickly convert size to a vec2 @since &NBSp;v0.99.1 */cc_deprecated_attribute static inline vec2 ccpfromsize (const Size & s) {&NBSP;&NBSP;&NBSP;&NBSP;RETURN&NBSP;VEC2 (s);} /** run a math operation function on each point component * absf, fllorf, ceilf, roundf * any function that has the signature: float func (float); * for example: let ' s try to Take the floor of x,y * ccpcompop (P,floorf); @since v0.99.1 */cc_ Deprecated_attribute static inline vec2 ccpcompop (const vec2& p, float (*opfunc) (float)) { return p.compop (opfunc);} /** linear interpolation between two points a and b @returns alpha == 0 ? a alpha == 1 ? b otherwise a Value between a. b @since v0.99.1 */cc_deprecated_attribute static inline vec2 ccplerp (const vec2& a, const vec2& b, float alpha) { Return a.lerp (B, alpha);} /** @returns if points have fuzzy equality which means equal with some degree of variance. @since v0.99.1 */cc_deprecated_ Attribute static inline bool ccpfuzzyequal (const vec2& a, const Vec2& b, float variance) { return a.fuzzyequals (b, variance );} /** multiplies a and b components, a.x*b.x, a.y*b.y @returns a component-wise multiplication @since v0.99.1 */cc_deprecated_attribute static inline vec2 ccpcompmult (Const vec2& a, const&NBSP;VEC2&&NBSP;B) {&NBSP;&NBSP;&NBSP;&NBSP;RETURN&NBSP;VEC2 (a.x * b.x, a.y * b.y );} /** @returns the signed angle in radians between two vector directions @since v0.99.1 */CC_DEPRECATED_ATTRIBUTE static inline float Ccpanglesigned (const vec2& a, const vec2& b) { return a.getangle (b);} /** @returns the angle in radians between two vector directions @since v0.99.1 */cc_deprecated_attribute static inline float ccpangle ( CONST&NBSP;VEC2&&NBSP;A,&NBSP;CONST&NBSP;VEC2&&NBSP;B) { return a.getangle ( b);} /** 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 */cc_deprecated_attribute static inline vec2 ccprotatebyangle (const Vec2& v, const vec2& pivot, float angle) { return V.rotatebyangle (Pivot, angle);} /** a general line-line intersection test @param p1 is the startpoint for the first line p1 = (P1&NBSP;-&NBSP;P2) @param p2 is the endpoint for the first line P1 = (P1&NBSP;-&NBSP;P2) @param p3 is the startpoint for the second line p2 = (P3&NBSP;-&NBSP;P4) @param p4 is the endpoint for the second line p2 = (P3&NBSP;-&NBSP;P4) @param s is the range for a hitpoint in p1 (pa = p1 + s* (P2&NBSP;-&NBSP;P1)) @ param t is the range for a hitpoint in p3 (PA&NBSP;=&NBSP;P2 + t* (P4&NBSP;-&NBSP;P3)) @return bool indicating successful intersection of a line note that to truly test intersection for Segments we have to make sure that s & t lie within [0..1] and for rays, make sure s & t > 0 the hit point is p3 + t * ( P4&NBSP;-&NBSP;P3); the hit point also is p1 + s * (P2&NBSP;-&NBSP;P1); @since v0.99.1 */CC_DEPRECATED_ATTRIBUTE static inline bool Ccplineintersect (const vec2& p1, const vec2& p2, &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;CONST&NBSP;VEC2&&NBSP;P3, const Vec2& p4, float *s, float *t) { return vec2:: Islineintersect (p1, p2, p3,&NBSP;P4,&NBSP;S,&NBSP;T);} /* ccpsegmentintersect returns true if segment a-b intersects with segment C-D @since v1.0.0 */CC_DEPRECATED_ATTRIBUTE static inline Bool ccpsegmentintersect (const vec2& a, const vec2& b, const Vec2& c, const vec2& d) { return vec2:: Issegmentintersect (a, b, c, d);} /* ccpintersectpoint returns the intersection point of line a-b, c-d @since v1.0.0 */CC_DEPRECATED_ATTRIBUTE static inline Vec2 Ccpintersectpoint (const vec2& a, const vec2& b, const vec2& c, const vec2& d) { return vec2::getintersectpoint (A, &NBSP;B,&NBSP;C,&NBSP;D);} Cc_deprecated_attribute inline vec2 ccpointmake (FloAt x, float y) { return vec2 (x, y);} Cc_deprecated_attribute inline size ccsizemake (float width, float height) { return size (width, height);} Cc_deprecated_attribute inline rect ccrectmake (float x, float y, float width, float height) { return rect (x, y, width, height);}
This article is from "A grain of sand in the Wind" blog, please be sure to keep this source http://libinqi456.blog.51cto.com/4819343/1603788
Cocos2d Self-band algorithm