cocos2d for iPhone  2.0.0
2D game engine for iOS and OS X
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Defines
Defines | Functions
/Users/rquesada/progs/cocos2d-iphone/cocos2d/Support/CGPointExtension.h File Reference
#import "ccMacros.h"
#import <math.h>
#import <objc/objc.h>
Include dependency graph for CGPointExtension.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define ccp(__X__, __Y__)   CGPointMake(__X__,__Y__)

Functions

static CGPoint ccpNeg (const CGPoint v)
static CGPoint ccpAdd (const CGPoint v1, const CGPoint v2)
static CGPoint ccpSub (const CGPoint v1, const CGPoint v2)
static CGPoint ccpMult (const CGPoint v, const CGFloat s)
static CGPoint ccpMidpoint (const CGPoint v1, const CGPoint v2)
static CGFloat ccpDot (const CGPoint v1, const CGPoint v2)
static CGFloat ccpCross (const CGPoint v1, const CGPoint v2)
static CGPoint ccpPerp (const CGPoint v)
static CGPoint ccpRPerp (const CGPoint v)
static CGPoint ccpProject (const CGPoint v1, const CGPoint v2)
static CGPoint ccpRotate (const CGPoint v1, const CGPoint v2)
static CGPoint ccpUnrotate (const CGPoint v1, const CGPoint v2)
static CGFloat ccpLengthSQ (const CGPoint v)
static CGFloat ccpDistanceSQ (const CGPoint p1, const CGPoint p2)
CGFloat ccpLength (const CGPoint v)
CGFloat ccpDistance (const CGPoint v1, const CGPoint v2)
CGPoint ccpNormalize (const CGPoint v)
CGPoint ccpForAngle (const CGFloat a)
CGFloat ccpToAngle (const CGPoint v)
float clampf (float value, float min_inclusive, float max_inclusive)
CGPoint ccpClamp (CGPoint p, CGPoint from, CGPoint to)
CGPoint ccpFromSize (CGSize s)
CGPoint ccpCompOp (CGPoint p, float(*opFunc)(float))
CGPoint ccpLerp (CGPoint a, CGPoint b, float alpha)
BOOL ccpFuzzyEqual (CGPoint a, CGPoint b, float variance)
CGPoint ccpCompMult (CGPoint a, CGPoint b)
float ccpAngleSigned (CGPoint a, CGPoint b)
float ccpAngle (CGPoint a, CGPoint b)
CGPoint ccpRotateByAngle (CGPoint v, CGPoint pivot, float angle)
BOOL ccpLineIntersect (CGPoint p1, CGPoint p2, CGPoint p3, CGPoint p4, float *s, float *t)

Detailed Description

CGPoint extensions based on Chipmunk's cpVect file. These extensions work both with CGPoint and cpVect.

The "ccp" prefix means: "CoCos2d Point"

Examples:

Definition in file CGPointExtension.h.


Define Documentation

#define ccp (   __X__,
  __Y__ 
)    CGPointMake(__X__,__Y__)

Helper macro that creates a CGPoint

Returns:
CGPoint
Since:
v0.7.2

Definition at line 66 of file CGPointExtension.h.


Function Documentation

static CGPoint ccpAdd ( const CGPoint  v1,
const CGPoint  v2 
) [inline, static]

Calculates sum of two points.

Returns:
CGPoint
Since:
v0.7.2

Definition at line 84 of file CGPointExtension.h.

float ccpAngle ( CGPoint  a,
CGPoint  b 
)
Returns:
the angle in radians between two vector directions
Since:
v0.99.1
float ccpAngleSigned ( CGPoint  a,
CGPoint  b 
)
Returns:
the signed angle in radians between two vector directions
Since:
v0.99.1
CGPoint ccpClamp ( CGPoint  p,
CGPoint  from,
CGPoint  to 
)

Clamp a point between from and to.

Since:
v0.99.1
CGPoint ccpCompMult ( CGPoint  a,
CGPoint  b 
)

Multiplies a nd b components, a.x*b.x, a.y*b.y

Returns:
a component-wise multiplication
Since:
v0.99.1
CGPoint ccpCompOp ( CGPoint  p,
float(*)(float)  opFunc 
)

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
static CGFloat ccpCross ( const CGPoint  v1,
const CGPoint  v2 
) [inline, static]

Calculates cross product of two points.

Returns:
CGFloat
Since:
v0.7.2

Definition at line 134 of file CGPointExtension.h.

CGFloat ccpDistance ( const CGPoint  v1,
const CGPoint  v2 
)

Calculates the distance between two points

Returns:
CGFloat
Since:
v0.7.2
static CGFloat ccpDistanceSQ ( const CGPoint  p1,
const CGPoint  p2 
) [inline, static]

Calculates the square distance between two points (not calling sqrt() )

Returns:
CGFloat
Since:
v1.1

Definition at line 204 of file CGPointExtension.h.

static CGFloat ccpDot ( const CGPoint  v1,
const CGPoint  v2 
) [inline, static]

Calculates dot product of two points.

Returns:
CGFloat
Since:
v0.7.2

Definition at line 124 of file CGPointExtension.h.

CGPoint ccpForAngle ( const CGFloat  a)

Converts radians to a normalized vector.

Returns:
CGPoint
Since:
v0.7.2
CGPoint ccpFromSize ( CGSize  s)

Quickly convert CGSize to a CGPoint

Since:
v0.99.1
BOOL ccpFuzzyEqual ( CGPoint  a,
CGPoint  b,
float  variance 
)
Returns:
if points have fuzzy equality which means equal with some degree of variance.
Since:
v0.99.1
CGFloat ccpLength ( const CGPoint  v)

Calculates distance between point an origin

Returns:
CGFloat
Since:
v0.7.2
static CGFloat ccpLengthSQ ( const CGPoint  v) [inline, static]

Calculates the square length of a CGPoint (not calling sqrt() )

Returns:
CGFloat
Since:
v0.7.2

Definition at line 194 of file CGPointExtension.h.

CGPoint ccpLerp ( CGPoint  a,
CGPoint  b,
float  alpha 
)

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
BOOL ccpLineIntersect ( CGPoint  p1,
CGPoint  p2,
CGPoint  p3,
CGPoint  p4,
float *  s,
float *  t 
)

A general line-line intersection test

Parameters:
p1is the startpoint for the first line P1 = (p1 - p2)
p2is the endpoint for the first line P1 = (p1 - p2)
p3is the startpoint for the second line P2 = (p3 - p4)
p4is the endpoint for the second line P2 = (p3 - p4)
sis the range for a hitpoint in P1 (pa = p1 + s*(p2 - p1))
tis the range for a hitpoint in P3 (pa = p2 + t*(p4 - p3))
Returns:
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
static CGPoint ccpMidpoint ( const CGPoint  v1,
const CGPoint  v2 
) [inline, static]

Calculates midpoint between two points.

Returns:
CGPoint
Since:
v0.7.2

Definition at line 114 of file CGPointExtension.h.

static CGPoint ccpMult ( const CGPoint  v,
const CGFloat  s 
) [inline, static]

Returns point multiplied by given factor.

Returns:
CGPoint
Since:
v0.7.2

Definition at line 104 of file CGPointExtension.h.

static CGPoint ccpNeg ( const CGPoint  v) [inline, static]

Returns opposite of point.

Returns:
CGPoint
Since:
v0.7.2

Definition at line 74 of file CGPointExtension.h.

CGPoint ccpNormalize ( const CGPoint  v)

Returns point multiplied to a length of 1.

Returns:
CGPoint
Since:
v0.7.2
static CGPoint ccpPerp ( const CGPoint  v) [inline, static]

Calculates perpendicular of v, rotated 90 degrees counter-clockwise -- cross(v, perp(v)) >= 0

Returns:
CGPoint
Since:
v0.7.2

Definition at line 144 of file CGPointExtension.h.

static CGPoint ccpProject ( const CGPoint  v1,
const CGPoint  v2 
) [inline, static]

Calculates the projection of v1 over v2.

Returns:
CGPoint
Since:
v0.7.2

Definition at line 164 of file CGPointExtension.h.

static CGPoint ccpRotate ( const CGPoint  v1,
const CGPoint  v2 
) [inline, static]

Rotates two points.

Returns:
CGPoint
Since:
v0.7.2

Definition at line 174 of file CGPointExtension.h.

CGPoint ccpRotateByAngle ( CGPoint  v,
CGPoint  pivot,
float  angle 
)

Rotates a point counter clockwise by the angle around a pivot

Parameters:
vis the point to rotate
pivotis the pivot, naturally
angleis the angle of rotation cw in radians
Returns:
the rotated point
Since:
v0.99.1
static CGPoint ccpRPerp ( const CGPoint  v) [inline, static]

Calculates perpendicular of v, rotated 90 degrees clockwise -- cross(v, rperp(v)) <= 0

Returns:
CGPoint
Since:
v0.7.2

Definition at line 154 of file CGPointExtension.h.

static CGPoint ccpSub ( const CGPoint  v1,
const CGPoint  v2 
) [inline, static]

Calculates difference of two points.

Returns:
CGPoint
Since:
v0.7.2

Definition at line 94 of file CGPointExtension.h.

CGFloat ccpToAngle ( const CGPoint  v)

Converts a vector to radians.

Returns:
CGFloat
Since:
v0.7.2
static CGPoint ccpUnrotate ( const CGPoint  v1,
const CGPoint  v2 
) [inline, static]

Unrotates two points.

Returns:
CGPoint
Since:
v0.7.2

Definition at line 184 of file CGPointExtension.h.

float clampf ( float  value,
float  min_inclusive,
float  max_inclusive 
)

Clamp a value between from and to.

Since:
v0.99.1

cocos2d for iPhone API Reference - Generated using Doxygen 1.8.0