Kohi Game Engine
math_types.h
Go to the documentation of this file.
1 
12 #pragma once
13 
14 #include "defines.h"
15 
16 typedef enum axis_3d {
17  AXIS_X = 0,
18  AXIS_Y = 1,
19  AXIS_Z = 2,
25  AXIS_ZY
27 
31 typedef union vec2_u {
34  struct {
35  union {
37  f32 x,
39  r,
41  s,
43  u;
44  };
45  union {
47  f32 y,
49  g,
51  t,
53  v;
54  };
55  };
56 } vec2;
57 
61 typedef union uvec2_u {
64  union {
65  struct {
66  union {
68  u32 x,
70  r,
72  s;
73  };
74  union {
76  u32 y,
78  g,
80  t;
81  };
82  };
83  };
85 
89 typedef union ivec2_u {
92  union {
93  struct {
94  union {
96  i32 x,
98  r,
100  s;
101  };
102  union {
106  g,
108  t;
109  };
110  };
111  };
113 
117 typedef union vec3_u {
120  struct {
121  union {
125  r,
127  s,
129  u;
130  };
131  union {
135  g,
137  t,
139  v;
140  };
141  union {
145  b,
147  p,
149  w;
150  };
151  };
153 
157 typedef union uvec3_u {
160  union {
161  struct {
162  union {
166  r,
168  s;
169  };
170  union {
174  g,
176  t;
177  };
178  union {
182  b,
184  p;
185  };
186  };
187  };
189 
193 typedef union ivec3_u {
196  union {
197  struct {
198  union {
202  r,
204  s;
205  };
206  union {
210  g,
212  t;
213  };
214  union {
218  b,
220  p;
221  };
222  };
223  };
225 
229 typedef union vec4_u {
232  union {
233  struct {
234  union {
238  r,
240  s;
241  };
242  union {
246  g,
248  t;
249  };
250  union {
254  b,
256  p,
259  };
260  union {
264  a,
266  q,
269  };
270  };
271  };
273 
275 typedef vec4 quat;
276 
278 typedef vec4 rect_2d;
279 
283 typedef union uvec4_u {
286  union {
287  struct {
288  union {
292  r,
294  s;
295  };
296  union {
300  g,
302  t;
303  };
304  union {
308  b,
310  p,
313  };
314  union {
318  a,
320  q,
323  };
324  };
325  };
327 
331 typedef union ivec4_u {
334  union {
335  struct {
336  union {
340  r,
342  s;
343  };
344  union {
348  g,
350  t;
351  };
352  union {
356  b,
358  p,
361  };
362  union {
366  a,
368  q,
371  };
372  };
373  };
375 
377 typedef union mat3_u {
379  f32 data[12];
381 
383 typedef union mat4_u {
385  f32 data[16];
387 
391 typedef struct extents_2d {
397 
401 typedef struct extents_3d {
407 
411 typedef extents_3d aabb;
412 
413 typedef struct obb {
415  // Orthonormal basis vectors
416  vec3 axis[3];
418 } obb;
419 
423 typedef struct vertex_3d {
435 
439 typedef struct skinned_vertex_3d {
455 
459 typedef struct vertex_2d {
465 
469 typedef struct position_vertex_3d {
473 
477 typedef struct colour_vertex_3d {
483 
484 typedef struct plane_3d {
488 
489 #define KFRUSTUM_SIDE_COUNT 6
490 
491 typedef enum kfrustum_side {
499 
500 typedef struct kfrustum {
501  // Top, bottom, right, left, far, near
504 
508 typedef union vec2i_t {
511  struct {
512  union {
516  r,
518  s,
520  u;
521  };
522  union {
526  g,
528  t,
530  v;
531  };
532  };
534 
538 typedef union vec3i_t {
541  union {
542  struct {
543  union {
547  r,
549  s;
550  };
551  union {
555  g,
557  t;
558  };
559  union {
563  b,
565  p;
566  };
567  };
568  };
570 
574 typedef union vec4i_t {
577  union {
578  struct {
579  union {
583  r,
585  s;
586  };
587  union {
591  g,
593  t;
594  };
595  union {
599  b,
601  p,
604  };
605  union {
609  a,
611  q,
614  };
615  };
616  };
618 
619 // integer-based 2D rectangle.
620 typedef vec4i rect_2di;
621 
622 typedef struct triangle {
625 
626 typedef enum ray_flag_bits {
630 
631 typedef u32 ray_flags;
632 
638 typedef struct ray {
643 } ray;
644 
645 typedef enum raycast_hit_type {
648  // Was a BVH AABB hit, but against a base node.
651 
652 typedef struct raycast_hit {
659 
660 typedef struct raycast_result {
664 
665 typedef struct ksphere {
This file contains global type definitions which are used throughout the entire engine and applicatio...
unsigned int u32
Unsigned 32-bit integer.
Definition: defines.h:27
float f32
32-bit floating point number
Definition: defines.h:49
signed int i32
Signed 32-bit integer.
Definition: defines.h:41
unsigned long long u64
Unsigned 64-bit integer.
Definition: defines.h:30
struct skinned_vertex_3d skinned_vertex_3d
Represents a single skinned vertex in 3D space.
u32 ray_flags
Definition: math_types.h:631
union ivec4_u ivec4
A 4-element vector of signed ints.
union uvec3_u uvec3
A 3-element vector of unsigned ints.
union mat3_u mat3
A 3x3 matrix.
struct ray ray
Represents a line which starts at an origin and proceed infinitely in the given direction....
struct kfrustum kfrustum
extents_3d aabb
Axis-aligned bounding box.
Definition: math_types.h:411
struct ksphere ksphere
struct raycast_hit raycast_hit
#define KFRUSTUM_SIDE_COUNT
Definition: math_types.h:489
struct triangle triangle
struct extents_2d extents_2d
Represents the extents of a 2d object.
struct vertex_2d vertex_2d
Represents a single vertex in 2D space.
union vec2_u vec2
A 2-element vector.
union vec4i_t vec4i
A 4-element integer-based vector.
axis_3d
Definition: math_types.h:16
@ AXIS_ZY
Definition: math_types.h:25
@ AXIS_XY
Definition: math_types.h:20
@ AXIS_X
Definition: math_types.h:17
@ AXIS_ZX
Definition: math_types.h:24
@ AXIS_Y
Definition: math_types.h:18
@ AXIS_XZ
Definition: math_types.h:21
@ AXIS_YZ
Definition: math_types.h:23
@ AXIS_Z
Definition: math_types.h:19
@ AXIS_YX
Definition: math_types.h:22
union vec4_u vec4
A 4-element vector.
union uvec2_u uvec2
A 2-element vector of unsigned ints.
vec4i rect_2di
Definition: math_types.h:620
union vec3_u vec3
A 3-element vector.
union mat4_u mat4
a 4x4 matrix, typically used to represent object transformations.
union uvec4_u uvec4
A 4-element vector of unsigned ints.
struct extents_3d extents_3d
Represents the extents of a 3d object.
raycast_hit_type
Definition: math_types.h:645
@ RAYCAST_HIT_TYPE_SURFACE
Definition: math_types.h:647
@ RAYCAST_HIT_TYPE_BVH_AABB
Definition: math_types.h:646
@ RAYCAST_HIT_TYPE_BVH_AABB_BASE_NODE
Definition: math_types.h:649
struct plane_3d plane_3d
struct obb obb
struct vertex_3d vertex_3d
Represents a single vertex in 3D space.
struct raycast_result raycast_result
union ivec2_u ivec2
A 2-element vector of signed ints.
union ivec3_u ivec3
A 3-element vector of signed ints.
vec4 rect_2d
A 2d rectangle.
Definition: math_types.h:278
ray_flag_bits
Definition: math_types.h:626
@ RAY_FLAG_IGNORE_IF_INSIDE_BIT
Definition: math_types.h:628
@ RAY_FLAG_NONE
Definition: math_types.h:627
struct position_vertex_3d position_vertex_3d
struct colour_vertex_3d colour_vertex_3d
Represents a single vertex in 3D space with position and colour data only.
kfrustum_side
Definition: math_types.h:491
@ KFRUSTUM_SIDE_NEAR
Definition: math_types.h:497
@ KFRUSTUM_SIDE_FAR
Definition: math_types.h:496
@ KFRUSTUM_SIDE_LEFT
Definition: math_types.h:495
@ KFRUSTUM_SIDE_RIGHT
Definition: math_types.h:494
@ KFRUSTUM_SIDE_TOP
Definition: math_types.h:492
@ KFRUSTUM_SIDE_BOTTOM
Definition: math_types.h:493
union vec3i_t vec3i
A 3-element integer-based vector.
union vec2i_t vec2i
A 2-element integer-based vector.
vec4 quat
A quaternion, used to represent rotational orientation.
Definition: math_types.h:275
Represents a single vertex in 3D space with position and colour data only.
Definition: math_types.h:477
vec4 position
The position of the vertex. w is ignored.
Definition: math_types.h:479
vec4 colour
The colour of the vertex.
Definition: math_types.h:481
Represents the extents of a 2d object.
Definition: math_types.h:391
vec2 max
The maximum extents of the object.
Definition: math_types.h:395
vec2 min
The minimum extents of the object.
Definition: math_types.h:393
Represents the extents of a 3d object.
Definition: math_types.h:401
vec3 min
The minimum extents of the object.
Definition: math_types.h:403
vec3 max
The maximum extents of the object.
Definition: math_types.h:405
Definition: math_types.h:500
plane_3d sides[KFRUSTUM_SIDE_COUNT]
Definition: math_types.h:502
Definition: math_types.h:665
vec3 position
Definition: math_types.h:666
f32 radius
Definition: math_types.h:667
Definition: math_types.h:413
vec3 center
Definition: math_types.h:414
vec3 axis[3]
Definition: math_types.h:416
vec3 half_extents
Definition: math_types.h:417
Definition: math_types.h:484
f32 distance
Definition: math_types.h:486
vec3 normal
Definition: math_types.h:485
Definition: math_types.h:469
vec4 position
The position of the vertex. w is ignored.
Definition: math_types.h:471
Represents a line which starts at an origin and proceed infinitely in the given direction....
Definition: math_types.h:638
f32 max_distance
Definition: math_types.h:641
vec3 origin
Definition: math_types.h:639
vec3 direction
Definition: math_types.h:640
ray_flags flags
Definition: math_types.h:642
Definition: math_types.h:652
vec3 position
Definition: math_types.h:656
f32 distance
Definition: math_types.h:654
vec3 normal
Definition: math_types.h:657
u64 user
Definition: math_types.h:655
raycast_hit_type type
Definition: math_types.h:653
Definition: math_types.h:660
raycast_hit * hits
Darray of hits. Not set if there are no hits.
Definition: math_types.h:662
Represents a single skinned vertex in 3D space.
Definition: math_types.h:439
vec3 position
The position of the vertex.
Definition: math_types.h:441
vec3 normal
The normal of the vertex.
Definition: math_types.h:443
vec2 texcoord
The texture coordinate of the vertex.
Definition: math_types.h:445
ivec4 bone_ids
Bone indices that will influence this index. -1 means no bone.
Definition: math_types.h:451
vec4 tangent
The tangent of the vertex.
Definition: math_types.h:449
vec4 weights
Weights from each bone that will influence this index.
Definition: math_types.h:453
vec4 colour
The colour of the vertex.
Definition: math_types.h:447
Definition: math_types.h:622
vec3 verts[3]
Definition: math_types.h:623
Represents a single vertex in 2D space.
Definition: math_types.h:459
vec2 position
The position of the vertex.
Definition: math_types.h:461
vec2 texcoord
The texture coordinate of the vertex.
Definition: math_types.h:463
Represents a single vertex in 3D space.
Definition: math_types.h:423
vec3 position
The position of the vertex.
Definition: math_types.h:425
vec3 normal
The normal of the vertex.
Definition: math_types.h:427
vec2 texcoord
The texture coordinate of the vertex.
Definition: math_types.h:429
vec4 tangent
The tangent of the vertex.
Definition: math_types.h:433
vec4 colour
The colour of the vertex.
Definition: math_types.h:431
A 2-element vector of signed ints.
Definition: math_types.h:89
i32 r
The first element.
Definition: math_types.h:98
i32 g
The third element.
Definition: math_types.h:106
i32 y
The second element.
Definition: math_types.h:104
i32 s
The first element.
Definition: math_types.h:100
i32 t
The third element.
Definition: math_types.h:108
i32 elements[2]
An array of x, y, z.
Definition: math_types.h:91
i32 x
The first element.
Definition: math_types.h:96
A 3-element vector of signed ints.
Definition: math_types.h:193
i32 r
The first element.
Definition: math_types.h:202
i32 g
The third element.
Definition: math_types.h:210
i32 elements[3]
An array of x, y, z.
Definition: math_types.h:195
i32 y
The second element.
Definition: math_types.h:208
i32 b
The third element.
Definition: math_types.h:218
i32 s
The first element.
Definition: math_types.h:204
i32 p
The third element.
Definition: math_types.h:220
i32 t
The third element.
Definition: math_types.h:212
i32 z
The third element.
Definition: math_types.h:216
i32 x
The first element.
Definition: math_types.h:200
A 4-element vector of signed ints.
Definition: math_types.h:331
i32 w
The fourth element.
Definition: math_types.h:364
i32 r
The first element.
Definition: math_types.h:340
i32 g
The third element.
Definition: math_types.h:348
i32 elements[4]
An array of x, y, z, w.
Definition: math_types.h:333
i32 y
The second element.
Definition: math_types.h:346
i32 height
The fourth element.
Definition: math_types.h:370
i32 width
The third element.
Definition: math_types.h:360
i32 b
The third element.
Definition: math_types.h:356
i32 s
The first element.
Definition: math_types.h:342
i32 a
The fourth element.
Definition: math_types.h:366
i32 p
The third element.
Definition: math_types.h:358
i32 t
The third element.
Definition: math_types.h:350
i32 z
The third element.
Definition: math_types.h:354
i32 q
The fourth element.
Definition: math_types.h:368
i32 x
The first element.
Definition: math_types.h:338
A 3x3 matrix.
Definition: math_types.h:377
f32 data[12]
The matrix elements.
Definition: math_types.h:379
a 4x4 matrix, typically used to represent object transformations.
Definition: math_types.h:383
f32 data[16]
The matrix elements.
Definition: math_types.h:385
A 2-element vector of unsigned ints.
Definition: math_types.h:61
u32 y
The second element.
Definition: math_types.h:76
u32 s
The first element.
Definition: math_types.h:72
u32 t
The third element.
Definition: math_types.h:80
u32 r
The first element.
Definition: math_types.h:70
u32 elements[2]
An array of x, y, z.
Definition: math_types.h:63
u32 g
The third element.
Definition: math_types.h:78
u32 x
The first element.
Definition: math_types.h:68
A 3-element vector of unsigned ints.
Definition: math_types.h:157
u32 y
The second element.
Definition: math_types.h:172
u32 b
The third element.
Definition: math_types.h:182
u32 s
The first element.
Definition: math_types.h:168
u32 t
The third element.
Definition: math_types.h:176
u32 elements[3]
An array of x, y, z.
Definition: math_types.h:159
u32 r
The first element.
Definition: math_types.h:166
u32 p
The third element.
Definition: math_types.h:184
u32 z
The third element.
Definition: math_types.h:180
u32 g
The third element.
Definition: math_types.h:174
u32 x
The first element.
Definition: math_types.h:164
A 4-element vector of unsigned ints.
Definition: math_types.h:283
u32 y
The second element.
Definition: math_types.h:298
u32 b
The third element.
Definition: math_types.h:308
u32 s
The first element.
Definition: math_types.h:294
u32 t
The third element.
Definition: math_types.h:302
u32 w
The fourth element.
Definition: math_types.h:316
u32 r
The first element.
Definition: math_types.h:292
u32 q
The fourth element.
Definition: math_types.h:320
u32 elements[4]
An array of x, y, z, w.
Definition: math_types.h:285
u32 width
The third element.
Definition: math_types.h:312
u32 p
The third element.
Definition: math_types.h:310
u32 z
The third element.
Definition: math_types.h:306
u32 height
The fourth element.
Definition: math_types.h:322
u32 g
The third element.
Definition: math_types.h:300
u32 a
The fourth element.
Definition: math_types.h:318
u32 x
The first element.
Definition: math_types.h:290
A 2-element vector.
Definition: math_types.h:31
f32 r
The first element.
Definition: math_types.h:39
f32 v
The second element.
Definition: math_types.h:53
f32 s
The first element.
Definition: math_types.h:41
f32 x
The first element.
Definition: math_types.h:37
f32 g
The second element.
Definition: math_types.h:49
f32 t
The second element.
Definition: math_types.h:51
f32 u
The first element.
Definition: math_types.h:43
f32 y
The second element.
Definition: math_types.h:47
f32 elements[2]
An array of x, y.
Definition: math_types.h:33
A 2-element integer-based vector.
Definition: math_types.h:508
i32 v
The second element.
Definition: math_types.h:530
i32 r
The first element.
Definition: math_types.h:516
i32 g
The second element.
Definition: math_types.h:526
i32 y
The second element.
Definition: math_types.h:524
i32 u
The first element.
Definition: math_types.h:520
i32 s
The first element.
Definition: math_types.h:518
i32 t
The second element.
Definition: math_types.h:528
i32 elements[2]
An array of x, y.
Definition: math_types.h:510
i32 x
The first element.
Definition: math_types.h:514
A 3-element vector.
Definition: math_types.h:117
f32 elements[3]
An array of x, y, z.
Definition: math_types.h:119
f32 r
The first element.
Definition: math_types.h:125
f32 v
The second element.
Definition: math_types.h:139
f32 s
The first element.
Definition: math_types.h:127
f32 b
The third element.
Definition: math_types.h:145
f32 x
The first element.
Definition: math_types.h:123
f32 p
The third element.
Definition: math_types.h:147
f32 g
The second element.
Definition: math_types.h:135
f32 t
The second element.
Definition: math_types.h:137
f32 u
The first element.
Definition: math_types.h:129
f32 z
The third element.
Definition: math_types.h:143
f32 y
The second element.
Definition: math_types.h:133
f32 w
The third element.
Definition: math_types.h:149
A 3-element integer-based vector.
Definition: math_types.h:538
i32 r
The first element.
Definition: math_types.h:547
i32 g
The third element.
Definition: math_types.h:555
i32 elements[3]
An array of x, y, z.
Definition: math_types.h:540
i32 y
The second element.
Definition: math_types.h:553
i32 b
The third element.
Definition: math_types.h:563
i32 s
The first element.
Definition: math_types.h:549
i32 p
The third element.
Definition: math_types.h:565
i32 t
The third element.
Definition: math_types.h:557
i32 z
The third element.
Definition: math_types.h:561
i32 x
The first element.
Definition: math_types.h:545
A 4-element vector.
Definition: math_types.h:229
f32 q
The fourth element.
Definition: math_types.h:266
f32 elements[4]
An array of x, y, z, w.
Definition: math_types.h:231
f32 height
The fourth element.
Definition: math_types.h:268
f32 r
The first element.
Definition: math_types.h:238
f32 a
The fourth element.
Definition: math_types.h:264
f32 s
The first element.
Definition: math_types.h:240
f32 b
The third element.
Definition: math_types.h:254
f32 x
The first element.
Definition: math_types.h:236
f32 p
The third element.
Definition: math_types.h:256
f32 g
The third element.
Definition: math_types.h:246
f32 t
The third element.
Definition: math_types.h:248
f32 width
The third element.
Definition: math_types.h:258
f32 z
The third element.
Definition: math_types.h:252
f32 y
The second element.
Definition: math_types.h:244
f32 w
The fourth element.
Definition: math_types.h:262
A 4-element integer-based vector.
Definition: math_types.h:574
i32 w
The fourth element.
Definition: math_types.h:607
i32 r
The first element.
Definition: math_types.h:583
i32 g
The third element.
Definition: math_types.h:591
i32 elements[4]
An array of x, y, z, w.
Definition: math_types.h:576
i32 y
The second element.
Definition: math_types.h:589
i32 height
The fourth element.
Definition: math_types.h:613
i32 width
The third element.
Definition: math_types.h:603
i32 b
The third element.
Definition: math_types.h:599
i32 s
The first element.
Definition: math_types.h:585
i32 a
The fourth element.
Definition: math_types.h:609
i32 p
The third element.
Definition: math_types.h:601
i32 t
The third element.
Definition: math_types.h:593
i32 z
The third element.
Definition: math_types.h:597
i32 q
The fourth element.
Definition: math_types.h:611
i32 x
The first element.
Definition: math_types.h:581