source: trunk/src/lol/base/types.h @ 3723

Last change on this file since 3723 was 3723, checked in by sam, 7 years ago

math: add vec5, vec6, etc. types up to 12 for convenience.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://www.wtfpl.net/ for more details.
9//
10
11#pragma once
12
13#include <stdint.h>
14
15namespace lol
16{
17
18/* It’s nice to have single-word type names, so define this. */
19typedef long double ldouble;
20
21/* The “real” type used for real numbers. It’s a specialisation of the
22 * “Real” template class. */
23template<int N> class Real;
24typedef Real<16> real;
25
26/* The “half” type used for 16-bit floating point numbers. */
27class half;
28
29/*
30 * Forward declaration of vec_t, mat_t, cmplx_t, quat_t
31 */
32
33/* HACK: if this is declared int const, Visual Studio becomes unable
34 * to perform template argument deduction. */
35#define FULL_SWIZZLE (0)
36
37template<typename T, int N, int SWIZZLE = FULL_SWIZZLE> struct vec_t;
38template<typename T, int COLS, int ROWS> struct mat_t;
39template<typename T> struct cmplx_t;
40template<typename T> struct quat_t;
41template<typename T> struct dualquat_t;
42
43/*
44 * Generic GLSL-like type names
45 */
46
47#define _T(tleft, tright, suffix) \
48    typedef tleft half tright f16##suffix; \
49    typedef tleft float tright suffix; \
50    typedef tleft double tright d##suffix; \
51    typedef tleft ldouble tright f128##suffix; \
52    typedef tleft int8_t tright i8##suffix; \
53    typedef tleft uint8_t tright u8##suffix; \
54    typedef tleft int16_t tright i16##suffix; \
55    typedef tleft uint16_t tright u16##suffix; \
56    typedef tleft int32_t tright i##suffix; \
57    typedef tleft uint32_t tright u##suffix; \
58    typedef tleft int64_t tright i64##suffix; \
59    typedef tleft uint64_t tright u64##suffix; \
60    typedef tleft real tright r##suffix;
61
62/* Idiotic hack to put "," inside a macro argument */
63#define _C ,
64
65_T(vec_t<, _C 2>, vec2)
66_T(vec_t<, _C 3>, vec3)
67_T(vec_t<, _C 4>, vec4)
68_T(vec_t<, _C 5>, vec5)
69_T(vec_t<, _C 6>, vec6)
70_T(vec_t<, _C 7>, vec7)
71_T(vec_t<, _C 8>, vec8)
72_T(vec_t<, _C 9>, vec9)
73_T(vec_t<, _C 10>, vec10)
74_T(vec_t<, _C 11>, vec11)
75_T(vec_t<, _C 12>, vec12)
76
77_T(mat_t<, _C 2 _C 2>, mat2)
78_T(mat_t<, _C 3 _C 3>, mat3)
79_T(mat_t<, _C 4 _C 4>, mat4)
80
81_T(mat_t<, _C 2 _C 3>, mat2x3)
82_T(mat_t<, _C 2 _C 4>, mat2x4)
83_T(mat_t<, _C 3 _C 2>, mat3x2)
84_T(mat_t<, _C 3 _C 4>, mat3x4)
85_T(mat_t<, _C 4 _C 2>, mat4x2)
86_T(mat_t<, _C 4 _C 3>, mat4x3)
87
88_T(cmplx_t<, >, cmplx)
89_T(quat_t<, >, quat)
90_T(dualquat_t<, >, dualquat)
91
92#undef _C
93#undef _T
94
95/*
96 * HLSL/Cg-compliant type names
97 */
98
99typedef vec2 float2;
100typedef vec3 float3;
101typedef vec4 float4;
102typedef vec5 float5;
103typedef vec6 float6;
104typedef vec7 float7;
105typedef vec8 float8;
106typedef vec9 float9;
107typedef vec10 float10;
108typedef vec11 float11;
109typedef vec12 float12;
110typedef mat2 float2x2;
111typedef mat3 float3x3;
112typedef mat4 float4x4;
113typedef mat2x3 float2x3;
114typedef mat2x4 float2x4;
115typedef mat3x2 float3x2;
116typedef mat3x4 float3x4;
117typedef mat4x2 float4x2;
118typedef mat4x3 float4x3;
119
120typedef f16vec2 half2;
121typedef f16vec3 half3;
122typedef f16vec4 half4;
123typedef f16mat2 half2x2;
124typedef f16mat3 half3x3;
125typedef f16mat4 half4x4;
126typedef f16mat2x3 half2x3;
127typedef f16mat2x4 half2x4;
128typedef f16mat3x2 half3x2;
129typedef f16mat3x4 half3x4;
130typedef f16mat4x2 half4x2;
131typedef f16mat4x3 half4x3;
132
133typedef ivec2 int2;
134typedef ivec3 int3;
135typedef ivec4 int4;
136typedef ivec5 int5;
137typedef ivec6 int6;
138typedef ivec7 int7;
139typedef ivec8 int8;
140typedef ivec9 int9;
141typedef ivec10 int10;
142typedef ivec11 int11;
143typedef ivec12 int12;
144typedef imat2 int2x2;
145typedef imat3 int3x3;
146typedef imat4 int4x4;
147typedef imat2x3 int2x3;
148typedef imat2x4 int2x4;
149typedef imat3x2 int3x2;
150typedef imat3x4 int3x4;
151typedef imat4x2 int4x2;
152typedef imat4x3 int4x3;
153
154} /* namespace lol */
155
Note: See TracBrowser for help on using the repository browser.