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

ShLibVector.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 SHLIBVECTOR_HPP
00025 #define SHLIBVECTOR_HPP
00026 
00027 #include "ShAttrib.hpp"
00028 #include "ShLib.hpp"
00029 
00030 namespace SH {
00031 
00032 SH_SHLIB_USUAL_NON_UNIT_OPS_RETTYPE(SH_VECTOR, SH_VECTOR);
00033 
00034 template<int N, ShBindingType B1, typename T, bool S1> 
00035 ShAttrib<N, SH_TEMP, T, SH_VECTOR, false>
00036 abs(const ShAttrib<N, B1, T, SH_VECTOR, S1>& var) 
00037 { 
00038   ShGeneric<N, T> t = abs(static_cast< ShGeneric<N, T> >(var)); 
00039   ShAttrib<N, SH_TEMP, T, SH_VECTOR, 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_VECTOR, false> 
00045 normalize(const ShAttrib<N, B1, T, SH_VECTOR, S1>& var) 
00046 {
00047   ShGeneric<N, T> t = normalize(static_cast< ShGeneric<N, T> >(var)); 
00048   ShAttrib<N, SH_TEMP, T, SH_VECTOR, false> vec(t.node(), t.swizzle(), t.neg()); 
00049   return vec;
00050 }
00051 
00052 SH_SHLIB_USUAL_SUBTRACT(SH_VECTOR);
00053 
00054 SH_SHLIB_LEFT_MATRIX_OPERATION(SH_VECTOR, 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_VECTOR, S1>& a, const ShAttrib<N, B2, T, SH_VECTOR, S2>& b)
00059 {
00060   return dot(a, b);
00061 }
00062 
00063 template<ShBindingType B1, ShBindingType B2, typename T, bool S1>
00064 ShAttrib<3, SH_TEMP, T, SH_VECTOR, false> 
00065 operator|(const ShMatrix<4, 4, B1, T>& m, const ShAttrib<3, B2, T, SH_VECTOR, S1>& v)
00066 {
00067   ShAttrib<3, SH_TEMP, T, SH_VECTOR, false> t;
00068   for (int i = 0; i < 3; i++) {
00069     t(i) = dot(m[i](0,1,2), v);
00070   }
00071   return t;
00072 }
00073 
00074 template<ShBindingType B1, ShBindingType B2, typename T, bool S1>
00075 ShAttrib<2, SH_TEMP, T, SH_VECTOR, false>
00076 operator|(const ShMatrix<3, 3, B1, T>& m, const ShAttrib<2, B2, T, SH_VECTOR, S1>& v)
00077 {
00078   ShAttrib<2, SH_TEMP, T, SH_VECTOR, false> t;
00079   for (int i = 0; i < 2; i++) {
00080     t(i) = dot(m[i](0,1), v);
00081   }
00082   return t;
00083 }
00084 
00085 template<ShBindingType B1, ShBindingType B2, typename T, bool S1>
00086 ShAttrib<1, SH_TEMP, T, SH_VECTOR, false>
00087 operator|(const ShMatrix<2, 2, B1, T>& m, const ShAttrib<1, B2, T, SH_VECTOR, S1>& v)
00088 {
00089   ShAttrib<1, SH_TEMP, T, SH_VECTOR, false> t;
00090   for (int i = 0; i < 1; i++) {
00091     t(i) = dot(m[i](0), v);
00092   }
00093   return t;
00094 }
00095 
00096 }
00097 
00098 #endif

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