Skip to content

Commit 0dc17e5

Browse files
committed
Implement default infinite perspective projection matrix creation functions
1 parent d6c6b4c commit 0dc17e5

7 files changed

Lines changed: 93 additions & 1 deletion

File tree

include/cglm/call/cam.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ CGLM_EXPORT
6363
void
6464
glmc_perspective_default(float aspect, mat4 dest);
6565

66+
CGLM_EXPORT
67+
void
68+
glmc_perspective_default_infinite(float aspect, mat4 dest);
69+
6670
CGLM_EXPORT
6771
void
6872
glmc_perspective_resize(float aspect, mat4 proj);

include/cglm/cam.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
float nearZ,
3131
mat4 dest)
3232
CGLM_INLINE void glm_perspective_default(float aspect, mat4 dest)
33+
CGLM_INLINE void glm_perspective_default_infinite(float aspect, mat4 dest)
3334
CGLM_INLINE void glm_perspective_resize(float aspect, mat4 proj)
3435
CGLM_INLINE void glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest)
3536
CGLM_INLINE void glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest)
@@ -343,6 +344,27 @@ glm_perspective_default(float aspect, mat4 dest) {
343344
#endif
344345
}
345346

347+
/*!
348+
* @brief set up infinite perspective projection matrix with default near
349+
* and angle values
350+
*
351+
* @param[in] aspect aspect ratio ( width / height )
352+
* @param[out] dest result matrix
353+
*/
354+
CGLM_INLINE
355+
void
356+
glm_perspective_default_infinite(float aspect, mat4 dest) {
357+
#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
358+
glm_perspective_default_infinite_lh_zo(aspect, dest);
359+
#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
360+
glm_perspective_default_infinite_lh_no(aspect, dest);
361+
#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
362+
glm_perspective_default_infinite_rh_zo(aspect, dest);
363+
#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
364+
glm_perspective_default_infinite_rh_no(aspect, dest);
365+
#endif
366+
}
367+
346368
/*!
347369
* @brief resize perspective matrix by aspect ratio ( width / height )
348370
* this makes very easy to resize proj matrix when window /viewport

include/cglm/clipspace/persp_lh_no.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
float nearZ,
2222
mat4 dest)
2323
CGLM_INLINE void glm_perspective_default_lh_no(float aspect, mat4 dest)
24+
CGLM_INLINE void glm_perspective_default_infinite_lh_no(float aspect, mat4 dest)
2425
CGLM_INLINE void glm_perspective_resize_lh_no(float aspect, mat4 proj)
2526
CGLM_INLINE void glm_persp_move_far_lh_no(mat4 proj,
2627
float deltaFar)
@@ -165,6 +166,20 @@ glm_perspective_default_lh_no(float aspect, mat4 dest) {
165166
glm_perspective_lh_no(GLM_PI_4f, aspect, 0.01f, 100.0f, dest);
166167
}
167168

169+
/*!
170+
* @brief set up infinite perspective projection matrix with default near
171+
* and angle values with a left-hand coordinate system and a
172+
* clip-space of [-1, 1].
173+
*
174+
* @param[in] aspect aspect ratio ( width / height )
175+
* @param[out] dest result matrix
176+
*/
177+
CGLM_INLINE
178+
void
179+
glm_perspective_default_infinite_lh_no(float aspect, mat4 dest) {
180+
glm_perspective_infinite_lh_no(GLM_PI_4f, aspect, 0.01f, dest);
181+
}
182+
168183
/*!
169184
* @brief resize perspective matrix by aspect ratio ( width / height )
170185
* this makes very easy to resize proj matrix when window /viewport

include/cglm/clipspace/persp_lh_zo.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
float nearZ,
2222
mat4 dest)
2323
CGLM_INLINE void glm_perspective_default_lh_zo(float aspect, mat4 dest)
24+
CGLM_INLINE void glm_perspective_default_infinite_lh_zo(float aspect, mat4 dest)
2425
CGLM_INLINE void glm_perspective_resize_lh_zo(float aspect, mat4 proj)
2526
CGLM_INLINE void glm_persp_move_far_lh_zo(mat4 proj,
2627
float deltaFar)
@@ -177,7 +178,7 @@ glm_persp_move_far_lh_zo(mat4 proj, float deltaFar) {
177178

178179
/*!
179180
* @brief set up perspective projection matrix with default near/far
180-
* and angle values with a left-hand coordinate system and a
181+
* and angle values with a left-hand coordinate system and a
181182
* clip-space of [0, 1].
182183
*
183184
* @param[in] aspect aspect ratio ( width / height )
@@ -189,6 +190,20 @@ glm_perspective_default_lh_zo(float aspect, mat4 dest) {
189190
glm_perspective_lh_zo(GLM_PI_4f, aspect, 0.01f, 100.0f, dest);
190191
}
191192

193+
/*!
194+
* @brief set up infinite perspective projection matrix with default near
195+
* and angle values with a left-hand coordinate system and a
196+
* clip-space of [0, 1].
197+
*
198+
* @param[in] aspect aspect ratio ( width / height )
199+
* @param[out] dest result matrix
200+
*/
201+
CGLM_INLINE
202+
void
203+
glm_perspective_default_infinite_lh_zo(float aspect, mat4 dest) {
204+
glm_perspective_infinite_lh_zo(GLM_PI_4f, aspect, 0.01f, dest);
205+
}
206+
192207
/*!
193208
* @brief resize perspective matrix by aspect ratio ( width / height )
194209
* this makes very easy to resize proj matrix when window /viewport

include/cglm/clipspace/persp_rh_no.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
float nearZ,
2222
mat4 dest)
2323
CGLM_INLINE void glm_perspective_default_rh_no(float aspect, mat4 dest)
24+
CGLM_INLINE void glm_perspective_default_infinite_rh_no(float aspect, mat4 dest)
2425
CGLM_INLINE void glm_perspective_resize_rh_no(float aspect, mat4 proj)
2526
CGLM_INLINE void glm_persp_move_far_rh_no(mat4 proj,
2627
float deltaFar)
@@ -165,6 +166,20 @@ glm_perspective_default_rh_no(float aspect, mat4 dest) {
165166
glm_perspective_rh_no(GLM_PI_4f, aspect, 0.01f, 100.0f, dest);
166167
}
167168

169+
/*!
170+
* @brief set up infinite perspective projection matrix with default near
171+
* and angle values with a right-hand coordinate system and a
172+
* clip-space of [-1, 1].
173+
*
174+
* @param[in] aspect aspect ratio ( width / height )
175+
* @param[out] dest result matrix
176+
*/
177+
CGLM_INLINE
178+
void
179+
glm_perspective_default_infinite_rh_no(float aspect, mat4 dest) {
180+
glm_perspective_infinite_rh_no(GLM_PI_4f, aspect, 0.01f, dest);
181+
}
182+
168183
/*!
169184
* @brief resize perspective matrix by aspect ratio ( width / height )
170185
* this makes very easy to resize proj matrix when window /viewport

include/cglm/clipspace/persp_rh_zo.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
float nearZ,
2222
mat4 dest)
2323
CGLM_INLINE void glm_perspective_default_rh_zo(float aspect, mat4 dest)
24+
CGLM_INLINE void glm_perspective_default_infinite_rh_zo(float aspect, mat4 dest)
2425
CGLM_INLINE void glm_perspective_resize_rh_zo(float aspect, mat4 proj)
2526
CGLM_INLINE void glm_persp_move_far_rh_zo(mat4 proj,
2627
float deltaFar)
@@ -163,6 +164,20 @@ glm_perspective_default_rh_zo(float aspect, mat4 dest) {
163164
glm_perspective_rh_zo(GLM_PI_4f, aspect, 0.01f, 100.0f, dest);
164165
}
165166

167+
/*!
168+
* @brief set up infinite perspective projection matrix with default near
169+
* and angle values with a right-hand coordinate system and a
170+
* clip-space of [0, 1].
171+
*
172+
* @param[in] aspect aspect ratio ( width / height )
173+
* @param[out] dest result matrix
174+
*/
175+
CGLM_INLINE
176+
void
177+
glm_perspective_default_infinite_rh_zo(float aspect, mat4 dest) {
178+
glm_perspective_infinite_rh_zo(GLM_PI_4f, aspect, 0.01f, dest);
179+
}
180+
166181
/*!
167182
* @brief resize perspective matrix by aspect ratio ( width / height )
168183
* this makes very easy to resize proj matrix when window /viewport

src/cam.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ glmc_perspective_default(float aspect, mat4 dest) {
8080
glm_perspective_default(aspect, dest);
8181
}
8282

83+
CGLM_EXPORT
84+
void
85+
glmc_perspective_default_infinite(float aspect, mat4 dest) {
86+
glm_perspective_default_infinite(aspect, dest);
87+
}
88+
8389
CGLM_EXPORT
8490
void
8591
glmc_perspective_resize(float aspect, mat4 proj) {

0 commit comments

Comments
 (0)