Sat, 10 May 2025 18:51:45 +0200
refactor rendering 1/3 - create new mesh structs
3 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * Copyright 2023 Mike Becker. All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions are met: | |
7 | * | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | |
14 | * | |
15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
25 | * POSSIBILITY OF SUCH DAMAGE. | |
26 | */ | |
27 | ||
28 | #ifndef ASCENSION_DATATYPES_H | |
29 | #define ASCENSION_DATATYPES_H | |
30 | ||
14 | 31 | #ifdef __cplusplus |
32 | #error You cannot ascend using C++ | |
33 | #endif | |
34 | ||
6
302971e8599b
move window related stuff to its own unit
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
35 | #include <stdbool.h> |
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
36 | #include <string.h> |
19 | 37 | #include <SDL2/SDL_pixels.h> |
4
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
38 | |
12
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
39 | // -------------------------------------------------------------------------- |
46
d3285aed65b3
make the timer have nanoseconds precision
Mike Becker <universe@uap-core.de>
parents:
45
diff
changeset
|
40 | // Useful Macros |
d3285aed65b3
make the timer have nanoseconds precision
Mike Becker <universe@uap-core.de>
parents:
45
diff
changeset
|
41 | // -------------------------------------------------------------------------- |
d3285aed65b3
make the timer have nanoseconds precision
Mike Becker <universe@uap-core.de>
parents:
45
diff
changeset
|
42 | |
d3285aed65b3
make the timer have nanoseconds precision
Mike Becker <universe@uap-core.de>
parents:
45
diff
changeset
|
43 | #define ASC_NANOS_SECOND 1000000000ull |
d3285aed65b3
make the timer have nanoseconds precision
Mike Becker <universe@uap-core.de>
parents:
45
diff
changeset
|
44 | #define ASC_NANOS_MILLISECOND 1000000ull |
d3285aed65b3
make the timer have nanoseconds precision
Mike Becker <universe@uap-core.de>
parents:
45
diff
changeset
|
45 | #define ASC_NANOS_MICROSECOND 1000000ull |
d3285aed65b3
make the timer have nanoseconds precision
Mike Becker <universe@uap-core.de>
parents:
45
diff
changeset
|
46 | |
d3285aed65b3
make the timer have nanoseconds precision
Mike Becker <universe@uap-core.de>
parents:
45
diff
changeset
|
47 | // -------------------------------------------------------------------------- |
12
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
48 | // Datatype Definitions |
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
49 | // -------------------------------------------------------------------------- |
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
50 | |
4
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
51 | typedef unsigned char asc_ubyte; |
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
52 | typedef signed char asc_sbyte; |
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
53 | |
5 | 54 | typedef union asc_vec2i { |
3 | 55 | struct { int x, y; }; |
56 | struct { int width, height; }; | |
37
8a8cc6725b48
add camera and render groups
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
57 | int data[2]; |
3 | 58 | } asc_vec2i; |
105 | 59 | #define asc_vec2i_new(x, y) (asc_vec2i){{(int)x, (int)y}} |
60 | ||
61 | typedef union asc_vec2u { | |
62 | struct { unsigned x, y; }; | |
63 | struct { unsigned width, height; }; | |
64 | unsigned data[2]; | |
65 | } asc_vec2u; | |
66 | #define asc_vec2u_new(x, y) (asc_vec2u){{(unsigned)x, (unsigned)y}} | |
3 | 67 | |
37
8a8cc6725b48
add camera and render groups
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
68 | typedef struct asc_recti { |
8a8cc6725b48
add camera and render groups
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
69 | asc_vec2i pos; |
105 | 70 | asc_vec2u size; |
37
8a8cc6725b48
add camera and render groups
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
71 | } asc_recti; |
105 | 72 | #define asc_recti_new(x, y, w, h) (asc_recti){asc_vec2i_new(x,y), asc_vec2u_new(w,h)} |
37
8a8cc6725b48
add camera and render groups
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
73 | |
115
e5f8c99b0987
refactor rendering 1/3 - create new mesh structs
Mike Becker <universe@uap-core.de>
parents:
105
diff
changeset
|
74 | typedef union asc_vec2f { |
e5f8c99b0987
refactor rendering 1/3 - create new mesh structs
Mike Becker <universe@uap-core.de>
parents:
105
diff
changeset
|
75 | struct { float x, y; }; |
e5f8c99b0987
refactor rendering 1/3 - create new mesh structs
Mike Becker <universe@uap-core.de>
parents:
105
diff
changeset
|
76 | struct { float width, height; }; |
e5f8c99b0987
refactor rendering 1/3 - create new mesh structs
Mike Becker <universe@uap-core.de>
parents:
105
diff
changeset
|
77 | struct { float u, v; }; |
e5f8c99b0987
refactor rendering 1/3 - create new mesh structs
Mike Becker <universe@uap-core.de>
parents:
105
diff
changeset
|
78 | float data[2]; |
e5f8c99b0987
refactor rendering 1/3 - create new mesh structs
Mike Becker <universe@uap-core.de>
parents:
105
diff
changeset
|
79 | } asc_vec2f; |
e5f8c99b0987
refactor rendering 1/3 - create new mesh structs
Mike Becker <universe@uap-core.de>
parents:
105
diff
changeset
|
80 | #define asc_vec2f_new(x, y, z) (asc_vec2f){{(float)x, (float)y}} |
e5f8c99b0987
refactor rendering 1/3 - create new mesh structs
Mike Becker <universe@uap-core.de>
parents:
105
diff
changeset
|
81 | |
37
8a8cc6725b48
add camera and render groups
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
82 | typedef union asc_vec3f { |
8a8cc6725b48
add camera and render groups
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
83 | struct { float x, y, z; }; |
8a8cc6725b48
add camera and render groups
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
84 | struct { float width, height, depth; }; |
45
18de2af03531
simplify how transforms work
Mike Becker <universe@uap-core.de>
parents:
41
diff
changeset
|
85 | struct { float pitch, yaw, roll; }; |
37
8a8cc6725b48
add camera and render groups
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
86 | float data[3]; |
8a8cc6725b48
add camera and render groups
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
87 | } asc_vec3f; |
105 | 88 | #define asc_vec3f_new(x, y, z) (asc_vec3f){{(float)x, (float)y, (float)(z)}} |
37
8a8cc6725b48
add camera and render groups
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
89 | |
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
90 | typedef struct asc_col4i { |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
91 | asc_ubyte red, green, blue, alpha; |
4
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
92 | } asc_col4i; |
105 | 93 | #define asc_col4i_new(r, g, b, a) (asc_col4i){(asc_ubyte)r, (asc_ubyte)g, (asc_ubyte)b, (asc_ubyte)a} |
4
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
94 | |
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
95 | typedef struct asc_col4f { |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
96 | float red, green, blue, alpha; |
4
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
97 | } asc_col4f; |
105 | 98 | #define asc_col4f_new(r, g, b, a) (asc_col4f){(float)r, (float)g, (float)b, (float)a} |
4
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
99 | |
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
100 | typedef float asc_mat4f[16]; |
12
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
101 | |
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
102 | // -------------------------------------------------------------------------- |
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
103 | // General Utility Functions |
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
104 | // -------------------------------------------------------------------------- |
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
105 | |
4
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
106 | static inline int asc_clamp_i(int v, int min, int max) { |
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
107 | if (v < min) return min; |
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
108 | if (v > max) return max; |
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
109 | return v; |
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
110 | } |
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
111 | |
105 | 112 | static inline unsigned asc_clamp_u(unsigned v, unsigned min, unsigned max) { |
113 | if (v < min) return min; | |
114 | if (v > max) return max; | |
115 | return v; | |
116 | } | |
117 | ||
4
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
118 | /** |
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
119 | * Converts a float color (0.0f to 1.0f) to an int color (0 to 255). |
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
120 | * |
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
121 | * This operation is quite expensive. When you need to use it often, it's |
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
122 | * quite obvious that you should change the data type. |
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
123 | * |
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
124 | * @param c the color using floats |
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
125 | * @return the same color using ints |
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
126 | */ |
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
127 | static inline asc_col4i asc_col_ftoi(asc_col4f c) { |
105 | 128 | unsigned red = (unsigned)(255*c.red); |
129 | unsigned green = (unsigned)(255*c.green); | |
130 | unsigned blue = (unsigned)(255*c.blue); | |
131 | unsigned alpha = (unsigned)(255*c.alpha); | |
4
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
132 | asc_col4i r; |
105 | 133 | r.red = asc_clamp_u(red, 0, 255); |
134 | r.green = asc_clamp_u(green, 0, 255); | |
135 | r.blue = asc_clamp_u(blue, 0, 255); | |
136 | r.alpha = asc_clamp_u(alpha, 0, 255); | |
4
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
137 | return r; |
b7acda6a4476
add simple color data types
Mike Becker <universe@uap-core.de>
parents:
3
diff
changeset
|
138 | } |
3 | 139 | |
19 | 140 | static inline SDL_Color asc_col_sdl(asc_col4i col) { |
32
86468a71dd73
add transformation matrix
Mike Becker <universe@uap-core.de>
parents:
19
diff
changeset
|
141 | return (SDL_Color) {.r = col.red, .g = col.green, .b = col.blue, .a = col.alpha}; |
19 | 142 | } |
143 | ||
12
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
144 | // -------------------------------------------------------------------------- |
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
145 | // Matrix Functions |
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
146 | // -------------------------------------------------------------------------- |
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
147 | |
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
148 | /** |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
149 | * Computes a matrix index in column-major order. |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
150 | * @param col the column |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
151 | * @param row the row |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
152 | * @param rows the number of rows |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
153 | */ |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
154 | #define asc_mat_index(col, row, rows) ((row) + (col) * (rows)) |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
155 | |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
156 | /** |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
157 | * Computes a 4x4 matrix index in column-major order. |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
158 | * @param col the column |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
159 | * @param row the row |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
160 | */ |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
161 | #define asc_mat4_index(col, row) asc_mat_index(col, row, 4) |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
162 | |
37
8a8cc6725b48
add camera and render groups
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
163 | static inline void asc_mat4f_unit(asc_mat4f mat) { |
8a8cc6725b48
add camera and render groups
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
164 | memset(mat, 0, sizeof(float) * 16); |
8a8cc6725b48
add camera and render groups
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
165 | mat[asc_mat4_index(0,0)] = 1; |
8a8cc6725b48
add camera and render groups
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
166 | mat[asc_mat4_index(1,1)] = 1; |
8a8cc6725b48
add camera and render groups
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
167 | mat[asc_mat4_index(2,2)] = 1; |
8a8cc6725b48
add camera and render groups
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
168 | mat[asc_mat4_index(3,3)] = 1; |
8a8cc6725b48
add camera and render groups
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
169 | } |
8a8cc6725b48
add camera and render groups
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
170 | |
12
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
171 | static inline void asc_mat4f_ortho( |
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
172 | asc_mat4f mat, |
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
173 | float left, |
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
174 | float right, |
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
175 | float bottom, |
41
df81d493716e
add correct interleaving of opaque and transparent sprites
Mike Becker <universe@uap-core.de>
parents:
38
diff
changeset
|
176 | float top, |
df81d493716e
add correct interleaving of opaque and transparent sprites
Mike Becker <universe@uap-core.de>
parents:
38
diff
changeset
|
177 | float near, |
df81d493716e
add correct interleaving of opaque and transparent sprites
Mike Becker <universe@uap-core.de>
parents:
38
diff
changeset
|
178 | float far |
12
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
179 | ) { |
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
180 | memset(mat, 0, sizeof(float) * 16); |
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
181 | mat[asc_mat4_index(0,0)] = 2.f / (right - left); |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
182 | mat[asc_mat4_index(1,1)] = 2.f / (top - bottom); |
41
df81d493716e
add correct interleaving of opaque and transparent sprites
Mike Becker <universe@uap-core.de>
parents:
38
diff
changeset
|
183 | mat[asc_mat4_index(2,2)] = -2.f / (far - near); |
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
184 | mat[asc_mat4_index(3,0)] = -(right + left) / (right - left); |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
185 | mat[asc_mat4_index(3,1)] = -(top + bottom) / (top - bottom); |
41
df81d493716e
add correct interleaving of opaque and transparent sprites
Mike Becker <universe@uap-core.de>
parents:
38
diff
changeset
|
186 | mat[asc_mat4_index(3,2)] = -(far + near) / (far - near); |
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
187 | mat[asc_mat4_index(3,3)] = 1; |
12
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
188 | } |
d89e0ebc76d2
add projection matrix to AscWindow
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
189 | |
99
ac143db979dc
add aspect-ration independent rendering
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
190 | /** |
ac143db979dc
add aspect-ration independent rendering
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
191 | * Shorter version of updating an orthographic matrix which assumes the top right corner at (0,0). |
ac143db979dc
add aspect-ration independent rendering
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
192 | * |
ac143db979dc
add aspect-ration independent rendering
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
193 | * @attention The matrix MUST have been properly initialized with asc_mat4f_ortho() with left=0 and top=0, first! |
ac143db979dc
add aspect-ration independent rendering
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
194 | * |
ac143db979dc
add aspect-ration independent rendering
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
195 | * @param mat the matrix |
ac143db979dc
add aspect-ration independent rendering
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
196 | * @param width the new width (right coordinate) |
ac143db979dc
add aspect-ration independent rendering
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
197 | * @param height the new height (bottom coordinate) |
ac143db979dc
add aspect-ration independent rendering
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
198 | */ |
ac143db979dc
add aspect-ration independent rendering
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
199 | static inline void asc_mat4f_ortho_update_size( |
ac143db979dc
add aspect-ration independent rendering
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
200 | asc_mat4f mat, |
ac143db979dc
add aspect-ration independent rendering
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
201 | float width, |
ac143db979dc
add aspect-ration independent rendering
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
202 | float height |
ac143db979dc
add aspect-ration independent rendering
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
203 | ) { |
ac143db979dc
add aspect-ration independent rendering
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
204 | mat[asc_mat4_index(0,0)] = 2.f / width; |
ac143db979dc
add aspect-ration independent rendering
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
205 | mat[asc_mat4_index(1,1)] = -2.f / height; |
ac143db979dc
add aspect-ration independent rendering
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
206 | } |
ac143db979dc
add aspect-ration independent rendering
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
207 | |
38
6e5629ea4c5c
implement that nodes inherit the world transform of their parent
Mike Becker <universe@uap-core.de>
parents:
37
diff
changeset
|
208 | static inline void asc_mat4f_mulst( |
6e5629ea4c5c
implement that nodes inherit the world transform of their parent
Mike Becker <universe@uap-core.de>
parents:
37
diff
changeset
|
209 | asc_mat4f dest, |
6e5629ea4c5c
implement that nodes inherit the world transform of their parent
Mike Becker <universe@uap-core.de>
parents:
37
diff
changeset
|
210 | asc_mat4f const left, |
6e5629ea4c5c
implement that nodes inherit the world transform of their parent
Mike Becker <universe@uap-core.de>
parents:
37
diff
changeset
|
211 | asc_mat4f const right |
6e5629ea4c5c
implement that nodes inherit the world transform of their parent
Mike Becker <universe@uap-core.de>
parents:
37
diff
changeset
|
212 | ) { |
6e5629ea4c5c
implement that nodes inherit the world transform of their parent
Mike Becker <universe@uap-core.de>
parents:
37
diff
changeset
|
213 | for (unsigned i = 0; i < 4; i++) { |
6e5629ea4c5c
implement that nodes inherit the world transform of their parent
Mike Becker <universe@uap-core.de>
parents:
37
diff
changeset
|
214 | for (unsigned j = 0; j < 4; j++) { |
6e5629ea4c5c
implement that nodes inherit the world transform of their parent
Mike Becker <universe@uap-core.de>
parents:
37
diff
changeset
|
215 | dest[asc_mat4_index(i, j)] = 0; |
6e5629ea4c5c
implement that nodes inherit the world transform of their parent
Mike Becker <universe@uap-core.de>
parents:
37
diff
changeset
|
216 | for (int k = 0; k < 4; k++) { |
6e5629ea4c5c
implement that nodes inherit the world transform of their parent
Mike Becker <universe@uap-core.de>
parents:
37
diff
changeset
|
217 | dest[asc_mat4_index(i,j)] += |
6e5629ea4c5c
implement that nodes inherit the world transform of their parent
Mike Becker <universe@uap-core.de>
parents:
37
diff
changeset
|
218 | left[asc_mat4_index(i,k)] * right[asc_mat4_index(k,j)]; |
6e5629ea4c5c
implement that nodes inherit the world transform of their parent
Mike Becker <universe@uap-core.de>
parents:
37
diff
changeset
|
219 | } |
6e5629ea4c5c
implement that nodes inherit the world transform of their parent
Mike Becker <universe@uap-core.de>
parents:
37
diff
changeset
|
220 | } |
6e5629ea4c5c
implement that nodes inherit the world transform of their parent
Mike Becker <universe@uap-core.de>
parents:
37
diff
changeset
|
221 | } |
6e5629ea4c5c
implement that nodes inherit the world transform of their parent
Mike Becker <universe@uap-core.de>
parents:
37
diff
changeset
|
222 | } |
6e5629ea4c5c
implement that nodes inherit the world transform of their parent
Mike Becker <universe@uap-core.de>
parents:
37
diff
changeset
|
223 | |
3 | 224 | #endif //ASCENSION_DATATYPES_H |