00001 00002 00003 00004 00005 00006 00007 #include "Volumizer.h" 00008 #include "math.h" 00009 00010 #ifndef __UTIL_H__ 00011 #define __UTIL_H__ 00012 00014 #define clamp(_val, _min, _max) ((_val < _min)?_min:((_val > _max)?_max:_val)) 00015 00017 typedef struct { 00018 float x, y, z; 00019 } vect; 00020 00022 typedef struct { 00023 float r, g, b, a; 00024 } color; 00025 00027 typedef struct { 00028 vect pos; 00029 vect org; 00030 vect up; 00031 float rotx, roty; 00032 } camera; 00033 00035 static inline float dot(vect v1, vect v2) 00036 { 00037 return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z; 00038 } 00039 00041 static inline vect cross(vect v1, vect v2) 00042 { 00043 vect res; 00044 00045 res.x = v1.y * v2.z - v2.y * v1.z; 00046 res.y = v1.z * v2.x - v2.z * v1.x; 00047 res.z = v1.x * v2.y - v2.x * v1.y; 00048 00049 return res; 00050 } 00051 00053 static inline float norm2(vect v) 00054 { 00055 return v.x*v.x + v.y*v.y + v.z*v.z; 00056 } 00057 00059 static inline float norm(vect v) 00060 { 00061 return sqrtf(norm2(v)); 00062 } 00063 00065 static inline void normalize(vect &v) 00066 { 00067 float vn = norm(v); 00068 00069 v.x /= vn; 00070 v.y /= vn; 00071 v.z /= vn; 00072 } 00073 00074 #endif //__UTIL_H__