ClanLib  2.3.7
vec1.h
Go to the documentation of this file.
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2011 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 ** Mark Page
28 ** Harry Storbacka
29 */
30 
33 
34 #pragma once
35 
36 #include "../api_core.h"
37 #include "cl_math.h"
38 #include "vec2.h"
39 #include "vec3.h"
40 #include "vec4.h"
41 
42 template<typename Type>
43 class CL_Vec1;
44 
45 template<typename Type>
46 class CL_Vec2;
47 
48 template<typename Type>
49 class CL_Vec3;
50 
51 template<typename Type>
52 class CL_Vec4;
53 
54 template<typename Type>
55 class CL_Mat2;
56 
57 template<typename Type>
58 class CL_Mat3;
59 
60 template<typename Type>
61 class CL_Mat4;
62 
63 template<typename Type>
64 class CL_Sizex;
65 
66 template<typename Type>
67 class CL_Pointx;
68 
69 class CL_Angle;
70 
77 template<typename Type>
78 class CL_Vec1
79 {
80 public:
81  typedef Type datatype;
82 
83  union { Type x; Type s; Type r; };
84 
85  CL_Vec1() : x(0) { }
86  CL_Vec1(const CL_Vec2<Type> &copy) { x = copy.x; }
87  CL_Vec1(const CL_Vec3<Type> &copy) { x = copy.x; }
88  CL_Vec1(const CL_Vec4<Type> &copy) { x = copy.x; }
89  CL_Vec1(const Type &p1) : x(p1) { }
90 
97  static CL_Vec1<Type> round(const CL_Vec1<Type>& vector) { CL_Vec1 dest; dest.x = (Type) floor(vector.x+0.5); return dest; }
98 
101 
102 public:
107  CL_Vec1<Type> &round() { x = (Type) floor(x+0.5); return *this;}
108 
112 
113 public:
114  const Type &operator[](unsigned int i) const { return ((Type *) this)[i]; }
115  Type &operator[](unsigned int i) { return ((Type *) this)[i]; }
116  operator Type *() { return (Type *) this; }
117  operator Type * const() const { return (Type * const) this; }
118 
120  void operator += (const CL_Vec1<Type>& vector) { x+= vector.x; }
121 
123  void operator += ( Type value) { x+= value; }
124 
126  CL_Vec1<Type> operator + (const CL_Vec1<Type>& vector) const {return CL_Vec1<Type>(vector.x + x);}
127 
129  CL_Vec1<Type> operator + (Type value) const {return CL_Vec1<Type>(value + x);}
130 
132  void operator -= (const CL_Vec1<Type>& vector) { x-= vector.x; }
133 
135  void operator -= ( Type value) { x-= value; }
136 
138  CL_Vec1<Type> operator - (const CL_Vec1<Type>& vector) const {return CL_Vec1<Type>(x - vector.x);}
139 
141  CL_Vec1<Type> operator - (Type value) const {return CL_Vec1<Type>(x - value);}
142 
144  void operator *= (const CL_Vec1<Type>& vector) { x*= vector.x; }
145 
147  void operator *= ( Type value) { x*= value; }
148 
150  CL_Vec1<Type> operator * (const CL_Vec1<Type>& vector) const {return CL_Vec1<Type>(vector.x * x);}
151 
153  CL_Vec1<Type> operator * (Type value) const {return CL_Vec1<Type>(value * x);}
154 
156  void operator /= (const CL_Vec1<Type>& vector) { x/= vector.x; }
157 
159  void operator /= ( Type value) { x/= value; }
160 
162  CL_Vec1<Type> operator / (const CL_Vec1<Type>& vector) const {return CL_Vec1<Type>(x / vector.x);}
163 
165  CL_Vec1<Type> operator / (Type value) const {return CL_Vec1<Type>(x / value);}
166 
168  CL_Vec1<Type> &operator = (const CL_Vec1<Type>& vector) { x = vector.x; return *this; }
169 
171  bool operator == (const CL_Vec1<Type>& vector) const {return ((x == vector.x));}
172 
174  bool operator != (const CL_Vec1<Type>& vector) const {return ((x != vector.x));}
176 };
177 
186