summaryrefslogtreecommitdiff
path: root/src/glm/core/type_vec3.hpp
blob: 8864d7db3750e4823845b514f67eabc4823ab3db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2008-08-22
// Updated : 2010-02-03
// Licence : This source is under MIT License
// File    : glm/core/type_tvec3.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef glm_core_type_gentype3
#define glm_core_type_gentype3

#include "type_vec.hpp"
#include "type_float.hpp"
#include "type_int.hpp"
#include "type_size.hpp"
#include "_swizzle.hpp"

namespace glm{
namespace detail
{
	template <typename T> struct tref2;
	template <typename T> struct tref3;
	template <typename T> struct tref4;
	template <typename T> struct tvec2;
	template <typename T> struct tvec4;

	//! Basic 3D vector type.
	//! \ingroup core_template
	template <typename T>
	struct tvec3
	{	
		enum ctor{null};

		typedef T value_type;
		typedef std::size_t size_type;
		GLM_FUNC_DECL size_type length() const;
		static GLM_FUNC_DECL size_type value_size();

		typedef tvec3<T> type;
		typedef tvec3<bool> bool_type;

		//////////////////////////////////////
		// Data

#	if(GLM_COMPONENT == GLM_COMPONENT_ONLY_XYZW)
		value_type x, y, z;
#	elif(GLM_COMPONENT == GLM_COMPONENT_MS_EXT)
		union 
		{
			struct{value_type x, y, z;};
			struct{value_type r, g, b;};
			struct{value_type s, t, p;};
		};
#	else//(GLM_COMPONENT == GLM_COMPONENT_GLSL_NAMES)
		union {value_type x, r, s;};
		union {value_type y, g, t;};
		union {value_type z, b, p;};
#	endif//GLM_COMPONENT

		//////////////////////////////////////
		// Accesses

		GLM_FUNC_DECL value_type & operator[](size_type i);
		GLM_FUNC_DECL value_type const & operator[](size_type i) const;

		//////////////////////////////////////
		// Implicit basic constructors

		GLM_FUNC_DECL tvec3();
		GLM_FUNC_DECL tvec3(tvec3<T> const & v);

		//////////////////////////////////////
		// Explicit basic constructors

		GLM_FUNC_DECL explicit tvec3(
			ctor);
		GLM_FUNC_DECL explicit tvec3(
			value_type const & s);
		GLM_FUNC_DECL explicit tvec3(
			value_type const & s1, 
			value_type const & s2, 
			value_type const & s3);

		//////////////////////////////////////
		// Swizzle constructors

		GLM_FUNC_DECL tvec3(tref3<T> const & r);

		//////////////////////////////////////
		// Convertion scalar constructors

		//! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
		template <typename U> 
		GLM_FUNC_DECL explicit tvec3(
			U const & x);
		//! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
		template <typename U, typename V, typename W> 
		GLM_FUNC_DECL explicit tvec3(
			U const & x, 
			V const & y, 
			W const & z);			

		//////////////////////////////////////
		// Convertion vector constructors

		//! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
		template <typename A, typename B> 
		GLM_FUNC_DECL explicit tvec3(tvec2<A> const & v, B const & s);
		//! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
		template <typename A, typename B> 
		GLM_FUNC_DECL explicit tvec3(A const & s, tvec2<B> const & v);
		//! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
		template <typename U> 
		GLM_FUNC_DECL explicit tvec3(tvec3<U> const & v);
		//! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
		template <typename U> 
		GLM_FUNC_DECL explicit tvec3(tvec4<U> const & v);

		//////////////////////////////////////
		// Unary arithmetic operators

		GLM_FUNC_DECL tvec3<T> & operator= (tvec3<T> const & v);
		template <typename U> 
		GLM_FUNC_DECL tvec3<T> & operator= (tvec3<U> const & v);

		template <typename U> 
		GLM_FUNC_DECL tvec3<T> & operator+=(U const & s);
		template <typename U> 
		GLM_FUNC_DECL tvec3<T> & operator+=(tvec3<U> const & v);
		template <typename U> 
		GLM_FUNC_DECL tvec3<T> & operator-=(U const & s);
		template <typename U> 
		GLM_FUNC_DECL tvec3<T> & operator-=(tvec3<U> const & v);
		template <typename U> 
		GLM_FUNC_DECL tvec3<T> & operator*=(U const & s);
		template <typename U> 
		GLM_FUNC_DECL tvec3<T> & operator*=(tvec3<U> const & v);
		template <typename U> 
		GLM_FUNC_DECL tvec3<T> & operator/=(U const & s);
		template <typename U> 
		GLM_FUNC_DECL tvec3<T> & operator/=(tvec3<U> const & v);
		GLM_FUNC_DECL tvec3<T> & operator++();
		GLM_FUNC_DECL tvec3<T> & operator--();

		//////////////////////////////////////
		// Unary bit operators

		template <typename U>
		GLM_FUNC_DECL tvec3<T> & operator%= (U const & s);
		template <typename U>
		GLM_FUNC_DECL tvec3<T> & operator%= (tvec3<U> const & v);
		template <typename U>
		GLM_FUNC_DECL tvec3<T> & operator&= (U const & s);
		template <typename U>
		GLM_FUNC_DECL tvec3<T> & operator&= (tvec3<U> const & v);
		template <typename U>
		GLM_FUNC_DECL tvec3<T> & operator|= (U const & s);
		template <typename U>
		GLM_FUNC_DECL tvec3<T> & operator|= (tvec3<U> const & v);
		template <typename U>
		GLM_FUNC_DECL tvec3<T> & operator^= (U const & s);
		template <typename U>
		GLM_FUNC_DECL tvec3<T> & operator^= (tvec3<U> const & v);
		template <typename U>
		GLM_FUNC_DECL tvec3<T> & operator<<=(U const & s);
		template <typename U>
		GLM_FUNC_DECL tvec3<T> & operator<<=(tvec3<U> const & v);
		template <typename U>
		GLM_FUNC_DECL tvec3<T> & operator>>=(U const & s);
		template <typename U>
		GLM_FUNC_DECL tvec3<T> & operator>>=(tvec3<U> const & v);

		//////////////////////////////////////
		// Swizzle operators

		GLM_FUNC_DECL value_type swizzle(comp X) const;
		GLM_FUNC_DECL tvec2<T> swizzle(comp X, comp Y) const;
		GLM_FUNC_DECL tvec3<T> swizzle(comp X, comp Y, comp Z) const;
		GLM_FUNC_DECL tvec4<T> swizzle(comp X, comp Y, comp Z, comp W) const;
		GLM_FUNC_DECL tref3<T> swizzle(comp X, comp Y, comp Z);
	};

	template <typename T>
	struct tref3
	{
		GLM_FUNC_DECL tref3(T & x, T & y, T & z);
		GLM_FUNC_DECL tref3(tref3<T> const & r);
		GLM_FUNC_DECL tref3(tvec3<T> const & v);

		GLM_FUNC_DECL tref3<T> & operator= (tref3<T> const & r);
		GLM_FUNC_DECL tref3<T> & operator= (tvec3<T> const & v);

		T & x;
		T & y;
		T & z;
	};

	GLM_DETAIL_IS_VECTOR(tvec3);
} //namespace detail

namespace core{
namespace type{
namespace precision
{
	//! 3 components vector of high precision floating-point numbers. 
	//! There is no guarantee on the actual precision.
	//! From GLSL 1.30.8 specification, section 4.5.2 Precision Qualifiers.
	//! \ingroup core_precision
	typedef detail::tvec3<highp_float>		highp_vec3;

	//! 3 components vector of medium precision floating-point numbers. 
	//! There is no guarantee on the actual precision.
	//! From GLSL 1.30.8 specification, section 4.5.2 Precision Qualifiers.
	//! \ingroup core_precision
	typedef detail::tvec3<mediump_float>	mediump_vec3;

	//! 3 components vector of low precision floating-point numbers. 
	//! There is no guarantee on the actual precision.
	//! From GLSL 1.30.8 specification, section 4.5.2 Precision Qualifiers.
	//! \ingroup core_precision
	typedef detail::tvec3<lowp_float>		lowp_vec3;

	//! 3 components vector of high precision signed integer numbers. 
	//! There is no guarantee on the actual precision.
	//! From GLSL 1.30.8 specification, section 4.1.5 Precision Qualifiers.
	//! \ingroup core_precision
	typedef detail::tvec3<highp_int>		highp_ivec3;

	//! 3 components vector of medium precision signed integer numbers. 
	//! There is no guarantee on the actual precision.
	//! From GLSL 1.30.8 specification, section 4.1.5 Precision Qualifiers.
	//! \ingroup core_precision
	typedef detail::tvec3<mediump_int>		mediump_ivec3;

	//! 3 components vector of low precision signed integer numbers. 
	//! There is no guarantee on the actual precision.
	//! From GLSL 1.30.8 specification, section 4.1.5 Precision Qualifiers.
	//! \ingroup core_precision
	typedef detail::tvec3<lowp_int>			lowp_ivec3;

	//! 3 components vector of high precision unsigned integer numbers. 
	//! There is no guarantee on the actual precision.
	//! From GLSL 1.30.8 specification, section 4.1.5 Precision Qualifiers.
	//! \ingroup core_precision
	typedef detail::tvec3<highp_uint>		highp_uvec3;

	//! 3 components vector of medium precision unsigned integer numbers. 
	//! There is no guarantee on the actual precision.
	//! From GLSL 1.30.8 specification, section 4.1.5 Precision Qualifiers.
	//! \ingroup core_precision
	typedef detail::tvec3<mediump_uint>		mediump_uvec3;

	//! 3 components vector of low precision unsigned integer numbers. 
	//! There is no guarantee on the actual precision.
	//! From GLSL 1.30.8 specification, section 4.1.5 Precision Qualifiers.
	//! \ingroup core_precision
	typedef detail::tvec3<lowp_uint>		lowp_uvec3;

}//namespace precision
}//namespace type
}//namespace core
}//namespace glm

#ifndef GLM_EXTERNAL_TEMPLATE
#include "type_vec3.inl"
#endif//GLM_EXTERNAL_TEMPLATE

#endif//glm_core_type_gentype3