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 2003-2005 Serious Hack Inc.
00004 // 
00005 // This software is provided 'as-is', without any express or implied
00006 // warranty. In no event will the authors be held liable for any damages
00007 // arising from the use of this software.
00008 // 
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it
00011 // freely, subject to the following restrictions:
00012 // 
00013 // 1. The origin of this software must not be misrepresented; you must
00014 // not claim that you wrote the original software. If you use this
00015 // software in a product, an acknowledgment in the product documentation
00016 // would be appreciated but is not required.
00017 // 
00018 // 2. Altered source versions must be plainly marked as such, and must
00019 // not be misrepresented as being the original software.
00020 // 
00021 // 3. This notice may not be removed or altered from any source
00022 // distribution.
00024 #ifndef SHLIBNORMAL_HPP
00025 #define SHLIBNORMAL_HPP
00026 
00027 #include "ShAttrib.hpp"
00028 #include "ShLib.hpp"
00029 
00030 namespace SH {
00031 
00032 SH_SHLIB_USUAL_NON_UNIT_OPS_RETTYPE(SH_NORMAL, SH_NORMAL);
00033 
00034 template<int N, ShBindingType B1, typename T, bool S1>
00035 ShAttrib<N, SH_TEMP, T, SH_NORMAL, false>
00036 abs(const ShAttrib<N, B1, T, SH_NORMAL, S1>& var)
00037 {
00038   ShGeneric<N, T> t = abs(static_cast< ShGeneric<N, T> >(var));
00039   ShAttrib<N, SH_TEMP, T, SH_NORMAL, false> vec(t.node(), t.swizzle(), t.neg());
00040   return vec;
00041 }
00042 
00043 template<int N, ShBindingType B1, typename T, bool S1>
00044 ShAttrib<N, SH_TEMP, T, SH_NORMAL, false>
00045 normalize(const ShAttrib<N, B1, T, SH_NORMAL, S1>& var)
00046 {
00047   ShGeneric<N, T> t = normalize(static_cast< ShGeneric<N, T> >(var));
00048   ShAttrib<N, SH_TEMP, T, SH_NORMAL, false> vec(t.node(), t.swizzle(), t.neg());
00049   return vec;
00050 }
00051 
00052 SH_SHLIB_USUAL_SUBTRACT(SH_NORMAL);
00053 
00054 SH_SHLIB_LEFT_MATRIX_OPERATION(SH_NORMAL, operator|, M);
00055 
00056 template<int N, ShBindingType B1, ShBindingType B2, typename T, bool S1, bool S2>
00057 ShGeneric<1, T>
00058 operator|(const ShAttrib<N, B1, T, SH_NORMAL, S1>& a, const ShAttrib<N, B2, T, SH_NORMAL, S2>& b)
00059 {
00060   return dot(a, b);
00061 }
00062 
00063 template<int N, ShBindingType B1, ShBindingType B2, typename T, bool S1, bool S2>
00064 ShGeneric<1, T> 
00065 operator|(const ShAttrib<N, B1, T, SH_VECTOR, S1>& a, const ShAttrib<N, B2, T, SH_NORMAL, S2>& b)
00066 {
00067   return dot(a, b);
00068 }
00069 
00070 template<int N, ShBindingType B1, ShBindingType B2, typename T, bool S1, bool S2>
00071 ShGeneric<1, T>
00072 operator|(const ShAttrib<N, B1, T, SH_NORMAL, S1>& a, const ShAttrib<N, B2, T, SH_VECTOR, S2>& b)
00073 {
00074   return dot(a, b);
00075 }
00076 
00077 template<ShBindingType B1, ShBindingType B2, typename T, bool S1>
00078 ShAttrib<3, SH_TEMP, T, SH_NORMAL, false>
00079 operator|(const ShMatrix<4, 4, B1, T>& m, const ShAttrib<3, B2, T, SH_NORMAL, S1>& v)
00080 {
00081   ShAttrib<3, SH_TEMP, T, SH_NORMAL, false> t;
00082   for (int i = 0; i < 3; i++) {
00083     t(i) = dot(m[i](0,1,2), v);
00084   }
00085   return t;
00086 }
00087 
00088 template<ShBindingType B1, ShBindingType B2, typename T, bool S1>
00089 ShAttrib<2, SH_TEMP, T, SH_NORMAL, false>
00090 operator|(const ShMatrix<3, 3, B1, T>& m, const ShAttrib<2, B2, T, SH_NORMAL, S1>& v)
00091 {
00092   ShAttrib<2, SH_TEMP, T, SH_NORMAL, false> t;
00093   for (int i = 0; i < 2; i++) {
00094     t(i) = dot(m[i](0,1), v);
00095   }
00096   return t;
00097 }
00098 
00099 template<ShBindingType B1, ShBindingType B2, typename T, bool S1>
00100 ShAttrib<1, SH_TEMP, T, SH_NORMAL, false>
00101 operator|(const ShMatrix<2, 2, B1, T>& m, const ShAttrib<1, B2, T, SH_NORMAL, S1>& v)
00102 {
00103   ShAttrib<1, SH_TEMP, T, SH_NORMAL, false> t;
00104   for (int i = 0; i < 1; i++) {
00105     t(i) = dot(m[i](0), v);
00106   }
00107   return t;
00108 }
00109 
00110 }
00111 
00112 #endif

Generated on Wed Jun 15 18:12:40 2005 for Sh by  doxygen 1.4.3-20050530