Changeset 1175


Ignore:
Timestamp:
Mar 27, 2012, 1:43:15 AM (8 years ago)
Author:
sam
Message:

math: move cross product out of the .cpp file.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lol/math/vector.h

    r1163 r1175  
    485485
    486486    DECLARE_MEMBER_OPS(Vec3)
    487 
    488     template<typename U>
    489     friend Vec3<U> cross(Vec3<U>, Vec3<U>);
    490487
    491488#if !defined __ANDROID__
     
    10781075    }
    10791076
     1077#define DECLARE_VEC_3_COERCE_OPS(tname, tprefix, t1, t2, tf) \
     1078    tprefix \
     1079    inline tname<tf> cross(tname<t1> const &a, tname<t2> const &b) \
     1080    { \
     1081        return tname<tf>((tf)(a.y * b.z) - (tf)(a.z * b.y), \
     1082                         (tf)(a.z * b.x) - (tf)(a.x * b.z), \
     1083                         (tf)(a.x * b.y) - (tf)(a.y * b.x)); \
     1084    }
     1085
    10801086#define DECLARE_BINARY_OPS(tname, tprefix, type) \
    10811087    DECLARE_BINARY_COERCE_OPS(tname, tprefix, type, type, type) \
     
    11111117    DECLARE_VECTOR_OPS(tname, static, type) \
    11121118
    1113 #define DECLARE_ALL_VECTOR_OPS(tname) \
    1114     DECLARE_ALL_VECTOR_OPS_INNER(tname, half) \
    1115     DECLARE_ALL_VECTOR_OPS_INNER(tname, float) \
    1116     DECLARE_ALL_VECTOR_OPS_INNER(tname, double) \
    1117     DECLARE_ALL_VECTOR_OPS_INNER(tname, int8_t) \
    1118     DECLARE_ALL_VECTOR_OPS_INNER(tname, uint8_t) \
    1119     DECLARE_ALL_VECTOR_OPS_INNER(tname, int16_t) \
    1120     DECLARE_ALL_VECTOR_OPS_INNER(tname, uint16_t) \
    1121     DECLARE_ALL_VECTOR_OPS_INNER(tname, int32_t) \
    1122     DECLARE_ALL_VECTOR_OPS_INNER(tname, uint32_t) \
    1123     DECLARE_ALL_VECTOR_OPS_INNER(tname, int64_t) \
    1124     DECLARE_ALL_VECTOR_OPS_INNER(tname, uint64_t)
     1119#define DECLARE_ALL_VECTOR_OPS(type) \
     1120    DECLARE_ALL_VECTOR_OPS_INNER(Vec2, type) \
     1121    DECLARE_ALL_VECTOR_OPS_INNER(Vec3, type) \
     1122    DECLARE_ALL_VECTOR_OPS_INNER(Vec4, type) \
     1123    \
     1124    DECLARE_VEC_3_COERCE_OPS(Vec3, static, type, type, type)
    11251125
    11261126#define DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, tlow, thigh) \
     
    11311131    DECLARE_VECTOR_COERCE_OPS(tname, static, thigh, tlow, thigh)
    11321132
    1133 #define DECLARE_ALL_VECTOR_COERCE_OPS(tname) \
    1134     /* Apply the same coercion rules as in the C++ standard. However,   */ \
    1135     /* instead of promoting int8_t etc. to int, we apply our own rules. */ \
    1136     /* FIXME: "half" and "real" are deactivated for now, because we do  */ \
    1137     /* not implement all combinations of operators for these types yet. */ \
    1138     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int8_t, uint8_t) \
    1139     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int8_t, int16_t) \
    1140     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int8_t, uint16_t) \
    1141     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int8_t, int32_t) \
    1142     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int8_t, uint32_t) \
    1143     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int8_t, int64_t) \
    1144     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int8_t, uint64_t) \
    1145     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int8_t, half) */ \
    1146     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int8_t, float) \
    1147     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int8_t, double) \
    1148     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int8_t, long double) \
    1149     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int8_t, real) */ \
    1150     \
    1151     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint8_t, int16_t) \
    1152     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint8_t, uint16_t) \
    1153     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint8_t, int32_t) \
    1154     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint8_t, uint32_t) \
    1155     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint8_t, int64_t) \
    1156     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint8_t, uint64_t) \
    1157     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint8_t, half) */ \
    1158     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint8_t, float) \
    1159     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint8_t, double) \
    1160     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint8_t, long double) \
    1161     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint8_t, real) */ \
    1162     \
    1163     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int16_t, uint16_t) \
    1164     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int16_t, int32_t) \
    1165     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int16_t, uint32_t) \
    1166     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int16_t, int64_t) \
    1167     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int16_t, uint64_t) \
    1168     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int16_t, half) */ \
    1169     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int16_t, float) \
    1170     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int16_t, double) \
    1171     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int16_t, long double) \
    1172     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int16_t, real) */ \
    1173     \
    1174     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint16_t, int32_t) \
    1175     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint16_t, uint32_t) \
    1176     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint16_t, int64_t) \
    1177     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint16_t, uint64_t) \
    1178     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint16_t, half) */ \
    1179     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint16_t, float) \
    1180     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint16_t, double) \
    1181     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint16_t, long double) \
    1182     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint16_t, real) */ \
    1183     \
    1184     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int32_t, uint32_t) \
    1185     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int32_t, int64_t) \
    1186     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int32_t, uint64_t) \
    1187     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int32_t, half) */ \
    1188     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int32_t, float) \
    1189     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int32_t, double) \
    1190     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int32_t, long double) \
    1191     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int32_t, real) */ \
    1192     \
    1193     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint32_t, int64_t) \
    1194     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint32_t, uint64_t) \
    1195     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint32_t, half) */ \
    1196     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint32_t, float) \
    1197     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint32_t, double) \
    1198     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint32_t, long double) \
    1199     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint32_t, real) */ \
    1200     \
    1201     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int64_t, uint64_t) \
    1202     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int64_t, half) */ \
    1203     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int64_t, float) \
    1204     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int64_t, double) \
    1205     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int64_t, long double) \
    1206     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, int64_t, real) */ \
    1207     \
    1208     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint64_t, half) */ \
    1209     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint64_t, float) \
    1210     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint64_t, double) \
    1211     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint64_t, long double) \
    1212     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, uint64_t, real) */ \
    1213     \
    1214     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, half, float) */ \
    1215     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, half, double) */ \
    1216     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, half, long double) */ \
    1217     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, half, real) */ \
    1218     \
    1219     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, float, double) \
    1220     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, float, long double) \
    1221     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, float, real) */ \
    1222     \
    1223     DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, double, long double) \
    1224     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, double, real) */ \
    1225     \
    1226     /* DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, long double, real) */
     1133#define DECLARE_ALL_VECTOR_COERCE_OPS(tlow, thigh) \
     1134    DECLARE_ALL_VECTOR_COERCE_OPS_INNER(Vec2, tlow, thigh) \
     1135    DECLARE_ALL_VECTOR_COERCE_OPS_INNER(Vec3, tlow, thigh) \
     1136    DECLARE_ALL_VECTOR_COERCE_OPS_INNER(Vec4, tlow, thigh) \
     1137    \
     1138    DECLARE_VEC_3_COERCE_OPS(Vec3, static, tlow, thigh, thigh) \
     1139    DECLARE_VEC_3_COERCE_OPS(Vec3, static, thigh, tlow, thigh)
    12271140
    12281141/* Disable warning about unary operator applied to unsigned type */
     
    12351148DECLARE_ALL_NONVECTOR_OPS(Quat)
    12361149
    1237 DECLARE_ALL_VECTOR_OPS(Vec2)
    1238 DECLARE_ALL_VECTOR_OPS(Vec3)
    1239 DECLARE_ALL_VECTOR_OPS(Vec4)
     1150DECLARE_ALL_VECTOR_OPS(half)
     1151DECLARE_ALL_VECTOR_OPS(float)
     1152DECLARE_ALL_VECTOR_OPS(double)
     1153DECLARE_ALL_VECTOR_OPS(int8_t)
     1154DECLARE_ALL_VECTOR_OPS(uint8_t)
     1155DECLARE_ALL_VECTOR_OPS(int16_t)
     1156DECLARE_ALL_VECTOR_OPS(uint16_t)
     1157DECLARE_ALL_VECTOR_OPS(int32_t)
     1158DECLARE_ALL_VECTOR_OPS(uint32_t)
     1159DECLARE_ALL_VECTOR_OPS(int64_t)
     1160DECLARE_ALL_VECTOR_OPS(uint64_t)
    12401161
    12411162#if defined _MSC_VER
     
    12581179#endif
    12591180
    1260 DECLARE_ALL_VECTOR_COERCE_OPS(Vec2)
    1261 DECLARE_ALL_VECTOR_COERCE_OPS(Vec3)
    1262 DECLARE_ALL_VECTOR_COERCE_OPS(Vec4)
     1181/* Apply the same coercion rules as in the C++ standard. However,   */
     1182/* instead of promoting int8_t etc. to int, we apply our own rules. */
     1183/* FIXME: "half" and "real" are deactivated for now, because we do  */
     1184/* not implement all combinations of operators for these types yet. */
     1185DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, uint8_t)
     1186DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, int16_t)
     1187DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, uint16_t)
     1188DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, int32_t)
     1189DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, uint32_t)
     1190DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, int64_t)
     1191DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, uint64_t)
     1192/* DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, half) */
     1193DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, float)
     1194DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, double)
     1195DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, long double)
     1196/* DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, real) */
     1197
     1198DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, int16_t)
     1199DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, uint16_t)
     1200DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, int32_t)
     1201DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, uint32_t)
     1202DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, int64_t)
     1203DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, uint64_t)
     1204/* DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, half) */
     1205DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, float)
     1206DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, double)
     1207DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, long double)
     1208/* DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, real) */
     1209
     1210DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, uint16_t)
     1211DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, int32_t)
     1212DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, uint32_t)
     1213DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, int64_t)
     1214DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, uint64_t)
     1215/* DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, half) */
     1216DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, float)
     1217DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, double)
     1218DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, long double)
     1219/* DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, real) */
     1220
     1221DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, int32_t)
     1222DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, uint32_t)
     1223DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, int64_t)
     1224DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, uint64_t)
     1225/* DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, half) */
     1226DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, float)
     1227DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, double)
     1228DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, long double)
     1229/* DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, real) */
     1230
     1231DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, uint32_t)
     1232DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, int64_t)
     1233DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, uint64_t)
     1234/* DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, half) */
     1235DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, float)
     1236DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, double)
     1237DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, long double)
     1238/* DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, real) */
     1239
     1240DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, int64_t)
     1241DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, uint64_t)
     1242/* DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, half) */
     1243DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, float)
     1244DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, double)
     1245DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, long double)
     1246/* DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, real) */
     1247
     1248DECLARE_ALL_VECTOR_COERCE_OPS(int64_t, uint64_t)
     1249/* DECLARE_ALL_VECTOR_COERCE_OPS(int64_t, half) */
     1250DECLARE_ALL_VECTOR_COERCE_OPS(int64_t, float)
     1251DECLARE_ALL_VECTOR_COERCE_OPS(int64_t, double)
     1252DECLARE_ALL_VECTOR_COERCE_OPS(int64_t, long double)
     1253/* DECLARE_ALL_VECTOR_COERCE_OPS(int64_t, real) */
     1254
     1255/* DECLARE_ALL_VECTOR_COERCE_OPS(uint64_t, half) */
     1256DECLARE_ALL_VECTOR_COERCE_OPS(uint64_t, float)
     1257DECLARE_ALL_VECTOR_COERCE_OPS(uint64_t, double)
     1258DECLARE_ALL_VECTOR_COERCE_OPS(uint64_t, long double)
     1259/* DECLARE_ALL_VECTOR_COERCE_OPS(uint64_t, real) */
     1260
     1261/* DECLARE_ALL_VECTOR_COERCE_OPS(half, float) */
     1262/* DECLARE_ALL_VECTOR_COERCE_OPS(half, double) */
     1263/* DECLARE_ALL_VECTOR_COERCE_OPS(half, long double) */
     1264/* DECLARE_ALL_VECTOR_COERCE_OPS(half, real) */
     1265
     1266DECLARE_ALL_VECTOR_COERCE_OPS(float, double)
     1267DECLARE_ALL_VECTOR_COERCE_OPS(float, long double)
     1268/* DECLARE_ALL_VECTOR_COERCE_OPS(float, real) */
     1269
     1270DECLARE_ALL_VECTOR_COERCE_OPS(double, long double)
     1271/* DECLARE_ALL_VECTOR_COERCE_OPS(double, real) */
     1272
     1273/* DECLARE_ALL_VECTOR_COERCE_OPS(long double, real) */
    12631274
    12641275#if defined __GNUC__ && (__GNUC__ >= 4)
  • trunk/src/vector.cpp

    r1173 r1175  
    3737{
    3838
    39 float dot(vec2 v1, vec2 v2)
    40 {
    41     return v1.x * v2.x + v1.y * v2.y;
    42 }
    43 
    44 float dot(vec3 v1, vec3 v2)
    45 {
    46     return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
    47 }
    48 
    49 float dot(vec4 v1, vec4 v2)
    50 {
    51     return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
    52 }
    53 
    54 template<> vec3 cross(vec3 v1, vec3 v2)
    55 {
    56     return vec3(v1.y * v2.z - v1.z * v2.y,
    57                 v1.z * v2.x - v1.x * v2.z,
    58                 v1.x * v2.y - v1.y * v2.x);
    59 }
    60 
    6139static inline float det3(float a, float b, float c,
    6240                         float d, float e, float f,
Note: See TracChangeset for help on using the changeset viewer.