vec1.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2011 The ClanLib Team
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 not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 **    Mark Page
00028 **    Harry Storbacka
00029 */
00030 
00033 
00034 #pragma once
00035 
00036 #include "../api_core.h"
00037 #include "cl_math.h"
00038 #include "vec2.h"
00039 #include "vec3.h"
00040 #include "vec4.h"
00041 
00042 template<typename Type>
00043 class CL_Vec1;
00044 
00045 template<typename Type>
00046 class CL_Vec2;
00047 
00048 template<typename Type>
00049 class CL_Vec3;
00050 
00051 template<typename Type>
00052 class CL_Vec4;
00053 
00054 template<typename Type>
00055 class CL_Mat2;
00056 
00057 template<typename Type>
00058 class CL_Mat3;
00059 
00060 template<typename Type>
00061 class CL_Mat4;
00062 
00063 template<typename Type>
00064 class CL_Sizex;
00065 
00066 template<typename Type>
00067 class CL_Pointx;
00068 
00069 class CL_Angle;
00070 
00077 template<typename Type>
00078 class CL_Vec1
00079 {
00080 public:
00081         typedef Type datatype;
00082 
00083         union { Type x; Type s; Type r; };
00084 
00085         CL_Vec1() : x(0) { }
00086         CL_Vec1(const CL_Vec2<Type> &copy) { x = copy.x; }
00087         CL_Vec1(const CL_Vec3<Type> &copy) { x = copy.x; }
00088         CL_Vec1(const CL_Vec4<Type> &copy) { x = copy.x; }
00089         CL_Vec1(const Type &p1) : x(p1) { }
00090 
00097         static CL_Vec1<Type> round(const CL_Vec1<Type>& vector) { CL_Vec1 dest; dest.x = (Type) floor(vector.x+0.5); return dest; }
00098 
00101 
00102 public:
00107         CL_Vec1<Type> &round() { x = (Type) floor(x+0.5); return *this;}
00108 
00112 
00113 public:
00114         const Type &operator[](unsigned int i) const { return ((Type *) this)[i]; }
00115         Type &operator[](unsigned int i) { return ((Type *) this)[i]; }
00116         operator Type *() { return (Type *) this; }
00117         operator Type * const() const { return (Type * const) this; }
00118 
00120         void operator += (const CL_Vec1<Type>& vector) { x+= vector.x; }
00121 
00123         void operator += ( Type value) { x+= value; }
00124 
00126         CL_Vec1<Type> operator + (const CL_Vec1<Type>& vector) const {return CL_Vec1<Type>(vector.x + x);}
00127 
00129         CL_Vec1<Type> operator + (Type value) const {return CL_Vec1<Type>(value + x);}
00130 
00132         void operator -= (const CL_Vec1<Type>& vector) { x-= vector.x; }
00133 
00135         void operator -= ( Type value) { x-= value; }
00136 
00138         CL_Vec1<Type> operator - (const CL_Vec1<Type>& vector) const {return CL_Vec1<Type>(x - vector.x);}
00139 
00141         CL_Vec1<Type> operator - (Type value) const {return CL_Vec1<Type>(x - value);}
00142 
00144         void operator *= (const CL_Vec1<Type>& vector) { x*= vector.x; }
00145 
00147         void operator *= ( Type value) { x*= value; }
00148 
00150         CL_Vec1<Type> operator * (const CL_Vec1<Type>& vector) const {return CL_Vec1<Type>(vector.x * x);}
00151 
00153         CL_Vec1<Type> operator * (Type value) const {return CL_Vec1<Type>(value * x);}
00154 
00156         void operator /= (const CL_Vec1<Type>& vector) { x/= vector.x; }
00157 
00159         void operator /= ( Type value) { x/= value; }
00160 
00162         CL_Vec1<Type> operator / (const CL_Vec1<Type>& vector) const {return CL_Vec1<Type>(x / vector.x);}
00163 
00165         CL_Vec1<Type> operator / (Type value) const {return CL_Vec1<Type>(x / value);}
00166 
00168         CL_Vec1<Type> &operator = (const CL_Vec1<Type>& vector) { x = vector.x; return *this; }
00169 
00171         bool operator == (const CL_Vec1<Type>& vector) const {return ((x == vector.x));}
00172 
00174         bool operator != (const CL_Vec1<Type>& vector) const {return ((x != vector.x));}
00176 };
00177 
00178 typedef CL_Vec1<unsigned char> CL_Vec1ub;
00179 typedef CL_Vec1<char> CL_Vec1b;
00180 typedef CL_Vec1<unsigned short> CL_Vec1us;
00181 typedef CL_Vec1<short> CL_Vec1s;
00182 typedef CL_Vec1<unsigned int> CL_Vec1ui;
00183 typedef CL_Vec1<int> CL_Vec1i;
00184 typedef CL_Vec1<float> CL_Vec1f;
00185 typedef CL_Vec1<double> CL_Vec1d;
00186