opengl

Sample code from LearnOpenGL.com
Log | Files | Refs

commit db1e273b0daac9440c21c78d35c684c703cab174
parent b4090b3e06d99d4c36aaef09c240423f720e15cf
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Tue, 27 Jun 2023 18:49:42 +0900

add rotation around arbitrary axis

Diffstat:
Mglm.c | 19+++++++++++++------
Mmain.c | 3+--
2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/glm.c b/glm.c @@ -154,16 +154,23 @@ translate(mat *m, const vec *v) return NULL; } - -// TODO: implementation in progress. use arbitrary axis. mat * rotate(mat *m, float rad, vec *axis) { + if (axis->size != 3) { + assert(!"axis size must be 3"); + } + float x = axis->data[0]; + float y = axis->data[1]; + float z = axis->data[2]; + float c = cosf(rad); + float s = sinf(rad); mat *rot = matMake((float[]){ // column major... - cos(rad), sin(rad), 0, 0, - -sin(rad), cos(rad), 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1}, 4); + c+x*x*(1-c), y*x*(1-c)+z*s, z*x*(1-c)-y*s, 0, + x*y*(1-c)-z*s, c+y*y*(1-c), z*y*(1-c)+x*s, 0, + x*z*(1-c)+y*s, y*z*(1-c)-x*s, c+z*z*(1-c), 0, + 0, 0, 0, 1, + }, 4); matDot(m, rot); matFree(rot); return m; diff --git a/main.c b/main.c @@ -50,7 +50,6 @@ processInput(GLFWwindow *window) int main(void) { - float theta = 0; float delta = 0.01; float vertices[] = { // positions, texture coords @@ -67,7 +66,7 @@ main(void) 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0,}, 4); - vec *axis = vecMake((float[]){0.0, 0.0, 1.0}, 3); + vec *axis = vecMake((float[]){1.0, 0.0, 0.0}, 3); // initialize glfw glfwInit();