PageRenderTime 4ms CodeModel.GetById 4ms app.highlight 70ms RepoModel.GetById 1ms app.codeStats 0ms

/deps/glm-0.9.4.0/test/gtc/gtc_matrix_access.cpp

https://bitbucket.org/sturmh/dirtygraphics
C++ | 382 lines | 271 code | 103 blank | 8 comment | 62 complexity | bb5db3c5ea9b93b3cbd24714b1c5791a MD5 | raw file
  1///////////////////////////////////////////////////////////////////////////////////////////////////
  2// OpenGL Mathematics Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
  3///////////////////////////////////////////////////////////////////////////////////////////////////
  4// Created : 2010-09-16
  5// Updated : 2011-05-07
  6// Licence : This source is under MIT licence
  7// File    : test/gtc/matrix_access.cpp
  8///////////////////////////////////////////////////////////////////////////////////////////////////
  9
 10#include <glm/glm.hpp>
 11#include <glm/gtc/matrix_access.hpp>
 12
 13int test_mat2x2_row_set()
 14{
 15    int Error = 0;
 16    
 17    glm::mat2x2 m(1);
 18    
 19	m = glm::row(m, 0, glm::vec2( 0,  1));
 20	m = glm::row(m, 1, glm::vec2( 4,  5));
 21
 22    Error += glm::row(m, 0) == glm::vec2( 0,  1) ? 0 : 1;
 23    Error += glm::row(m, 1) == glm::vec2( 4,  5) ? 0 : 1;
 24
 25    return Error;
 26}
 27
 28int test_mat2x2_col_set()
 29{
 30    int Error = 0;
 31    
 32    glm::mat2x2 m(1);
 33    
 34	m = glm::column(m, 0, glm::vec2( 0,  1));
 35	m = glm::column(m, 1, glm::vec2( 4,  5));
 36
 37    Error += glm::column(m, 0) == glm::vec2( 0,  1) ? 0 : 1;
 38    Error += glm::column(m, 1) == glm::vec2( 4,  5) ? 0 : 1;
 39
 40    return Error;
 41}
 42
 43int test_mat2x3_row_set()
 44{
 45    int Error = 0;
 46    
 47    glm::mat2x3 m(1);
 48    
 49	m = glm::row(m, 0, glm::vec2( 0,  1));
 50	m = glm::row(m, 1, glm::vec2( 4,  5));
 51	m = glm::row(m, 2, glm::vec2( 8,  9));
 52
 53    Error += glm::row(m, 0) == glm::vec2( 0,  1) ? 0 : 1;
 54    Error += glm::row(m, 1) == glm::vec2( 4,  5) ? 0 : 1;
 55    Error += glm::row(m, 2) == glm::vec2( 8,  9) ? 0 : 1;
 56
 57    return Error;
 58}
 59
 60int test_mat2x3_col_set()
 61{
 62    int Error = 0;
 63    
 64    glm::mat2x3 m(1);
 65    
 66	m = glm::column(m, 0, glm::vec3( 0,  1,  2));
 67	m = glm::column(m, 1, glm::vec3( 4,  5,  6));
 68
 69    Error += glm::column(m, 0) == glm::vec3( 0,  1,  2) ? 0 : 1;
 70    Error += glm::column(m, 1) == glm::vec3( 4,  5,  6) ? 0 : 1;
 71
 72    return Error;
 73}
 74
 75int test_mat2x4_row_set()
 76{
 77    int Error = 0;
 78    
 79    glm::mat2x4 m(1);
 80    
 81	m = glm::row(m, 0, glm::vec2( 0,  1));
 82	m = glm::row(m, 1, glm::vec2( 4,  5));
 83	m = glm::row(m, 2, glm::vec2( 8,  9));
 84	m = glm::row(m, 3, glm::vec2(12, 13));
 85
 86    Error += glm::row(m, 0) == glm::vec2( 0,  1) ? 0 : 1;
 87    Error += glm::row(m, 1) == glm::vec2( 4,  5) ? 0 : 1;
 88    Error += glm::row(m, 2) == glm::vec2( 8,  9) ? 0 : 1;
 89	Error += glm::row(m, 3) == glm::vec2(12, 13) ? 0 : 1;
 90
 91    return Error;
 92}
 93
 94int test_mat2x4_col_set()
 95{
 96    int Error = 0;
 97    
 98    glm::mat2x4 m(1);
 99    
100	m = glm::column(m, 0, glm::vec4( 0,  1,  2, 3));
101	m = glm::column(m, 1, glm::vec4( 4,  5,  6, 7));
102
103    Error += glm::column(m, 0) == glm::vec4( 0,  1,  2, 3) ? 0 : 1;
104    Error += glm::column(m, 1) == glm::vec4( 4,  5,  6, 7) ? 0 : 1;
105
106    return Error;
107}
108
109int test_mat3x2_row_set()
110{
111    int Error = 0;
112    
113    glm::mat3x2 m(1);
114    
115	m = glm::row(m, 0, glm::vec3( 0,  1,  2));
116	m = glm::row(m, 1, glm::vec3( 4,  5,  6));
117
118    Error += glm::row(m, 0) == glm::vec3( 0,  1,  2) ? 0 : 1;
119    Error += glm::row(m, 1) == glm::vec3( 4,  5,  6) ? 0 : 1;
120
121    return Error;
122}
123
124int test_mat3x2_col_set()
125{
126    int Error = 0;
127    
128    glm::mat3x2 m(1);
129    
130	m = glm::column(m, 0, glm::vec2( 0,  1));
131	m = glm::column(m, 1, glm::vec2( 4,  5));
132	m = glm::column(m, 2, glm::vec2( 8,  9));
133
134    Error += glm::column(m, 0) == glm::vec2( 0,  1) ? 0 : 1;
135    Error += glm::column(m, 1) == glm::vec2( 4,  5) ? 0 : 1;
136    Error += glm::column(m, 2) == glm::vec2( 8,  9) ? 0 : 1;
137
138    return Error;
139}
140
141int test_mat3x3_row_set()
142{
143    int Error = 0;
144    
145    glm::mat3x3 m(1);
146    
147	m = glm::row(m, 0, glm::vec3( 0,  1,  2));
148	m = glm::row(m, 1, glm::vec3( 4,  5,  6));
149	m = glm::row(m, 2, glm::vec3( 8,  9, 10));
150
151    Error += glm::row(m, 0) == glm::vec3( 0,  1,  2) ? 0 : 1;
152    Error += glm::row(m, 1) == glm::vec3( 4,  5,  6) ? 0 : 1;
153    Error += glm::row(m, 2) == glm::vec3( 8,  9, 10) ? 0 : 1;
154
155    return Error;
156}
157
158int test_mat3x3_col_set()
159{
160    int Error = 0;
161    
162    glm::mat3x3 m(1);
163    
164	m = glm::column(m, 0, glm::vec3( 0,  1,  2));
165	m = glm::column(m, 1, glm::vec3( 4,  5,  6));
166	m = glm::column(m, 2, glm::vec3( 8,  9, 10));
167
168    Error += glm::column(m, 0) == glm::vec3( 0,  1,  2) ? 0 : 1;
169    Error += glm::column(m, 1) == glm::vec3( 4,  5,  6) ? 0 : 1;
170    Error += glm::column(m, 2) == glm::vec3( 8,  9, 10) ? 0 : 1;
171
172    return Error;
173}
174
175int test_mat3x4_row_set()
176{
177    int Error = 0;
178    
179    glm::mat3x4 m(1);
180    
181	m = glm::row(m, 0, glm::vec3( 0,  1,  2));
182	m = glm::row(m, 1, glm::vec3( 4,  5,  6));
183	m = glm::row(m, 2, glm::vec3( 8,  9, 10));
184	m = glm::row(m, 3, glm::vec3(12, 13, 14));
185
186    Error += glm::row(m, 0) == glm::vec3( 0,  1,  2) ? 0 : 1;
187    Error += glm::row(m, 1) == glm::vec3( 4,  5,  6) ? 0 : 1;
188    Error += glm::row(m, 2) == glm::vec3( 8,  9, 10) ? 0 : 1;
189	Error += glm::row(m, 3) == glm::vec3(12, 13, 14) ? 0 : 1;
190
191    return Error;
192}
193
194int test_mat3x4_col_set()
195{
196    int Error = 0;
197    
198    glm::mat3x4 m(1);
199    
200	m = glm::column(m, 0, glm::vec4( 0,  1,  2, 3));
201	m = glm::column(m, 1, glm::vec4( 4,  5,  6, 7));
202	m = glm::column(m, 2, glm::vec4( 8,  9, 10, 11));
203
204    Error += glm::column(m, 0) == glm::vec4( 0,  1,  2, 3) ? 0 : 1;
205    Error += glm::column(m, 1) == glm::vec4( 4,  5,  6, 7) ? 0 : 1;
206    Error += glm::column(m, 2) == glm::vec4( 8,  9, 10, 11) ? 0 : 1;
207
208    return Error;
209}
210
211int test_mat4x2_row_set()
212{
213    int Error = 0;
214    
215    glm::mat4x2 m(1);
216    
217	m = glm::row(m, 0, glm::vec4( 0,  1,  2,  3));
218	m = glm::row(m, 1, glm::vec4( 4,  5,  6,  7));
219
220    Error += glm::row(m, 0) == glm::vec4( 0,  1,  2,  3) ? 0 : 1;
221    Error += glm::row(m, 1) == glm::vec4( 4,  5,  6,  7) ? 0 : 1;
222
223    return Error;
224}
225
226int test_mat4x2_col_set()
227{
228    int Error = 0;
229    
230    glm::mat4x2 m(1);
231    
232	m = glm::column(m, 0, glm::vec2( 0,  1));
233	m = glm::column(m, 1, glm::vec2( 4,  5));
234	m = glm::column(m, 2, glm::vec2( 8,  9));
235	m = glm::column(m, 3, glm::vec2(12, 13));
236
237    Error += glm::column(m, 0) == glm::vec2( 0,  1) ? 0 : 1;
238    Error += glm::column(m, 1) == glm::vec2( 4,  5) ? 0 : 1;
239    Error += glm::column(m, 2) == glm::vec2( 8,  9) ? 0 : 1;
240    Error += glm::column(m, 3) == glm::vec2(12, 13) ? 0 : 1;
241
242    return Error;
243}
244
245int test_mat4x3_row_set()
246{
247    int Error = 0;
248    
249    glm::mat4x3 m(1);
250    
251	m = glm::row(m, 0, glm::vec4( 0,  1,  2,  3));
252	m = glm::row(m, 1, glm::vec4( 4,  5,  6,  7));
253	m = glm::row(m, 2, glm::vec4( 8,  9, 10, 11));
254
255    Error += glm::row(m, 0) == glm::vec4( 0,  1,  2,  3) ? 0 : 1;
256    Error += glm::row(m, 1) == glm::vec4( 4,  5,  6,  7) ? 0 : 1;
257    Error += glm::row(m, 2) == glm::vec4( 8,  9, 10, 11) ? 0 : 1;
258
259    return Error;
260}
261
262int test_mat4x3_col_set()
263{
264    int Error = 0;
265    
266    glm::mat4x3 m(1);
267    
268	m = glm::column(m, 0, glm::vec3( 0,  1,  2));
269	m = glm::column(m, 1, glm::vec3( 4,  5,  6));
270	m = glm::column(m, 2, glm::vec3( 8,  9, 10));
271	m = glm::column(m, 3, glm::vec3(12, 13, 14));
272
273    Error += glm::column(m, 0) == glm::vec3( 0,  1,  2) ? 0 : 1;
274    Error += glm::column(m, 1) == glm::vec3( 4,  5,  6) ? 0 : 1;
275    Error += glm::column(m, 2) == glm::vec3( 8,  9, 10) ? 0 : 1;
276    Error += glm::column(m, 3) == glm::vec3(12, 13, 14) ? 0 : 1;
277
278    return Error;
279}
280
281int test_mat4x4_row_set()
282{
283    int Error = 0;
284    
285    glm::mat4 m(1);
286    
287	m = glm::row(m, 0, glm::vec4( 0,  1,  2,  3));
288	m = glm::row(m, 1, glm::vec4( 4,  5,  6,  7));
289	m = glm::row(m, 2, glm::vec4( 8,  9, 10, 11));
290	m = glm::row(m, 3, glm::vec4(12, 13, 14, 15));
291
292    Error += glm::row(m, 0) == glm::vec4( 0,  1,  2,  3) ? 0 : 1;
293    Error += glm::row(m, 1) == glm::vec4( 4,  5,  6,  7) ? 0 : 1;
294    Error += glm::row(m, 2) == glm::vec4( 8,  9, 10, 11) ? 0 : 1;
295    Error += glm::row(m, 3) == glm::vec4(12, 13, 14, 15) ? 0 : 1;
296
297    return Error;
298}
299
300int test_mat4x4_col_set()
301{
302    int Error = 0;
303    
304    glm::mat4 m(1);
305    
306	m = glm::column(m, 0, glm::vec4( 0,  1,  2,  3));
307	m = glm::column(m, 1, glm::vec4( 4,  5,  6,  7));
308	m = glm::column(m, 2, glm::vec4( 8,  9, 10, 11));
309	m = glm::column(m, 3, glm::vec4(12, 13, 14, 15));
310
311    Error += glm::column(m, 0) == glm::vec4( 0,  1,  2,  3) ? 0 : 1;
312    Error += glm::column(m, 1) == glm::vec4( 4,  5,  6,  7) ? 0 : 1;
313    Error += glm::column(m, 2) == glm::vec4( 8,  9, 10, 11) ? 0 : 1;
314    Error += glm::column(m, 3) == glm::vec4(12, 13, 14, 15) ? 0 : 1;
315
316    return Error;
317}
318
319int test_mat4x4_row_get()
320{
321    int Error = 0;
322    
323    glm::mat4 m(1);
324    
325    glm::vec4 A = glm::row(m, 0);
326    Error += A == glm::vec4(1, 0, 0, 0) ? 0 : 1;
327    glm::vec4 B = glm::row(m, 1);
328    Error += B == glm::vec4(0, 1, 0, 0) ? 0 : 1;
329    glm::vec4 C = glm::row(m, 2);
330    Error += C == glm::vec4(0, 0, 1, 0) ? 0 : 1;
331    glm::vec4 D = glm::row(m, 3);
332    Error += D == glm::vec4(0, 0, 0, 1) ? 0 : 1;
333
334    return Error;
335}
336
337int test_mat4x4_col_get()
338{
339    int Error = 0;
340    
341    glm::mat4 m(1);
342    
343    glm::vec4 A = glm::column(m, 0);
344    Error += A == glm::vec4(1, 0, 0, 0) ? 0 : 1;
345    glm::vec4 B = glm::column(m, 1);
346    Error += B == glm::vec4(0, 1, 0, 0) ? 0 : 1;
347    glm::vec4 C = glm::column(m, 2);
348    Error += C == glm::vec4(0, 0, 1, 0) ? 0 : 1;
349    glm::vec4 D = glm::column(m, 3);
350    Error += D == glm::vec4(0, 0, 0, 1) ? 0 : 1;
351    
352    return Error;    
353}
354
355int main()
356{
357	int Error = 0;
358
359	Error += test_mat2x2_row_set();
360    Error += test_mat2x2_col_set();
361	Error += test_mat2x3_row_set();
362    Error += test_mat2x3_col_set();
363	Error += test_mat2x4_row_set();
364    Error += test_mat2x4_col_set();
365	Error += test_mat3x2_row_set();
366    Error += test_mat3x2_col_set();
367	Error += test_mat3x3_row_set();
368    Error += test_mat3x3_col_set();
369	Error += test_mat3x4_row_set();
370    Error += test_mat3x4_col_set();
371	Error += test_mat4x2_row_set();
372    Error += test_mat4x2_col_set();
373	Error += test_mat4x3_row_set();
374    Error += test_mat4x3_col_set();
375	Error += test_mat4x4_row_set();
376    Error += test_mat4x4_col_set();
377
378    Error += test_mat4x4_row_get();
379    Error += test_mat4x4_col_get();
380
381	return Error;
382}