00001 #include <stdint.h>
00002
00003 #ifdef __APPLE__
00004 #include "TargetConditionals.h"
00005 #endif
00006
00007 #if (TARGET_OS_IPHONE == 1) || (TARGET_OS_MAC == 1) && (!defined CP_USE_CGPOINTS)
00008 #define CP_USE_CGPOINTS 1
00009 #endif
00010
00011 #if CP_USE_CGPOINTS == 1
00012 #if TARGET_OS_IPHONE
00013 #import <CoreGraphics/CGGeometry.h>
00014 #elif TARGET_OS_MAC
00015 #include <ApplicationServices/ApplicationServices.h>
00016 #endif
00017
00018 #if defined(__LP64__) && __LP64__
00019 #define CP_USE_DOUBLES 1
00020 #else
00021 #define CP_USE_DOUBLES 0
00022 #endif
00023 #endif
00024
00025 #ifndef CP_USE_DOUBLES
00026
00027 #define CP_USE_DOUBLES 1
00028 #endif
00029
00033
00034 #if CP_USE_DOUBLES
00035
00036
00037 typedef double cpFloat;
00038 #define cpfsqrt sqrt
00039 #define cpfsin sin
00040 #define cpfcos cos
00041 #define cpfacos acos
00042 #define cpfatan2 atan2
00043 #define cpfmod fmod
00044 #define cpfexp exp
00045 #define cpfpow pow
00046 #define cpffloor floor
00047 #define cpfceil ceil
00048 #else
00049 typedef float cpFloat;
00050 #define cpfsqrt sqrtf
00051 #define cpfsin sinf
00052 #define cpfcos cosf
00053 #define cpfacos acosf
00054 #define cpfatan2 atan2f
00055 #define cpfmod fmodf
00056 #define cpfexp expf
00057 #define cpfpow powf
00058 #define cpffloor floorf
00059 #define cpfceil ceilf
00060 #endif
00061
00062 #ifndef INFINITY
00063 #ifdef _MSC_VER
00064 union MSVC_EVIL_FLOAT_HACK
00065 {
00066 unsigned __int8 Bytes[4];
00067 float Value;
00068 };
00069 static union MSVC_EVIL_FLOAT_HACK INFINITY_HACK = {{0x00, 0x00, 0x80, 0x7F}};
00070 #define INFINITY (INFINITY_HACK.Value)
00071 #endif
00072
00073 #ifdef __GNUC__
00074 #define INFINITY (__builtin_inf())
00075 #endif
00076
00077 #ifndef INFINITY
00078 #define INFINITY (1e1000)
00079 #endif
00080 #endif
00081
00082 #ifndef M_PI
00083 #define M_PI 3.14159265358979323846264338327950288
00084 #endif
00085
00086 #ifndef M_E
00087 #define M_E 2.71828182845904523536028747135266250
00088 #endif
00089
00090
00092 static inline cpFloat cpfmax(cpFloat a, cpFloat b)
00093 {
00094 return (a > b) ? a : b;
00095 }
00096
00098 static inline cpFloat cpfmin(cpFloat a, cpFloat b)
00099 {
00100 return (a < b) ? a : b;
00101 }
00102
00104 static inline cpFloat cpfabs(cpFloat f)
00105 {
00106 return (f < 0) ? -f : f;
00107 }
00108
00110 static inline cpFloat cpfclamp(cpFloat f, cpFloat min, cpFloat max)
00111 {
00112 return cpfmin(cpfmax(f, min), max);
00113 }
00114
00116 static inline cpFloat cpfclamp01(cpFloat f)
00117 {
00118 return cpfmax(0.0f, cpfmin(f, 1.0f));
00119 }
00120
00121
00122
00124 static inline cpFloat cpflerp(cpFloat f1, cpFloat f2, cpFloat t)
00125 {
00126 return f1*(1.0f - t) + f2*t;
00127 }
00128
00130 static inline cpFloat cpflerpconst(cpFloat f1, cpFloat f2, cpFloat d)
00131 {
00132 return f1 + cpfclamp(f2 - f1, -d, d);
00133 }
00134
00136 typedef uintptr_t cpHashValue;
00137
00138
00140 #ifdef CP_BOOL_TYPE
00141 typedef CP_BOOL_TYPE cpBool;
00142 #else
00143 typedef int cpBool;
00144 #endif
00145
00146 #ifndef cpTrue
00147
00148 #define cpTrue 1
00149 #endif
00150
00151 #ifndef cpFalse
00152
00153 #define cpFalse 0
00154 #endif
00155
00156 #ifdef CP_DATA_POINTER_TYPE
00157 typedef CP_DATA_POINTER_TYPE cpDataPointer;
00158 #else
00159
00160 typedef void * cpDataPointer;
00161 #endif
00162
00163 #ifdef CP_COLLISION_TYPE_TYPE
00164 typedef CP_COLLISION_TYPE_TYPE cpCollisionType;
00165 #else
00166
00167 typedef uintptr_t cpCollisionType;
00168 #endif
00169
00170 #ifdef CP_GROUP_TYPE
00171 typedef CP_GROUP_TYPE cpGroup;
00172 #else
00173
00174 typedef uintptr_t cpGroup;
00175 #endif
00176
00177 #ifdef CP_LAYERS_TYPE
00178 typedef CP_LAYERS_TYPE cpLayers;
00179 #else
00180
00181 typedef unsigned int cpLayers;
00182 #endif
00183
00184 #ifdef CP_TIMESTAMP_TYPE
00185 typedef CP_TIMESTAMP_TYPE cpTimestamp;
00186 #else
00187
00188 typedef unsigned int cpTimestamp;
00189 #endif
00190
00191 #ifndef CP_NO_GROUP
00192
00193 #define CP_NO_GROUP ((cpGroup)0)
00194 #endif
00195
00196 #ifndef CP_ALL_LAYERS
00197
00198 #define CP_ALL_LAYERS (~(cpLayers)0)
00199 #endif
00200
00201
00202
00203
00204 #if CP_USE_CGPOINTS
00205 typedef CGPoint cpVect;
00206 #else
00207
00208
00209 typedef struct cpVect{cpFloat x,y;} cpVect;
00210 #endif
00211
00212 typedef struct cpMat2x2 {
00213
00214 cpFloat a, b, c, d;
00215 } cpMat2x2;