00001 #ifndef animal_x3dtk_linear__________________________
00002 #define animal_x3dtk_linear__________________________
00003
00008 #include <animal/value.h>
00009 #include <X3DTK/kernel.h>
00010 #include <animal/matrix.h>
00011
00012 namespace animal
00013 {
00014
00015
00016
00018 template<>
00019 struct container_traits<X3DTK::SFVec3f>
00020 {
00021 typedef float* iterator;
00022 typedef float value_type;
00023 typedef value_type& reference;
00024 typedef std::size_t size_type;
00025
00027 static iterator begin(X3DTK::SFVec3f& v) { return &(v.x); }
00029 static inline iterator end(X3DTK::SFVec3f& v) { return &v.x + 3; }
00031 static inline size_type size(X3DTK::SFVec3f&) { return 3; }
00032 };
00033
00035 template<>
00036 struct container_traits<X3DTK::SFVec3f const>
00037 {
00038 typedef const float* iterator;
00039 typedef float value_type;
00040 typedef const value_type& reference;
00041 typedef std::size_t size_type;
00042
00044 static inline iterator begin(X3DTK::SFVec3f& v) { return &v.x; }
00046 static inline iterator end(X3DTK::SFVec3f& v) { return &v.x + 3; }
00048 static inline size_type size(X3DTK::SFVec3f& v) { return 3; }
00049 };
00050
00051 template<>
00052 struct Value<X3DTK::SFVec3f>
00053 {
00054 static inline X3DTK::SFVec3f zero()
00055 {
00056 return X3DTK::SFVec3f(0,0,0);
00057 }
00058 };
00059
00060 template<>
00061 struct value_type<X3DTK::SFVec3f>
00062 {
00063 typedef float type;
00064 };
00065
00066 inline std::size_t size(const X3DTK::SFVec3f& ){ return 3;}
00067 inline const float* begin(const X3DTK::SFVec3f& v){ return &(v.x);}
00068 inline float* begin(X3DTK::SFVec3f& v){ return &(v.x);}
00069 inline const float* end(const X3DTK::SFVec3f& v){ return &(v.x) + 3;}
00070 inline float* end(X3DTK::SFVec3f& v){ return &(v.x) + 3;}
00071
00072
00073 inline X3DTK::SFVec3f& operator *= (X3DTK::SFVec3f& v, float f)
00074 {
00075 for( int i=0; i<3; ++i )
00076 v.f_data()[i]*= f;
00077 return v;
00078 }
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 inline float v_dot( const X3DTK::MFVec3f& u, const X3DTK::MFVec3f& v )
00161 {
00162 float p=0;
00163 for( unsigned int i=0, iend=size(u); i!=iend; ++i )
00164 p += v_dot( u[i], v[i] );
00165 return p;
00166 }
00167
00168 inline void v_peq (X3DTK::MFVec3f& v, const X3DTK::MFVec3f& u)
00169 {
00170 for( unsigned int i=0, iend=size(u); i!=iend; ++i )
00171 v_peq( v[i], u[i] );
00172 }
00173
00174 inline void v_peq (X3DTK::MFVec3f& v, float a, const X3DTK::MFVec3f& u)
00175 {
00176 for( unsigned int i=0, iend=size(u); i!=iend; ++i )
00177 v_peq( v[i], a, u[i] );
00178 }
00179
00180 inline float v_norm(const X3DTK::MFVec3f& u)
00181 {
00182 return sqrt( v_dot(u,u) );
00183 }
00184
00185 }
00186 #endif