Alchemy
Loading...
Searching...
No Matches

vector3.h

Go to the documentation of this file.
1#ifndef ALCHEMY_VECTOR3_H
2#define ALCHEMY_VECTOR3_H
3
4/// @file
5/// Vector3, a three-coordinate vector.
6
7#include "types.h"
8#include "static_assert.h"
9
10/// Three coordinates, x, y and z: a position, a velocity or a direction.
11struct Vector3 {
12#ifdef UBFIX
13 union {
14 struct {
15 s32 x;
16 s32 y;
17 s32 z;
18 };
19 s32 coordinates[3]; ///< x, y and z, as Vector3_Coordinates returns them
20 };
21#else
25#endif
26};
27
28/// Returns the vector's three coordinates as an array.
29// UB: transform routines index three coordinates from separate scalar members.
30// UBFIX gives those routines a real array while preserving named components.
31static inline const s32 *Vector3_Coordinates(const struct Vector3 *vector) {
32#ifdef UBFIX
33 return vector->coordinates;
34#else
35 return &vector->x;
36#endif
37}
38
39STATIC_ASSERT(sizeof(struct Vector3) == 0x0c);
40STATIC_ASSERT(offsetof(struct Vector3, x) == 0x00);
41STATIC_ASSERT(offsetof(struct Vector3, y) == 0x04);
42STATIC_ASSERT(offsetof(struct Vector3, z) == 0x08);
43
44#endif
STATIC_ASSERT, a compile-time check that emits nothing.
#define STATIC_ASSERT(condition)
C89 permits repeated extern declarations of the same array.
#define offsetof(type, member)
Definition stddef.h:19
Three coordinates, x, y and z: a position, a velocity or a direction.
Definition vector3.h:11
s32 z
Definition vector3.h:24
s32 x
Definition vector3.h:22
s32 y
Definition vector3.h:23
The integer types, TRUE, UNUSED and the fixed-address macros.
signed int s32
Definition types.h:14
static const s32 * Vector3_Coordinates(const struct Vector3 *vector)
Returns the vector's three coordinates as an array.
Definition vector3.h:31