1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// OpenGL Mathematics Copyright (c) 2006 G-Truc Creation (www.g-truc.net)
3
///////////////////////////////////////////////////////////////////////////////////////////////////
4
// Created : 2008-04-27
5
// Updated : 2008-05-24
6
// Licence : This source is under MIT License
7
// File : glm/gtx/string_cast.hpp
8
///////////////////////////////////////////////////////////////////////////////////////////////////
16
GLM_FUNC_QUALIFIER std::string format(const char* msg, ...)
18
std::size_t const STRING_BUFFER(4096);
19
char text[STRING_BUFFER];
27
#if((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER_VC >= GLM_COMPILER_VC2005))
28
vsprintf_s(text, STRING_BUFFER, msg, list);
30
vsprintf(text, msg, list);
34
return std::string(text);
37
static const char* True = "true";
38
static const char* False = "false";
41
////////////////////////////////
44
GLM_FUNC_QUALIFIER std::string to_string(detail::half const & x)
46
return detail::format("half(%2.4f)", float(x));
49
GLM_FUNC_QUALIFIER std::string to_string(float x)
51
return detail::format("float(%f)", x);
54
GLM_FUNC_QUALIFIER std::string to_string(double x)
56
return detail::format("double(%f)", x);
59
GLM_FUNC_QUALIFIER std::string to_string(int x)
61
return detail::format("int(%d)", x);
64
GLM_FUNC_QUALIFIER std::string to_string(unsigned int x)
66
return detail::format("uint(%d)", x);
69
////////////////////////////////
72
GLM_FUNC_QUALIFIER std::string to_string
74
detail::tvec2<bool> const & v
77
return detail::format("bvec2(%s, %s)",
78
v.x ? detail::True : detail::False,
79
v.y ? detail::True : detail::False);
82
GLM_FUNC_QUALIFIER std::string to_string
84
detail::tvec3<bool> const & v
87
return detail::format("bvec3(%s, %s, %s)",
88
v.x ? detail::True : detail::False,
89
v.y ? detail::True : detail::False,
90
v.z ? detail::True : detail::False);
93
GLM_FUNC_QUALIFIER std::string to_string
95
detail::tvec4<bool> const & v
98
return detail::format("bvec4(%s, %s, %s, %s)",
99
v.x ? detail::True : detail::False,
100
v.y ? detail::True : detail::False,
101
v.z ? detail::True : detail::False,
102
v.w ? detail::True : detail::False);
105
////////////////////////////////
109
GLM_FUNC_QUALIFIER std::string to_string
111
detail::tvec2<detail::half> const & v
114
return detail::format("hvec2(%2.4f, %2.4f)", v.x.toFloat(), v.y.toFloat());
118
GLM_FUNC_QUALIFIER std::string to_string
120
detail::tvec3<detail::half> const & v
123
return detail::format("hvec3(%2.4f, %2.4f, %2.4f)", v.x.toFloat(), v.y.toFloat(), v.z.toFloat());
127
GLM_FUNC_QUALIFIER std::string to_string
129
detail::tvec4<detail::half> const & v
132
return detail::format("hvec4(%2.4f, %2.4f, %2.4f, %2.4f)", v.x.toFloat(), v.y.toFloat(), v.z.toFloat(), v.w.toFloat());
135
////////////////////////////////
139
GLM_FUNC_QUALIFIER std::string to_string
141
detail::tvec2<float> const & v
144
return detail::format("fvec2(%f, %f)", v.x, v.y);
148
GLM_FUNC_QUALIFIER std::string to_string
150
detail::tvec3<float> const & v
153
return detail::format("fvec3(%f, %f, %f)", v.x, v.y, v.z);
157
GLM_FUNC_QUALIFIER std::string to_string
159
detail::tvec4<float> const & v
162
return detail::format("fvec4(%f, %f, %f, %f)", v.x, v.y, v.z, v.w);
165
////////////////////////////////
169
GLM_FUNC_QUALIFIER std::string to_string
171
detail::tvec2<double> const & v
174
return detail::format("dvec2(%f, %f)", v.x, v.y);
178
GLM_FUNC_QUALIFIER std::string to_string
180
detail::tvec3<double> const & v
183
return detail::format("dvec3(%f, %f, %f)", v.x, v.y, v.z);
187
GLM_FUNC_QUALIFIER std::string to_string
189
detail::tvec4<double> const & v
192
return detail::format("dvec4(%f, %f, %f, %f)", v.x, v.y, v.z, v.w);
195
////////////////////////////////
199
GLM_FUNC_QUALIFIER std::string to_string
201
detail::tvec2<int> const & v
204
return detail::format("ivec2(%d, %d)", v.x, v.y);
208
GLM_FUNC_QUALIFIER std::string to_string
210
detail::tvec3<int> const & v
213
return detail::format("ivec3(%d, %d, %d)", v.x, v.y, v.z);
217
GLM_FUNC_QUALIFIER std::string to_string
219
detail::tvec4<int> const & v
222
return detail::format("ivec4(%d, %d, %d, %d)", v.x, v.y, v.z, v.w);
225
////////////////////////////////
226
// Unsigned int vectors
229
GLM_FUNC_QUALIFIER std::string to_string
231
detail::tvec2<unsigned int> const & v
234
return detail::format("uvec2(%d, %d)", v.x, v.y);
238
GLM_FUNC_QUALIFIER std::string to_string
240
detail::tvec3<unsigned int> const & v
243
return detail::format("uvec3(%d, %d, %d)", v.x, v.y, v.z);
247
GLM_FUNC_QUALIFIER std::string to_string
249
detail::tvec4<unsigned int> const & v
252
return detail::format("uvec4(%d, %d, %d, %d)", v.x, v.y, v.z, v.w);
255
////////////////////////////////
259
GLM_FUNC_QUALIFIER std::string to_string
261
detail::tmat2x2<detail::half> const & m
264
return detail::format("hmat2x2((%f, %f), (%f, %f))",
265
m[0][0].toFloat(), m[0][1].toFloat(),
266
m[1][0].toFloat(), m[1][1].toFloat());
270
GLM_FUNC_QUALIFIER std::string to_string
272
detail::tmat2x3<detail::half> const & x
275
return detail::format("hmat2x3((%f, %f, %f), (%f, %f, %f))",
276
x[0][0].toFloat(), x[0][1].toFloat(), x[0][2].toFloat(),
277
x[1][0].toFloat(), x[1][1].toFloat(), x[1][2].toFloat());
281
GLM_FUNC_QUALIFIER std::string to_string
283
detail::tmat2x4<detail::half> const & x
286
return detail::format("hmat2x4((%f, %f, %f, %f), (%f, %f, %f, %f))",
287
x[0][0].toFloat(), x[0][1].toFloat(), x[0][2].toFloat(), x[0][3].toFloat(),
288
x[1][0].toFloat(), x[1][1].toFloat(), x[1][2].toFloat(), x[1][3].toFloat());
292
GLM_FUNC_QUALIFIER std::string to_string
294
detail::tmat3x2<detail::half> const & x
297
return detail::format("hmat3x2((%f, %f), (%f, %f), (%f, %f))",
298
x[0][0].toFloat(), x[0][1].toFloat(),
299
x[1][0].toFloat(), x[1][1].toFloat(),
300
x[2][0].toFloat(), x[2][1].toFloat());
304
GLM_FUNC_QUALIFIER std::string to_string
306
detail::tmat3x3<detail::half> const & x
309
return detail::format("hmat3x3((%f, %f, %f), (%f, %f, %f), (%f, %f, %f))",
310
x[0][0].toFloat(), x[0][1].toFloat(), x[0][2].toFloat(),
311
x[1][0].toFloat(), x[1][1].toFloat(), x[1][2].toFloat(),
312
x[2][0].toFloat(), x[2][1].toFloat(), x[2][2].toFloat());
316
GLM_FUNC_QUALIFIER std::string to_string
318
detail::tmat3x4<detail::half> const & x
321
return detail::format("hmat3x4((%f, %f, %f, %f), (%f, %f, %f, %f), (%f, %f, %f, %f))",
322
x[0][0].toFloat(), x[0][1].toFloat(), x[0][2].toFloat(), x[0][3].toFloat(),
323
x[1][0].toFloat(), x[1][1].toFloat(), x[1][2].toFloat(), x[1][3].toFloat(),
324
x[2][0].toFloat(), x[2][1].toFloat(), x[2][2].toFloat(), x[2][3].toFloat());
328
GLM_FUNC_QUALIFIER std::string to_string
330
detail::tmat4x2<detail::half> const & x
333
return detail::format("hmat4x2((%f, %f), (%f, %f), (%f, %f), (%f, %f))",
334
x[0][0].toFloat(), x[0][1].toFloat(),
335
x[1][0].toFloat(), x[1][1].toFloat(),
336
x[2][0].toFloat(), x[2][1].toFloat(),
337
x[3][0].toFloat(), x[3][1].toFloat());
341
GLM_FUNC_QUALIFIER std::string to_string
343
detail::tmat4x3<detail::half> const & x
346
return detail::format("hmat4x3((%f, %f, %f), (%f, %f, %f), (%f, %f, %f), (%f, %f, %f))",
347
x[0][0].toFloat(), x[0][1].toFloat(), x[0][2].toFloat(),
348
x[1][0].toFloat(), x[1][1].toFloat(), x[1][2].toFloat(),
349
x[2][0].toFloat(), x[2][1].toFloat(), x[2][2].toFloat(),
350
x[3][0].toFloat(), x[3][1].toFloat(), x[3][2].toFloat());
354
GLM_FUNC_QUALIFIER std::string to_string
356
detail::tmat4x4<detail::half> const & x
359
return detail::format("hmat4x4((%f, %f, %f, %f), (%f, %f, %f, %f), (%f, %f, %f, %f), (%f, %f, %f, %f))",
360
x[0][0].toFloat(), x[0][1].toFloat(), x[0][2].toFloat(), x[0][3].toFloat(),
361
x[1][0].toFloat(), x[1][1].toFloat(), x[1][2].toFloat(), x[1][3].toFloat(),
362
x[2][0].toFloat(), x[2][1].toFloat(), x[2][2].toFloat(), x[2][3].toFloat(),
363
x[3][0].toFloat(), x[3][1].toFloat(), x[3][2].toFloat(), x[3][3].toFloat());
366
////////////////////////////////
370
GLM_FUNC_QUALIFIER std::string to_string
372
detail::tmat2x2<float> const & x
375
return detail::format("mat2x2((%f, %f), (%f, %f))",
381
GLM_FUNC_QUALIFIER std::string to_string
383
detail::tmat2x3<float> const & x
386
return detail::format("mat2x3((%f, %f, %f), (%f, %f, %f))",
387
x[0][0], x[0][1], x[0][2],
388
x[1][0], x[1][1], x[1][2]);
392
GLM_FUNC_QUALIFIER std::string to_string
394
detail::tmat2x4<float> const & x
397
return detail::format("mat2x4((%f, %f, %f, %f), (%f, %f, %f, %f))",
398
x[0][0], x[0][1], x[0][2], x[0][3],
399
x[1][0], x[1][1], x[1][2], x[1][3]);
403
GLM_FUNC_QUALIFIER std::string to_string
405
detail::tmat3x2<float> const & x
408
return detail::format("mat3x2((%f, %f), (%f, %f), (%f, %f))",
415
GLM_FUNC_QUALIFIER std::string to_string
417
detail::tmat3x3<float> const & x
420
return detail::format("mat3x3((%f, %f, %f), (%f, %f, %f), (%f, %f, %f))",
421
x[0][0], x[0][1], x[0][2],
422
x[1][0], x[1][1], x[1][2],
423
x[2][0], x[2][1], x[2][2]);
427
GLM_FUNC_QUALIFIER std::string to_string
429
detail::tmat3x4<float> const & x
432
return detail::format("mat3x4((%f, %f, %f, %f), (%f, %f, %f, %f), (%f, %f, %f, %f))",
433
x[0][0], x[0][1], x[0][2], x[0][3],
434
x[1][0], x[1][1], x[1][2], x[1][3],
435
x[2][0], x[2][1], x[2][2], x[2][3]);
439
GLM_FUNC_QUALIFIER std::string to_string
441
detail::tmat4x2<float> const & x
444
return detail::format("mat4x2((%f, %f), (%f, %f), (%f, %f), (%f, %f))",
452
GLM_FUNC_QUALIFIER std::string to_string
454
detail::tmat4x3<float> const & x
457
return detail::format("mat4x3((%f, %f, %f), (%f, %f, %f), (%f, %f, %f), (%f, %f, %f))",
458
x[0][0], x[0][1], x[0][2],
459
x[1][0], x[1][1], x[1][2],
460
x[2][0], x[2][1], x[2][2],
461
x[3][0], x[3][1], x[3][2]);
465
GLM_FUNC_QUALIFIER std::string to_string
467
detail::tmat4x4<float> const & x
470
return detail::format("mat4x4((%f, %f, %f, %f), (%f, %f, %f, %f), (%f, %f, %f, %f), (%f, %f, %f, %f))",
471
x[0][0], x[0][1], x[0][2], x[0][3],
472
x[1][0], x[1][1], x[1][2], x[1][3],
473
x[2][0], x[2][1], x[2][2], x[2][3],
474
x[3][0], x[3][1], x[3][2], x[3][3]);
477
////////////////////////////////
481
GLM_FUNC_QUALIFIER std::string to_string
483
detail::tmat2x2<double> const & x
486
return detail::format("dmat2x2((%f, %f), (%f, %f))",
492
GLM_FUNC_QUALIFIER std::string to_string
494
detail::tmat2x3<double> const & x
497
return detail::format("dmat2x3((%f, %f, %f), (%f, %f, %f))",
498
x[0][0], x[0][1], x[0][2],
499
x[1][0], x[1][1], x[1][2]);
503
GLM_FUNC_QUALIFIER std::string to_string
505
detail::tmat2x4<double> const & x
508
return detail::format("dmat2x4((%f, %f, %f, %f), (%f, %f, %f, %f))",
509
x[0][0], x[0][1], x[0][2], x[0][3],
510
x[1][0], x[1][1], x[1][2], x[1][3]);
514
GLM_FUNC_QUALIFIER std::string to_string
516
detail::tmat3x2<double> const & x
519
return detail::format("dmat3x2((%f, %f), (%f, %f), (%f, %f))",
526
GLM_FUNC_QUALIFIER std::string to_string
528
detail::tmat3x3<double> const & x
531
return detail::format("dmat3x3((%f, %f, %f), (%f, %f, %f), (%f, %f, %f))",
532
x[0][0], x[0][1], x[0][2],
533
x[1][0], x[1][1], x[1][2],
534
x[2][0], x[2][1], x[2][2]);
538
GLM_FUNC_QUALIFIER std::string to_string
540
detail::tmat3x4<double> const & x
543
return detail::format("dmat3x4((%f, %f, %f, %f), (%f, %f, %f, %f), (%f, %f, %f, %f))",
544
x[0][0], x[0][1], x[0][2], x[0][3],
545
x[1][0], x[1][1], x[1][2], x[1][3],
546
x[2][0], x[2][1], x[2][2], x[2][3]);
550
GLM_FUNC_QUALIFIER std::string to_string
552
detail::tmat4x2<double> const & x
555
return detail::format("dmat4x2((%f, %f), (%f, %f), (%f, %f), (%f, %f))",
563
GLM_FUNC_QUALIFIER std::string to_string
565
detail::tmat4x3<double> const & x
568
return detail::format("dmat4x3((%f, %f, %f), (%f, %f, %f), (%f, %f, %f), (%f, %f, %f))",
569
x[0][0], x[0][1], x[0][2],
570
x[1][0], x[1][1], x[1][2],
571
x[2][0], x[2][1], x[2][2],
572
x[3][0], x[3][1], x[3][2]);
576
GLM_FUNC_QUALIFIER std::string to_string
578
detail::tmat4x4<double> const & x
581
return detail::format("dmat4x4((%f, %f, %f, %f), (%f, %f, %f, %f), (%f, %f, %f, %f), (%f, %f, %f, %f))",
582
x[0][0], x[0][1], x[0][2], x[0][3],
583
x[1][0], x[1][1], x[1][2], x[1][3],
584
x[2][0], x[2][1], x[2][2], x[2][3],
585
x[3][0], x[3][1], x[3][2], x[3][3]);