PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 38ms RepoModel.GetById 2ms app.codeStats 0ms

/ExternalLibs/glm-0.9.2.1/test/gtc/gtc_matrix_access.cpp

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