31 #ifdef __cplusplus |
31 #ifdef __cplusplus |
32 #error You cannot ascend using C++ |
32 #error You cannot ascend using C++ |
33 #endif |
33 #endif |
34 |
34 |
35 #include <stdbool.h> |
35 #include <stdbool.h> |
36 #include <SDL2/SDL_endian.h> |
36 #include <string.h> |
37 |
37 |
38 // -------------------------------------------------------------------------- |
38 // -------------------------------------------------------------------------- |
39 // Datatype Definitions |
39 // Datatype Definitions |
40 // -------------------------------------------------------------------------- |
40 // -------------------------------------------------------------------------- |
41 |
41 |
46 int data[2]; |
46 int data[2]; |
47 struct { int x, y; }; |
47 struct { int x, y; }; |
48 struct { int width, height; }; |
48 struct { int width, height; }; |
49 } asc_vec2i; |
49 } asc_vec2i; |
50 |
50 |
51 typedef union asc_col4i { |
51 typedef struct asc_col4i { |
52 asc_ubyte data[4]; |
52 asc_ubyte red, green, blue, alpha; |
53 #if SDL_BYTEORDER == SDL_BIG_ENDIAN |
|
54 struct { asc_ubyte red, green, blue, alpha; }; |
|
55 #else |
|
56 struct { asc_ubyte alpha, blue, green, red; }; |
|
57 #endif |
|
58 } asc_col4i; |
53 } asc_col4i; |
59 |
54 |
60 typedef union asc_col4f { |
55 typedef struct asc_col4f { |
61 float data[4]; |
56 float red, green, blue, alpha; |
62 #if SDL_BYTEORDER == SDL_BIG_ENDIAN |
|
63 struct { float red, green, blue, alpha; }; |
|
64 #else |
|
65 struct { float alpha, blue, green, red; }; |
|
66 #endif |
|
67 } asc_col4f; |
57 } asc_col4f; |
68 |
58 |
69 typedef float asc_mat4f[4][4]; |
59 typedef float asc_mat4f[16]; |
70 |
60 |
71 // -------------------------------------------------------------------------- |
61 // -------------------------------------------------------------------------- |
72 // General Utility Functions |
62 // General Utility Functions |
73 // -------------------------------------------------------------------------- |
63 // -------------------------------------------------------------------------- |
74 |
64 |
102 |
92 |
103 // -------------------------------------------------------------------------- |
93 // -------------------------------------------------------------------------- |
104 // Matrix Functions |
94 // Matrix Functions |
105 // -------------------------------------------------------------------------- |
95 // -------------------------------------------------------------------------- |
106 |
96 |
|
97 /** |
|
98 * Computes a matrix index in column-major order. |
|
99 * @param col the column |
|
100 * @param row the row |
|
101 * @param rows the number of rows |
|
102 */ |
|
103 #define asc_mat_index(col, row, rows) ((row) + (col) * (rows)) |
|
104 |
|
105 /** |
|
106 * Computes a 4x4 matrix index in column-major order. |
|
107 * @param col the column |
|
108 * @param row the row |
|
109 */ |
|
110 #define asc_mat4_index(col, row) asc_mat_index(col, row, 4) |
|
111 |
107 static inline void asc_mat4f_ortho( |
112 static inline void asc_mat4f_ortho( |
108 asc_mat4f mat, |
113 asc_mat4f mat, |
109 float left, |
114 float left, |
110 float right, |
115 float right, |
111 float bottom, |
116 float bottom, |
112 float top |
117 float top |
113 ) { |
118 ) { |
114 memset(mat, 0, sizeof(float) * 16); |
119 memset(mat, 0, sizeof(float) * 16); |
115 mat[0][0] = 2.f / (right - left); |
120 mat[asc_mat4_index(0,0)] = 2.f / (right - left); |
116 mat[1][1] = 2.f / (top - bottom); |
121 mat[asc_mat4_index(1,1)] = 2.f / (top - bottom); |
117 mat[2][2] = -1; |
122 mat[asc_mat4_index(2,2)] = -1; |
118 mat[3][0] = -(right + left) / (right - left); |
123 mat[asc_mat4_index(3,0)] = -(right + left) / (right - left); |
119 mat[3][1] = -(top + bottom) / (top - bottom); |
124 mat[asc_mat4_index(3,1)] = -(top + bottom) / (top - bottom); |
|
125 mat[asc_mat4_index(3,3)] = 1; |
120 } |
126 } |
121 |
127 |
122 #endif //ASCENSION_DATATYPES_H |
128 #endif //ASCENSION_DATATYPES_H |