Changeset 1175
 Timestamp:
 Mar 27, 2012, 1:43:15 AM (9 years ago)
 Location:
 trunk/src
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/lol/math/vector.h
r1163 r1175 485 485 486 486 DECLARE_MEMBER_OPS(Vec3) 487 488 template<typename U>489 friend Vec3<U> cross(Vec3<U>, Vec3<U>);490 487 491 488 #if !defined __ANDROID__ … … 1078 1075 } 1079 1076 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 1080 1086 #define DECLARE_BINARY_OPS(tname, tprefix, type) \ 1081 1087 DECLARE_BINARY_COERCE_OPS(tname, tprefix, type, type, type) \ … … 1111 1117 DECLARE_VECTOR_OPS(tname, static, type) \ 1112 1118 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) 1125 1125 1126 1126 #define DECLARE_ALL_VECTOR_COERCE_OPS_INNER(tname, tlow, thigh) \ … … 1131 1131 DECLARE_VECTOR_COERCE_OPS(tname, static, thigh, tlow, thigh) 1132 1132 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) 1227 1140 1228 1141 /* Disable warning about unary operator applied to unsigned type */ … … 1235 1148 DECLARE_ALL_NONVECTOR_OPS(Quat) 1236 1149 1237 DECLARE_ALL_VECTOR_OPS(Vec2) 1238 DECLARE_ALL_VECTOR_OPS(Vec3) 1239 DECLARE_ALL_VECTOR_OPS(Vec4) 1150 DECLARE_ALL_VECTOR_OPS(half) 1151 DECLARE_ALL_VECTOR_OPS(float) 1152 DECLARE_ALL_VECTOR_OPS(double) 1153 DECLARE_ALL_VECTOR_OPS(int8_t) 1154 DECLARE_ALL_VECTOR_OPS(uint8_t) 1155 DECLARE_ALL_VECTOR_OPS(int16_t) 1156 DECLARE_ALL_VECTOR_OPS(uint16_t) 1157 DECLARE_ALL_VECTOR_OPS(int32_t) 1158 DECLARE_ALL_VECTOR_OPS(uint32_t) 1159 DECLARE_ALL_VECTOR_OPS(int64_t) 1160 DECLARE_ALL_VECTOR_OPS(uint64_t) 1240 1161 1241 1162 #if defined _MSC_VER … … 1258 1179 #endif 1259 1180 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. */ 1185 DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, uint8_t) 1186 DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, int16_t) 1187 DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, uint16_t) 1188 DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, int32_t) 1189 DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, uint32_t) 1190 DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, int64_t) 1191 DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, uint64_t) 1192 /* DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, half) */ 1193 DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, float) 1194 DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, double) 1195 DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, long double) 1196 /* DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, real) */ 1197 1198 DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, int16_t) 1199 DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, uint16_t) 1200 DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, int32_t) 1201 DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, uint32_t) 1202 DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, int64_t) 1203 DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, uint64_t) 1204 /* DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, half) */ 1205 DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, float) 1206 DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, double) 1207 DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, long double) 1208 /* DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, real) */ 1209 1210 DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, uint16_t) 1211 DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, int32_t) 1212 DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, uint32_t) 1213 DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, int64_t) 1214 DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, uint64_t) 1215 /* DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, half) */ 1216 DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, float) 1217 DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, double) 1218 DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, long double) 1219 /* DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, real) */ 1220 1221 DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, int32_t) 1222 DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, uint32_t) 1223 DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, int64_t) 1224 DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, uint64_t) 1225 /* DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, half) */ 1226 DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, float) 1227 DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, double) 1228 DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, long double) 1229 /* DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, real) */ 1230 1231 DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, uint32_t) 1232 DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, int64_t) 1233 DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, uint64_t) 1234 /* DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, half) */ 1235 DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, float) 1236 DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, double) 1237 DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, long double) 1238 /* DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, real) */ 1239 1240 DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, int64_t) 1241 DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, uint64_t) 1242 /* DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, half) */ 1243 DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, float) 1244 DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, double) 1245 DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, long double) 1246 /* DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, real) */ 1247 1248 DECLARE_ALL_VECTOR_COERCE_OPS(int64_t, uint64_t) 1249 /* DECLARE_ALL_VECTOR_COERCE_OPS(int64_t, half) */ 1250 DECLARE_ALL_VECTOR_COERCE_OPS(int64_t, float) 1251 DECLARE_ALL_VECTOR_COERCE_OPS(int64_t, double) 1252 DECLARE_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) */ 1256 DECLARE_ALL_VECTOR_COERCE_OPS(uint64_t, float) 1257 DECLARE_ALL_VECTOR_COERCE_OPS(uint64_t, double) 1258 DECLARE_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 1266 DECLARE_ALL_VECTOR_COERCE_OPS(float, double) 1267 DECLARE_ALL_VECTOR_COERCE_OPS(float, long double) 1268 /* DECLARE_ALL_VECTOR_COERCE_OPS(float, real) */ 1269 1270 DECLARE_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) */ 1263 1274 1264 1275 #if defined __GNUC__ && (__GNUC__ >= 4) 
trunk/src/vector.cpp
r1173 r1175 37 37 { 38 38 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 61 39 static inline float det3(float a, float b, float c, 62 40 float d, float e, float f,
Note: See TracChangeset
for help on using the changeset viewer.