cocos2d 自带算法

/** @def CCRANDOM_MINUS1_1
  returns a random float between -1 and 1
返回一个随机漂浮在-1和1之间的随机数 */
#define CCRANDOM_MINUS1_1() ((2.0f*((float)rand()/RAND_MAX))-1.0f)
 
/** @def CCRANDOM_0_1
  returns a random float between 0 and 1
  返回一个随机漂浮在0和1之间的随机数
  */
#define CCRANDOM_0_1() ((float)rand()/RAND_MAX)
 
/** @def CC_DEGREES_TO_RADIANS
  converts degrees to radians
  将度转换为弧度
  */
#define CC_DEGREES_TO_RADIANS(__ANGLE__) ((__ANGLE__) * 0.01745329252f) // PI / 180
 
/** @def CC_RADIANS_TO_DEGREES
  converts 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  inline  Vec2 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  Vec2
ccpNeg( const  Vec2& v)
{
     return  -v;
}
 
/** Calculates sum of two points.
  @return Vec2
  @since v0.7.2
  @deprecated please use Vec2::+, for example: v1 + v2
  */
CC_DEPRECATED_ATTRIBUTE  static  inline  Vec2
ccpAdd( const  Vec2& v1,  const  Vec2& 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  Vec2
ccpSub( 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  Vec2
ccpMult( 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  Vec2
ccpMidpoint( const  Vec2& v1,  const  Vec2& v2)
{
     return  v1.getMidpoint(v2);
}
 
/** Calculates dot product of two points.
  @return float
  @since v0.7.2
  */
CC_DEPRECATED_ATTRIBUTE  static  inline  float
ccpDot( const  Vec2& v1,  const  Vec2& v2)
{
     return  v1.dot(v2);
}
 
/** Calculates cross product of two points.
  @return float
  @since v0.7.2
  */
CC_DEPRECATED_ATTRIBUTE  static  inline  float
ccpCross( const  Vec2& v1,  const  Vec2& 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  Vec2
ccpPerp( const  Vec2& 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  Vec2
ccpRPerp( const  Vec2& v)
{
     return  v.getRPerp();
}
 
/** Calculates the projection of v1 over v2.
  @return Vec2
  @since v0.7.2
  */
CC_DEPRECATED_ATTRIBUTE  static  inline  Vec2
ccpProject( const  Vec2& v1,  const  Vec2& v2)
{
     return  v1.project(v2);
}
 
/** Rotates two points.
  @return Vec2
  @since v0.7.2
  */
CC_DEPRECATED_ATTRIBUTE  static  inline  Vec2
ccpRotate( const  Vec2& v1,  const  Vec2& v2)
{
     return  v1.rotate(v2);
}
 
/** Unrotates two points.
  @return Vec2
  @since v0.7.2
  */
CC_DEPRECATED_ATTRIBUTE  static  inline  Vec2
ccpUnrotate( const  Vec2& v1,  const  Vec2& 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  float
ccpLengthSQ( const  Vec2& v)
{
     return  v.getLengthSq();
}
 
 
/** Calculates the square distance between two points (not calling sqrt() )
  @return float
  @since v1.1
  */
CC_DEPRECATED_ATTRIBUTE  static  inline  float
ccpDistanceSQ( const  Vec2 p1,  const  Vec2 p2)
{
     return  (p1 - p2).getLengthSq();
}
 
 
/** Calculates distance between point an origin
  @return float
  @since v0.7.2
  */
CC_DEPRECATED_ATTRIBUTE  static  inline  float  ccpLength( const  Vec2& v)
{
     return  v.getLength();
}
 
/** Calculates the distance between two points
  @return float
  @since v0.7.2
  */
CC_DEPRECATED_ATTRIBUTE  static  inline  float  ccpDistance( const  Vec2& v1,  const  Vec2& v2)
{
     return  v1.getDistance(v2);
}
 
/** Returns point multiplied to a length of 1.
  @return Vec2
  @since v0.7.2
  */
CC_DEPRECATED_ATTRIBUTE  static  inline  Vec2 ccpNormalize( const  Vec2& v)
{
     return  v.getNormalized();
}
 
/** Converts radians to a normalized vector.
将弧度转换为归一化向量。
  @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.
向量转换为弧度。
  @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 v0.99.1
  */
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 v0.99.1
  */
CC_DEPRECATED_ATTRIBUTE  static  inline  Vec2 ccpFromSize( const  Size& s)
{
     return  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  Vec2& b)
{
     return  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  Vec2& a,  const  Vec2& 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 - p2)
  @param p2
  is the endpoint for the first line P1 = (p1 - p2)
  @param p3
  is the startpoint for the second line P2 = (p3 - p4)
  @param p4
  is the endpoint for the second line P2 = (p3 - p4)
  @param s
  is the range for a hitpoint in P1 (pa = p1 + s*(p2 - p1))
  @param t
  is the range for a hitpoint in P3 (pa = p2 + t*(p4 - 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 - p3);
  the hit point also is    p1 + s * (p2 - p1);
  @since v0.99.1
  */
CC_DEPRECATED_ATTRIBUTE  static  inline  bool  ccpLineIntersect( const  Vec2& p1,  const  Vec2& p2,
                                                      const  Vec2& p3,  const  Vec2& p4,
                                                      float  *s,  float  *t)
{
     return  Vec2::isLineIntersect(p1, p2, p3, p4, s, 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, B, C, 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);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值