ogl_vec3f_normal.c (530B)
1 /* 2 2018 David DiPaola 3 licensed under CC0 (public domain, see https://creativecommons.org/publicdomain/zero/1.0/) 4 */ 5 6 #include <GL/glew.h> 7 8 #include "ogl.h" 9 10 int 11 ogl_vec3f_normal( 12 struct ogl_vec3f vector, 13 struct ogl_vec3f * out_result 14 ) { 15 GLfloat vector_magnitude = ogl_vec3f_magnitude(vector); 16 if (ogl_GLfloat_isapproxequal(vector_magnitude, 0.0f)) { 17 return -1; 18 } 19 20 (*out_result).x = vector.x / vector_magnitude; 21 (*out_result).y = vector.y / vector_magnitude; 22 (*out_result).z = vector.z / vector_magnitude; 23 return 0; 24 } 25