PageRenderTime 37ms CodeModel.GetById 19ms app.highlight 14ms RepoModel.GetById 0ms app.codeStats 0ms

/glm/core/type_vec3.hpp

https://bitbucket.org/ggerganov/test_opengl
C++ Header | 344 lines | 186 code | 53 blank | 105 comment | 7 complexity | 54a5106ec4915d439f37720104098c79 MD5 | raw file
  1///////////////////////////////////////////////////////////////////////////////////
  2/// OpenGL Mathematics (glm.g-truc.net)
  3///
  4/// Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
  5/// Permission is hereby granted, free of charge, to any person obtaining a copy
  6/// of this software and associated documentation files (the "Software"), to deal
  7/// in the Software without restriction, including without limitation the rights
  8/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9/// copies of the Software, and to permit persons to whom the Software is
 10/// furnished to do so, subject to the following conditions:
 11/// 
 12/// The above copyright notice and this permission notice shall be included in
 13/// all copies or substantial portions of the Software.
 14/// 
 15/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 20/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 21/// THE SOFTWARE.
 22///
 23/// @ref core
 24/// @file glm/core/type_vec3.hpp
 25/// @date 2008-08-22 / 2011-06-15
 26/// @author Christophe Riccio
 27///////////////////////////////////////////////////////////////////////////////////
 28
 29#ifndef glm_core_type_gentype3
 30#define glm_core_type_gentype3
 31
 32#include "type_vec.hpp"
 33#include "type_float.hpp"
 34#include "type_int.hpp"
 35#include "type_size.hpp"
 36#include "_swizzle.hpp"
 37
 38namespace glm{
 39namespace detail
 40{
 41	template <typename T> struct tref2;
 42	template <typename T> struct tref3;
 43	template <typename T> struct tref4;
 44	template <typename T> struct tvec2;
 45	template <typename T> struct tvec4;
 46
 47	// Basic 3D vector type.
 48	// \ingroup core_template
 49	template <typename T>
 50	struct tvec3
 51	{	
 52		enum ctor{null};
 53
 54		typedef T value_type;
 55		typedef std::size_t size_type;
 56		GLM_FUNC_DECL size_type length() const;
 57
 58		typedef tvec3<T> type;
 59		typedef tvec3<bool> bool_type;
 60
 61		//////////////////////////////////////
 62		// Data
 63
 64#	if(GLM_COMPONENT == GLM_COMPONENT_CXX11)
 65		union 
 66		{
 67#		if(defined(GLM_SWIZZLE))
 68			_GLM_SWIZZLE3_2_MEMBERS(value_type, glm::detail::tvec2<value_type>, x, y, z)
 69			_GLM_SWIZZLE3_2_MEMBERS(value_type, glm::detail::tvec2<value_type>, r, g, b)
 70			_GLM_SWIZZLE3_2_MEMBERS(value_type, glm::detail::tvec2<value_type>, s, t, p)
 71			_GLM_SWIZZLE3_3_MEMBERS(value_type, glm::detail::tvec3<value_type>, x, y, z)
 72			_GLM_SWIZZLE3_3_MEMBERS(value_type, glm::detail::tvec3<value_type>, r, g, b)
 73			_GLM_SWIZZLE3_3_MEMBERS(value_type, glm::detail::tvec3<value_type>, s, t, p)
 74			_GLM_SWIZZLE3_4_MEMBERS(value_type, glm::detail::tvec4<value_type>, x, y, z)
 75			_GLM_SWIZZLE3_4_MEMBERS(value_type, glm::detail::tvec4<value_type>, r, g, b)
 76			_GLM_SWIZZLE3_4_MEMBERS(value_type, glm::detail::tvec4<value_type>, s, t, p)
 77#		endif//(defined(GLM_SWIZZLE))
 78
 79			struct{value_type r, g, b;};
 80			struct{value_type s, t, p;};
 81			struct{value_type x, y, z;};
 82		};
 83#	elif(GLM_COMPONENT == GLM_COMPONENT_CXX98)
 84		union {value_type x, r, s;};
 85		union {value_type y, g, t;};
 86		union {value_type z, b, p;};
 87
 88#		if(defined(GLM_SWIZZLE))
 89			// Defines all he swizzle operator as functions
 90			GLM_SWIZZLE_GEN_REF_FROM_VEC3(T, detail::tvec3, detail::tref2, detail::tref3)
 91			GLM_SWIZZLE_GEN_VEC_FROM_VEC3(T, detail::tvec3, detail::tvec2, detail::tvec3, detail::tvec4)
 92#		endif//(defined(GLM_SWIZZLE))
 93#	else //(GLM_COMPONENT == GLM_COMPONENT_ONLY_XYZW)
 94		value_type x, y, z;
 95
 96#		if(defined(GLM_SWIZZLE))
 97			// Defines all he swizzle operator as functions
 98			GLM_SWIZZLE_GEN_REF_FROM_VEC3_COMP(T, detail::tvec3, detail::tref2, detail::tref3, x, y, z)
 99			GLM_SWIZZLE_GEN_VEC_FROM_VEC3_COMP(T, detail::tvec3, detail::tvec2, detail::tvec3, detail::tvec4, x, y, z)
100#		endif//(defined(GLM_SWIZZLE))
101#	endif//GLM_COMPONENT
102
103		//////////////////////////////////////
104		// Accesses
105
106		GLM_FUNC_DECL value_type & operator[](size_type i);
107		GLM_FUNC_DECL value_type const & operator[](size_type i) const;
108
109		//////////////////////////////////////
110		// Implicit basic constructors
111
112		GLM_FUNC_DECL tvec3();
113		GLM_FUNC_DECL tvec3(tvec3<T> const & v);
114
115		//////////////////////////////////////
116		// Explicit basic constructors
117
118		GLM_FUNC_DECL explicit tvec3(
119			ctor);
120		GLM_FUNC_DECL explicit tvec3(
121			value_type const & s);
122		GLM_FUNC_DECL explicit tvec3(
123			value_type const & s1, 
124			value_type const & s2, 
125			value_type const & s3);
126
127		//////////////////////////////////////
128		// Convertion scalar constructors
129
130		//! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
131		template <typename U> 
132		GLM_FUNC_DECL explicit tvec3(
133			U const & x);
134		//! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
135		template <typename U, typename V, typename W> 
136		GLM_FUNC_DECL explicit tvec3(
137			U const & x, 
138			V const & y, 
139			W const & z);			
140
141		//////////////////////////////////////
142		// Convertion vector constructors
143
144		//! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
145		template <typename A, typename B> 
146		GLM_FUNC_DECL explicit tvec3(tvec2<A> const & v, B const & s);
147		//! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
148		template <typename A, typename B> 
149		GLM_FUNC_DECL explicit tvec3(A const & s, tvec2<B> const & v);
150		//! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
151		template <typename U> 
152		GLM_FUNC_DECL explicit tvec3(tvec3<U> const & v);
153		//! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
154		template <typename U> 
155		GLM_FUNC_DECL explicit tvec3(tvec4<U> const & v);
156
157		//////////////////////////////////////
158		// Swizzle constructors
159
160		GLM_FUNC_DECL tvec3(tref3<T> const & r);
161
162		template <typename A, typename B> 
163		GLM_FUNC_DECL explicit tvec3(tref2<A> const & v, B const & s);
164
165		template <typename A, typename B> 
166		GLM_FUNC_DECL explicit tvec3(A const & s, tref2<B> const & v);
167
168        template <int E0, int E1, int E2>
169        GLM_FUNC_DECL tvec3(glm::detail::swizzle<3, T, tvec3<T>, E0, E1, E2, -1> const & that)
170        {
171            *this = that();
172        }
173
174        template <int E0, int E1>
175        GLM_FUNC_DECL tvec3(glm::detail::swizzle<2, T, tvec2<T>, E0, E1, -1, -2> const & v, T const & s)
176        {
177            *this = tvec3<T>(v(), s);
178        }
179
180        template <int E0, int E1>
181        GLM_FUNC_DECL tvec3(T const & s, glm::detail::swizzle<2, T, tvec2<T>, E0, E1, -1, -2> const & v)
182        {
183            *this = tvec3<T>(s, v());
184        }
185
186		//////////////////////////////////////
187		// Unary arithmetic operators
188
189		GLM_FUNC_DECL tvec3<T> & operator= (tvec3<T> const & v);
190		template <typename U> 
191		GLM_FUNC_DECL tvec3<T> & operator= (tvec3<U> const & v);
192
193		template <typename U> 
194		GLM_FUNC_DECL tvec3<T> & operator+=(U const & s);
195		template <typename U> 
196		GLM_FUNC_DECL tvec3<T> & operator+=(tvec3<U> const & v);
197		template <typename U> 
198		GLM_FUNC_DECL tvec3<T> & operator-=(U const & s);
199		template <typename U> 
200		GLM_FUNC_DECL tvec3<T> & operator-=(tvec3<U> const & v);
201		template <typename U> 
202		GLM_FUNC_DECL tvec3<T> & operator*=(U const & s);
203		template <typename U> 
204		GLM_FUNC_DECL tvec3<T> & operator*=(tvec3<U> const & v);
205		template <typename U> 
206		GLM_FUNC_DECL tvec3<T> & operator/=(U const & s);
207		template <typename U> 
208		GLM_FUNC_DECL tvec3<T> & operator/=(tvec3<U> const & v);
209		GLM_FUNC_DECL tvec3<T> & operator++();
210		GLM_FUNC_DECL tvec3<T> & operator--();
211
212		//////////////////////////////////////
213		// Unary bit operators
214
215		template <typename U>
216		GLM_FUNC_DECL tvec3<T> & operator%= (U const & s);
217		template <typename U>
218		GLM_FUNC_DECL tvec3<T> & operator%= (tvec3<U> const & v);
219		template <typename U>
220		GLM_FUNC_DECL tvec3<T> & operator&= (U const & s);
221		template <typename U>
222		GLM_FUNC_DECL tvec3<T> & operator&= (tvec3<U> const & v);
223		template <typename U>
224		GLM_FUNC_DECL tvec3<T> & operator|= (U const & s);
225		template <typename U>
226		GLM_FUNC_DECL tvec3<T> & operator|= (tvec3<U> const & v);
227		template <typename U>
228		GLM_FUNC_DECL tvec3<T> & operator^= (U const & s);
229		template <typename U>
230		GLM_FUNC_DECL tvec3<T> & operator^= (tvec3<U> const & v);
231		template <typename U>
232		GLM_FUNC_DECL tvec3<T> & operator<<=(U const & s);
233		template <typename U>
234		GLM_FUNC_DECL tvec3<T> & operator<<=(tvec3<U> const & v);
235		template <typename U>
236		GLM_FUNC_DECL tvec3<T> & operator>>=(U const & s);
237		template <typename U>
238		GLM_FUNC_DECL tvec3<T> & operator>>=(tvec3<U> const & v);
239
240		//////////////////////////////////////
241		// Swizzle operators
242
243		GLM_FUNC_DECL value_type swizzle(comp X) const;
244		GLM_FUNC_DECL tvec2<T> swizzle(comp X, comp Y) const;
245		GLM_FUNC_DECL tvec3<T> swizzle(comp X, comp Y, comp Z) const;
246		GLM_FUNC_DECL tvec4<T> swizzle(comp X, comp Y, comp Z, comp W) const;
247		GLM_FUNC_DECL tref2<T> swizzle(comp X, comp Y);
248		GLM_FUNC_DECL tref3<T> swizzle(comp X, comp Y, comp Z);
249	};
250
251	template <typename T>
252	struct tref3
253	{
254		GLM_FUNC_DECL tref3(T & x, T & y, T & z);
255		GLM_FUNC_DECL tref3(tref3<T> const & r);
256		GLM_FUNC_DECL explicit tref3(tvec3<T> const & v);
257
258		GLM_FUNC_DECL tref3<T> & operator= (tref3<T> const & r);
259		GLM_FUNC_DECL tref3<T> & operator= (tvec3<T> const & v);
260
261		GLM_FUNC_DECL tvec3<T> operator() ();
262
263		T & x;
264		T & y;
265		T & z;
266	};
267
268	GLM_DETAIL_IS_VECTOR(tvec3);
269} //namespace detail
270
271	/// @addtogroup core_precision
272	/// @{
273
274	/// 3 components vector of high precision floating-point numbers. 
275	/// There is no guarantee on the actual precision.
276	/// 
277	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.5 Vectors</a>
278	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
279	typedef detail::tvec3<highp_float>		highp_vec3;
280
281	/// 3 components vector of medium precision floating-point numbers. 
282	/// There is no guarantee on the actual precision.
283	/// 
284	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.5 Vectors</a>
285	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
286	typedef detail::tvec3<mediump_float>	mediump_vec3;
287
288	/// 3 components vector of low precision floating-point numbers. 
289	/// There is no guarantee on the actual precision.
290	/// 
291	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.5 Vectors</a>
292	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
293	typedef detail::tvec3<lowp_float>		lowp_vec3;
294
295	/// 3 components vector of high precision signed integer numbers. 
296	/// There is no guarantee on the actual precision.
297	/// 
298	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.5 Vectors</a>
299	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
300	typedef detail::tvec3<highp_int>		highp_ivec3;
301
302	/// 3 components vector of medium precision signed integer numbers. 
303	/// There is no guarantee on the actual precision.
304	/// 
305	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.5 Vectors</a>
306	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
307	typedef detail::tvec3<mediump_int>		mediump_ivec3;
308
309	/// 3 components vector of low precision signed integer numbers. 
310	/// There is no guarantee on the actual precision.
311	/// 
312	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.5 Vectors</a>
313	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
314	typedef detail::tvec3<lowp_int>			lowp_ivec3;
315
316	/// 3 components vector of high precision unsigned integer numbers. 
317	/// There is no guarantee on the actual precision.
318	/// 
319	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.5 Vectors</a>
320	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
321	typedef detail::tvec3<highp_uint>		highp_uvec3;
322
323	/// 3 components vector of medium precision unsigned integer numbers. 
324	/// There is no guarantee on the actual precision.
325	/// 
326	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.5 Vectors</a>
327	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
328	typedef detail::tvec3<mediump_uint>		mediump_uvec3;
329
330	/// 3 components vector of low precision unsigned integer numbers. 
331	/// There is no guarantee on the actual precision.
332	/// 
333	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.5 Vectors</a>
334	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
335	typedef detail::tvec3<lowp_uint>		lowp_uvec3;
336
337	/// @}
338}//namespace glm
339
340#ifndef GLM_EXTERNAL_TEMPLATE
341#include "type_vec3.inl"
342#endif//GLM_EXTERNAL_TEMPLATE
343
344#endif//glm_core_type_gentype3