cpVect vs. CGPoint (Chipmunk vs. CoreGraphics)

Chipmunk has a type called cpVect that is used to define a vector.
The above mentioned structure is defined as:

1
2
3
typedef struct cpVect{
    cpFloat x,y;
} cpVect;

On the other hand, CoreGraphics has a similar type called CGPoint that is defined as:

1
2
3
4
5
struct CGPoint {
    CGFloat x;
    CGFloat y;
};
typedef struct CGPoint CGPoint;

These 2 types has the same attributes (they are identical) but they aren’t interchangeable because they are different types.
You can’t add a CGPoint with a cpVect, neither you can’t test whether or not a cpVect is inside a CGRect, etc.

Since cocos2d v0.7.1 you will be able to mix them and use them interchangeably. The solution was a simple hack:

1
2
3
4
5
6
7
// file cpVect.h
 
#import <CoreGraphics/CGGeometry.h>
#define cpVect CGPoint
//typedef struct cpVect{
//     cpFloat x,y;
//} cpVect;

1 Response to “cpVect vs. CGPoint (Chipmunk vs. CoreGraphics)”


Leave a Reply




Social Widgets powered by AB-WebLog.com.