opengl

Sample code from LearnOpenGL.com
Log | Files | Refs

commit 9bb9a98cfb4d4c7dd589fefe255955fedeeeede8
parent c83abc7d1c98908d2de62e8b0b53a624cead465a
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Thu, 29 Jun 2023 07:56:37 +0900

add orthogonal projection

Diffstat:
Mglm.c | 21+++++++++++++++++++++
Mglm.h | 2++
Mmain.c | 2+-
3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/glm.c b/glm.c @@ -171,6 +171,27 @@ matMakePers(float fov, float aspect, float near, float far) return m; } +mat * +matMakeOrth(float minx, float maxx, float miny, float maxy, float near, + float far) +{ + mat *m = (mat *)malloc(sizeof(mat)); + m->data = (float *)calloc(sizeof(float), 16); + + m->data[0] = 2 / (maxx - minx); + m->data[12] = -(maxx + minx) / (maxx - minx); + m->data[5] = 2 / (maxy - miny); + m->data[13] = -(maxy + miny) / (maxy - miny); + m->data[10] = -2 / (far - near); + m->data[14] = -(far + near) / (far - near); + m->data[15] = 1; + + m->size = 4; + numMat++; + return m; +} + + void matFree(mat *m) diff --git a/glm.h b/glm.h @@ -31,6 +31,8 @@ char *matStr(char *s, mat *m); mat *matMake(float *data, int size); mat *matMakeIdent(int size); mat *matMakePers(float fov, float aspect, float near, float far); +mat *matMakeOrth(float minx, float maxx, float miny, float maxy, float near, + float far); void matFree(mat *m); mat *matDot(mat *m, const mat *n); int matCount(void); diff --git a/main.c b/main.c @@ -110,7 +110,7 @@ main(void) mat *viewMat = matMakeIdent(4); mat *projMat = matMakePers((float)M_PI/4, (float)width/(float)height, 0.1, 100.0); - + vec *axis0 = vecMake((float[]){1.41421356/2, 1.41421356/2, 0.0}, 3); vec *axis1 = vecMake((float[]){0.0, 0.0, 1.0}, 3);