我希望能够做到这一点:
vec2 pos(1,5);
myActor.position = [Coord positionFrom: pos ];
使用我的结构:
typedef float32 float;
struct vec2 {
vec2(float32 xx, float32 yy) {
x = xx;
y = yy;
}
float32 x, y;
};
坐标.h
@interface Coord : NSObject {
}
+(CGPoint) positionFrom: (vec2) pos;
+(CGPoint) positionFromAngle: (float32) angle;
坐标.mm
#import "Coord.h"
@implementation Coord
+(CGPoint) positionFrom:(vec2) pos {
return CGPointMake( pos.x * 32, pos.y * 32);
}
+(CGPoint) positionFromAngle:(float32) angle {
return CGPointMake( cos(angle) * 32, cos(angle) * 32);
}
@end
但是我得到了这些错误(在 Coord.h 中的 positionFrom 行):
Expected ')' before 'vec2'
Expected ')' before 'float32'