Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ShLibNormal.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright (c) 2003 University of Waterloo Computer Graphics Laboratory
00004 // Project administrator: Michael D. McCool
00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa,
00006 //          Michael D. McCool
00007 // 
00008 // This software is provided 'as-is', without any express or implied
00009 // warranty. In no event will the authors be held liable for any damages
00010 // arising from the use of this software.
00011 // 
00012 // Permission is granted to anyone to use this software for any purpose,
00013 // including commercial applications, and to alter it and redistribute it
00014 // freely, subject to the following restrictions:
00015 // 
00016 // 1. The origin of this software must not be misrepresented; you must
00017 // not claim that you wrote the original software. If you use this
00018 // software in a product, an acknowledgment in the product documentation
00019 // would be appreciated but is not required.
00020 // 
00021 // 2. Altered source versions must be plainly marked as such, and must
00022 // not be misrepresented as being the original software.
00023 // 
00024 // 3. This notice may not be removed or altered from any source
00025 // distribution.
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

Generated on Mon Jan 24 18:36:33 2005 for Sh by  doxygen 1.4.1