cocos2d 自带算法

前端之家收集整理的这篇文章主要介绍了cocos2d 自带算法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
/**@defCCRANDOM_MINUS1_1
returnsarandomfloatbetween-1and1
返回一个随机漂浮在-1和1之间的随机数*/
#defineCCRANDOM_MINUS1_1()((2.0f*((float)rand()/RAND_MAX))-1.0f)
/**@defCCRANDOM_0_1
returnsarandomfloatbetween0and1
返回一个随机漂浮在0和1之间的随机
*/
#defineCCRANDOM_0_1()((float)rand()/RAND_MAX)
/**@defCC_DEGREES_TO_RADIANS
convertsdegreestoradians
将度转换为弧度
*/
#defineCC_DEGREES_TO_RADIANS(__ANGLE__)((__ANGLE__)*0.01745329252f)//PI/180
/**@defCC_RADIANS_TO_DEGREES
convertsradianstodegrees
将弧度转换成度
*/
#defineCC_RADIANS_TO_DEGREES(__ANGLE__)((__ANGLE__)*57.29577951f)//PI*180
*************************************************************************************
/**HelpermacrothatcreatesaVec2
@returnVec2
@sincev0.7.2
*/
CC_DEPRECATED_ATTRIBUTE inline Vec2ccp( float x, y)
{
return Vec2(x,y);
}
/**Returnsoppositeofpoint.
@returnVec2
@sincev0.7.2
@deprecatedpleaseuseVec2::-,forexample:-v1
*/
static Vec2
ccpNeg( const Vec2&v)
{
-v;
}
/**Calculatessumoftwopoints.
@returnVec2
@sincev0.7.2
@deprecatedpleaseuseVec2::+,forexample:v1+v2
*/
Vec2
ccpAdd( Vec2&v1, Vec2&v2)
{
v1+v2;
}
/**Calculatesdifferenceoftwopoints.
@returnVec2
@sincev0.7.2
*/
Vec2
ccpSub( Vec2&v2)
{
v1-v2;
}
/**Returnspointmultipliedbygivenfactor.
@returnVec2
@sincev0.7.2
@deprecatedpleaseuseVec2::*,forexample:v1*v2
*/
Vec2
ccpMult( Vec2&v,153)!important">const s)
{
v*s;
}
/**Calculatesmidpointbetweentwopoints.
@returnVec2
@sincev0.7.2
@deprecatedpleaseuseitlike(v1+v2)/2.0f
*/
Vec2
ccpMidpoint( Vec2&v2)
{
v1.getMidpoint(v2);
}
/**Calculatesdotproductoftwopoints.
@returnfloat
@sincev0.7.2
*/
@H_792_301@inline float
ccpDot( Vec2&v2)
{
v1.dot(v2);
}
/**Calculatescrossproductoftwopoints.
@returnfloat
@sincev0.7.2
*/
float
ccpCross( Vec2&v2)
{
v1.cross(v2);
}
/**Calculatesperpendicularofv,rotated90degreescounter-clockwise--cross(v,perp(v))>=0
@returnVec2
@sincev0.7.2
*/
Vec2
ccpPerp( Vec2&v)
{
v.getPerp();
}
@returnVec2
@sincev0.7.2
*/
Vec2
ccpRPerp( Vec2&v)
@H_888_403@{
v.getRPerp();
}
/**Calculatestheprojectionofv1overv2.
@returnVec2
@sincev0.7.2
*/
Vec2
ccpProject( Vec2&v2)
{
v1.project(v2);
}
/**Rotatestwopoints.
@returnVec2
@sincev0.7.2
*/
Vec2
ccpRotate( Vec2&v2)
{
v1.rotate(v2);
}
/**Unrotatestwopoints.
@returnVec2
@sincev0.7.2
*/
Vec2
ccpunrotate( Vec2&v2)
{
v1.unrotate(v2);
@H_574_502@}
/**CalculatesthesquarelengthofaVec2(notcallingsqrt())
@returnfloat
@sincev0.7.2
*/
float
ccpLengthSQ( Vec2&v)
{
v.getLengthSq();
}
/**Calculatesthesquaredistancebetweentwopoints(notcallingsqrt())
@returnfloat
@sincev1.1
*/
float
ccpDistanceSQ( Vec2p1,monospace!important; font-size:1em!important; min-height:inherit!important; color:black!important">Vec2p2)
{
(p1-p2).getLengthSq();
}
/**Calculatesdistancebetweenpointanorigin
@returnfloat
@sincev0.7.2
*/
ccpLength( Vec2&v)
{
v.getLength();
}
/**Calculatesthedistancebetweentwopoints
@returnfloat
@sincev0.7.2
*/
ccpDistance( Vec2&v2)
{
v1.getDistance(v2);
}
/**Returnspointmultipliedtoalengthof1.
@returnVec2
@sincev0.7.2
*/
Vec2ccpNormalize( Vec2&v)
{
v.getNormalized();
}
/**Convertsradianstoanormalizedvector.
将弧度转换为归一化向量。
@returnVec2
@sincev0.7.2
*/
Vec2ccpForAngle( a)
{
Vec2::forAngle(a);
}
/**Convertsavectortoradians.
向量转换为弧度。
@returnfloat
@sincev0.7.2
*/
ccpToAngle( Vec2&v)
{
v.getAngle();
}
/**Clampapointbetweenfromandto.
@sincev0.99.1
*/
Vec2ccpClamp( Vec2&p,monospace!important; font-size:1em!important; min-height:inherit!important; color:black!important">Vec2&from,monospace!important; font-size:1em!important; min-height:inherit!important; color:black!important">Vec2&to)
{
p.getClampPoint(from,to);
}
/**QuicklyconvertSizetoaVec2
@sincev0.99.1
*/
Vec2ccpFromSize( Size&s)
{
Vec2(s);
}
/**Runamathoperationfunctiononeachpointcomponent
*absf,fllorf,ceilf,roundf
*anyfunctionthathasthesignature:floatfunc(float);
*Forexample:let'strytotakethefloorofx,y
*ccpCompOp(p,floorf);
@sincev0.99.1
*/
Vec2ccpCompOp( (*opFunc)( ))
{
p.compOp(opFunc);
}
/**LinearInterpolationbetweentwopointsaandb
@returns
alpha==0?a
alpha==1?b
otherwiseavaluebetweena..b
@sincev0.99.1
*/
Vec2ccpLerp( Vec2&a,monospace!important; font-size:1em!important; min-height:inherit!important; color:black!important">Vec2&b,monospace!important; font-size:1em!important; min-height:inherit!important; color:black!important">alpha)
{
a.lerp(b,alpha);
}
/**@returnsifpointshavefuzzyequalitywhichmeansequalwithsomedegreeofvariance.
@sincev0.99.1
*/
bool ccpFuzzyEqual( variance)
{
@H_404_868@a.fuzzyEquals(b,variance);
}
/**Multipliesaandbcomponents,a.x*b.x,a.y*b.y
@returnsacomponent-wisemultiplication
@sincev0.99.1
*/
Vec2ccpCompMult( Vec2&b)
{
Vec2(a.x*b.x,a.y*b.y);
}
/**@returnsthesignedangleinradiansbetweentwovectordirections
@sincev0.99.1
*/
ccpAngleSigned( Vec2&b)
{
a.getAngle(b);
}
/**@returnstheangleinradiansbetweentwovectordirections
@sincev0.99.1
*/
ccpAngle( Vec2&b)
{
a.getAngle(b);
}
/**Rotatesapointcounterclockwisebytheanglearoundapivot
@paramvisthepointtorotate
@parampivotisthepivot,naturally
@paramangleistheangleofrotationcwinradians
@returnstherotatedpoint
@sincev0.99.1
*/
Vec2ccpRotateByAngle( Vec2&pivot,monospace!important; font-size:1em!important; min-height:inherit!important; color:black!important">angle)
{
v.rotateByAngle(pivot,angle);
}
/**Ageneralline-lineintersectiontest
@paramp1
isthestartpointforthefirstlineP1=(p1-p2)
@paramp2
istheendpointforthefirstlineP1=(p1-p2)
@paramp3
isthestartpointforthesecondlineP2=(p3-p4)
@paramp4
istheendpointforthesecondlineP2=(p3-p4)
@params
istherangeforahitpointinP1(pa=p1+s*(p2-p1))
@paramt
istherangeforahitpointinP3(pa=p2+t*(p4-p3))
@returnbool
indicatingsuccessfulintersectionofaline
notethattotrulytestintersectionforsegmentswehavetomake
surethats&tliewithin[0..1]andforrays,makesures&t>0
thehitpointisp3+t*(p4-p3);
thehitpointalsoisp1+s*(p2-p1);
@sincev0.99.1
*/
ccpLineIntersect( Vec2&p1,monospace!important; font-size:1em!important; min-height:inherit!important; color:black!important">Vec2&p2,
Vec2&p3,monospace!important; font-size:1em!important; min-height:inherit!important; color:black!important">Vec2&p4,
*s,monospace!important; font-size:1em!important; min-height:inherit!important; color:black!important">*t)
{
Vec2::isLineIntersect(p1,p2,p3,p4,s,t);
}
/*
ccpSegmentIntersectreturnstrueifSegmentA-BintersectswithsegmentC-D
@sincev1.0.0
*/
CC_DEPRECATED_ATTRIBUTE
ccpSegmentIntersect( Vec2&A,153)!important">const
Vec2&B,monospace!important; font-size:1em!important; min-height:inherit!important; color:black!important">Vec2&C,monospace!important; font-size:1em!important; min-height:inherit!important; color:black!important">Vec2&D)
{
Vec2::isSegmentIntersect(A,B,C,D);
}
/*
ccpIntersectPointreturnstheintersectionpointoflineA-B,C-D
@sincev1.0.0
*/
CC_DEPRECATED_ATTRIBUTE
Vec2ccpIntersectPoint( Vec2&
B,monospace!important; font-size:1em!important; min-height:inherit!important; color:black!important">Vec2&D)
{
Vec2::getIntersectPoint(A,D);
}
Vec2CCPointMake( y)
{
}
SizeCCSizeMake( width,monospace!important; font-size:1em!important; min-height:inherit!important; color:black!important">height)
{
Size(width,height);
}
RectCCRectMake( y,monospace!important; font-size:1em!important; min-height:inherit!important; color:black!important">height)
{
Rect(x,y,width,height);
}
原文链接:https://www.f2er.com/cocos2dx/342815.html

猜你在找的Cocos2d-x相关文章