summaryrefslogtreecommitdiff
path: root/libs/cglm/include/cglm/struct/clipspace/persp_lh_no.h
blob: 1c1bb68ecb2db35ae5b189d596d448a2e0d5a1b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/*
 * Copyright (c), Recep Aslantas.
 *
 * MIT License (MIT), htt../opensource.org/licenses/MIT
 * Full license can be found in the LICENSE file
 */

/*
 Functions:
   CGLM_INLINE mat4s glms_frustum_lh_no(float left,    float right,
                                        float bottom,  float top,
                                        float nearZ,   float farZ)
   CGLM_INLINE mat4s glms_perspective_lh_no(float fovy,
                                            float aspect,
                                            float nearZ,
                                            float farZ)
   CGLM_INLINE void  glms_persp_move_far_lh_no(mat4s proj, float deltaFar)
   CGLM_INLINE mat4s glms_perspective_default_lh_no(float aspect)
   CGLM_INLINE void  glms_perspective_resize_lh_no(mat4s proj, float aspect)
   CGLM_INLINE void  glms_persp_decomp_lh_no(mat4s  proj,
                                             float *nearv, float *farv,
                                             float *top,   float *bottom,
                                             float *left,  float *right)
   CGLM_INLINE void  glms_persp_decompv_lh_no(mat4s proj, float dest[6])
   CGLM_INLINE void  glms_persp_decomp_x_lh_no(mat4s proj, float *left, float *right)
   CGLM_INLINE void  glms_persp_decomp_y_lh_no(mat4s proj, float *top, float *bottom)
   CGLM_INLINE void  glms_persp_decomp_z_lh_no(mat4s proj, float *nearv, float *farv)
   CGLM_INLINE void  glms_persp_decomp_far_lh_no(mat4s proj, float *farZ)
   CGLM_INLINE void  glms_persp_decomp_near_lh_no(mat4s proj, float *nearZ)
   CGLM_INLINE float glms_persp_fovy_lh_no(mat4s proj)
   CGLM_INLINE float glms_persp_aspect_lh_no(mat4s proj)
   CGLM_INLINE vec4s glms_persp_sizes_lh_no(mat4s proj, float fovy)
 */

#ifndef cglms_persp_lh_no_h
#define cglms_persp_lh_no_h

#include "../../common.h"
#include "../../types-struct.h"
#include "../../plane.h"
#include "../../cam.h"

/*!
 * @brief set up perspective peprojection matrix
 *        with a left-hand coordinate system and a
 *        clip-space of [-1, 1].
 *
 * @param[in]  left    viewport.left
 * @param[in]  right   viewport.right
 * @param[in]  bottom  viewport.bottom
 * @param[in]  top     viewport.top
 * @param[in]  nearZ   near clipping plane
 * @param[in]  farZ    far clipping plane
 * @returns    result matrix
 */
CGLM_INLINE
mat4s
glms_frustum_lh_no(float left,   float right,
                   float bottom, float top,
                   float nearZ,  float farZ) {
  mat4s dest;
  glm_frustum_lh_no(left, right, bottom, top, nearZ, farZ, dest.raw);
  return dest;
}

/*!
 * @brief set up perspective projection matrix
 *        with a left-hand coordinate system and a
 *        clip-space of [-1, 1].
 *
 * @param[in]  fovy    field of view angle
 * @param[in]  aspect  aspect ratio ( width / height )
 * @param[in]  nearZ   near clipping plane
 * @param[in]  farZ    far clipping planes
 * @returns    result matrix
 */
CGLM_INLINE
mat4s
glms_perspective_lh_no(float fovy, float aspect, float nearZ, float farZ) {
  mat4s dest;
  glm_perspective_lh_no(fovy, aspect, nearZ, farZ, dest.raw);
  return dest;
}

/*!
 * @brief extend perspective projection matrix's far distance
 *        with a left-hand coordinate system and a
 *        clip-space of [-1, 1].
 *
 * NOTE: if you dodn't want to create new matrix then use array api on struct.raw
 *       like glms_persp_move_far_lh_no(prooj.raw, deltaFar) to avoid create new mat4
 *       each time
 *       
 * this function does not guarantee far >= near, be aware of that!
 *
 * @param[in, out] proj      projection matrix to extend
 * @param[in]      deltaFar  distance from existing far (negative to shink)
 */
CGLM_INLINE
mat4s
glms_persp_move_far_lh_no(mat4s proj, float deltaFar) {
  mat4s dest;
  dest = proj;
  glm_persp_move_far_lh_no(dest.raw, deltaFar);
  return dest;
}

/*!
 * @brief set up perspective projection matrix with default near/far
 *        and angle values with a left-hand coordinate system and a
 *        clip-space of [-1, 1].
 *
 * @param[in]  aspect aspect ratio ( width / height )
 * @returns    result matrix
 */
CGLM_INLINE
mat4s
glms_perspective_default_lh_no(float aspect) {
  mat4s dest;
  glm_perspective_default_lh_no(aspect, dest.raw);
  return dest;
}

/*!
 * @brief resize perspective matrix by aspect ratio ( width / height )
 *        this makes very easy to resize proj matrix when window /viewport
 *        reized with a left-hand coordinate system and a
 *        clip-space of [-1, 1].
 *
 * NOTE: if you dodn't want to create new matrix then use array api on struct.raw
 *       like glm_perspective_resize_lh_no(proj.raw, aspect) to avoid create new mat4
 *       each time
 *       
 * @param[in, out] proj   perspective projection matrix
 * @param[in]      aspect aspect ratio ( width / height )
 */
CGLM_INLINE
mat4s
glms_perspective_resize_lh_no(mat4s proj, float aspect) {
  mat4s dest;
  dest = proj;
  glm_perspective_resize_lh_no(aspect, dest.raw);
  return dest;
}

/*!
 * @brief decomposes frustum values of perspective projection.
 *        with a left-hand coordinate system and a
 *        clip-space of [-1, 1].
 *
 * @param[in]  proj    perspective projection matrix
 * @param[out] nearZ   near
 * @param[out] farZ    far
 * @param[out] top     top
 * @param[out] bottom  bottom
 * @param[out] left    left
 * @param[out] right   right
 */
CGLM_INLINE
void
glms_persp_decomp_lh_no(mat4s proj,
                        float * __restrict nearZ, float * __restrict farZ,
                        float * __restrict top,   float * __restrict bottom,
                        float * __restrict left,  float * __restrict right) {
  glm_persp_decomp_lh_no(proj.raw, nearZ, farZ, top, bottom, left, right);
}

/*!
 * @brief decomposes frustum values of perspective projection.
 *        this makes easy to get all values at once
 *        with a left-hand coordinate system and a
 *        clip-space of [-1, 1].
 *
 * @param[in]  proj   perspective projection matrix
 * @param[out] dest   array
 */
CGLM_INLINE
void
glms_persp_decompv_lh_no(mat4s proj, float dest[6]) {
  glm_persp_decompv_lh_no(proj.raw, dest);
}

/*!
 * @brief decomposes left and right values of perspective projection
 *        with a left-hand coordinate system and a
 *        clip-space of [-1, 1].
 *        x stands for x axis (left / right axis)
 *
 * @param[in]  proj  perspective projection matrix
 * @param[out] left  left
 * @param[out] right right
 */
CGLM_INLINE
void
glms_persp_decomp_x_lh_no(mat4s proj,
                          float * __restrict left,
                          float * __restrict right) {
  glm_persp_decomp_x_lh_no(proj.raw, left, right);
}

/*!
 * @brief decomposes top and bottom values of perspective projection
 *        with a left-hand coordinate system and a
 *        clip-space of [-1, 1].
 *        y stands for y axis (top / botom axis)
 *
 * @param[in]  proj   perspective projection matrix
 * @param[out] top    top
 * @param[out] bottom bottom
 */
CGLM_INLINE
void
glms_persp_decomp_y_lh_no(mat4s proj,
                          float * __restrict top,
                          float * __restrict bottom) {
  glm_persp_decomp_y_lh_no(proj.raw, top, bottom);
}

/*!
 * @brief decomposes near and far values of perspective projection
 *        with a left-hand coordinate system and a
 *        clip-space of [-1, 1].
 *        z stands for z axis (near / far axis)
 *
 * @param[in]  proj    perspective projection matrix
 * @param[out] nearZ   near
 * @param[out] farZ    far
 */
CGLM_INLINE
void
glms_persp_decomp_z_lh_no(mat4s proj,
                          float * __restrict nearZ,
                          float * __restrict farZ) {
  glm_persp_decomp_z_lh_no(proj.raw, nearZ, farZ);
}

/*!
 * @brief decomposes far value of perspective projection
 *        with a left-hand coordinate system and a
 *        clip-space of [-1, 1].
 *
 * @param[in]  proj   perspective projection matrix
 * @param[out] farZ   far
 */
CGLM_INLINE
void
glms_persp_decomp_far_lh_no(mat4s proj, float * __restrict farZ) {
  glm_persp_decomp_far_lh_no(proj.raw, farZ);
}

/*!
 * @brief decomposes near value of perspective projection
 *        with a left-hand coordinate system and a
 *        clip-space of [-1, 1].
 *
 * @param[in]  proj  perspective projection matrix
 * @param[out] nearZ near
 */
CGLM_INLINE
void
glms_persp_decomp_near_lh_no(mat4s proj, float * __restrict nearZ) {
  glm_persp_decomp_near_lh_no(proj.raw, nearZ);
}

/*!
 * @brief returns field of view angle along the Y-axis (in radians)
 *        with a left-hand coordinate system and a
 *        clip-space of [-1, 1].
 *
 * if you need to degrees, use glm_deg to convert it or use this:
 * fovy_deg = glm_deg(glm_persp_fovy(projMatrix))
 *
 * @param[in] proj perspective projection matrix
 */
CGLM_INLINE
float
glms_persp_fovy_lh_no(mat4s proj) {
  return glm_persp_fovy_lh_no(proj.raw);
}

/*!
 * @brief returns aspect ratio of perspective projection
 *        with a left-hand coordinate system and a
 *        clip-space of [-1, 1].
 *
 * @param[in] proj perspective projection matrix
 */
CGLM_INLINE
float
glms_persp_aspect_lh_no(mat4s proj) {
  return glm_persp_aspect_lh_no(proj.raw);
}

/*!
 * @brief returns sizes of near and far planes of perspective projection
 *        with a left-hand coordinate system and a
 *        clip-space of [-1, 1].
 *
 * @param[in]  proj perspective projection matrix
 * @param[in]  fovy fovy (see brief)
 * @returns    sizes as vector, sizes order: [Wnear, Hnear, Wfar, Hfar]
 */
CGLM_INLINE
vec4s
glms_persp_sizes_lh_no(mat4s proj, float fovy) {
  vec4s dest;
  glm_persp_sizes_lh_no(proj.raw, fovy, dest.raw);
  return dest;
}

#endif /* cglms_persp_lh_no_h */