00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027 #ifndef SHLIBNORMAL_HPP
00028 #define SHLIBNORMAL_HPP
00029
00030 #include "ShNormal.hpp"
00031 #include "ShVector.hpp"
00032 #include "ShLib.hpp"
00033
00034 namespace SH {
00035
00036 SH_SHLIB_USUAL_NON_UNIT_OPS_RETTYPE(ShNormal, ShNormal);
00037
00038 template<int N, ShBindingType B1, typename T, bool S1>
00039 ShNormal<N, SH_TEMP, T, false>
00040 abs(const ShNormal<N, B1, T, S1>& var)
00041 {
00042 ShGeneric<N, T> t = abs(static_cast< ShGeneric<N, T> >(var));
00043 ShNormal<N, SH_TEMP, T, false> vec(t.node(), t.swizzle(), t.neg());
00044 return vec;
00045 }
00046
00047 template<int N, ShBindingType B1, typename T, bool S1>
00048 ShNormal<N, SH_TEMP, T, false>
00049 normalize(const ShNormal<N, B1, T, S1>& var)
00050 {
00051 ShGeneric<N, T> t = normalize(static_cast< ShGeneric<N, T> >(var));
00052 ShNormal<N, SH_TEMP, T, false> vec(t.node(), t.swizzle(), t.neg());
00053 return vec;
00054 }
00055
00056 SH_SHLIB_USUAL_SUBTRACT(ShNormal);
00057
00058 SH_SHLIB_LEFT_MATRIX_OPERATION(ShNormal, operator|, M);
00059
00060 template<int N, ShBindingType B1, ShBindingType B2, typename T, bool S1, bool S2>
00061 ShGeneric<1, T> operator|(const ShNormal<N, B1, T, S1>& a,
00062 const ShNormal<N, B2, T, S2>& b)
00063 {
00064 return dot(a, b);
00065 }
00066
00067 template<int N, ShBindingType B1, ShBindingType B2, typename T, bool S1, bool S2>
00068 ShGeneric<1, T> operator|(const ShVector<N, B1, T, S1>& a,
00069 const ShNormal<N, B2, T, S2>& b)
00070 {
00071 return dot(a, b);
00072 }
00073
00074 template<int N, ShBindingType B1, ShBindingType B2, typename T, bool S1, bool S2>
00075 ShGeneric<1, T> operator|(const ShNormal<N, B1, T, S1>& a,
00076 const ShVector<N, B2, T, S2>& b)
00077 {
00078 return dot(a, b);
00079 }
00080
00081 template<ShBindingType B1, ShBindingType B2, typename T, bool S1>
00082 ShNormal<3, SH_TEMP, T, false> operator|(const ShMatrix<4, 4, B1, T>& m,
00083 const ShNormal<3, B2, T, S1>& v)
00084 {
00085 ShNormal<3, SH_TEMP, T, false> t;
00086 for (int i = 0; i < 3; i++) {
00087 t(i) = dot(m[i](0,1,2), v);
00088 }
00089 return t;
00090 }
00091
00092 template<ShBindingType B1, ShBindingType B2, typename T, bool S1>
00093 ShNormal<2, SH_TEMP, T, false> operator|(const ShMatrix<3, 3, B1, T>& m,
00094 const ShNormal<2, B2, T, S1>& v)
00095 {
00096 ShNormal<2, SH_TEMP, T, false> t;
00097 for (int i = 0; i < 2; i++) {
00098 t(i) = dot(m[i](0,1), v);
00099 }
00100 return t;
00101 }
00102
00103 template<ShBindingType B1, ShBindingType B2, typename T, bool S1>
00104 ShNormal<1, SH_TEMP, T, false> operator|(const ShMatrix<2, 2, B1, T>& m,
00105 const ShNormal<1, B2, T, S1>& v)
00106 {
00107 ShNormal<1, SH_TEMP, T, false> t;
00108 for (int i = 0; i < 1; i++) {
00109 t(i) = dot(m[i](0), v);
00110 }
00111 return t;
00112 }
00113
00114
00115 }
00116
00117 #endif