opengl_learn

Step-by-step introduction to OpenGL
git clone https://0xdd.org/code/opengl_learn.git
Log | Files | Refs | README | LICENSE

ogl_vec3f_cross.c (557B)


      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 void
     11 ogl_vec3f_cross(
     12 	struct ogl_vec3f a, struct ogl_vec3f b,
     13 	struct ogl_vec3f * out_result
     14 ) {
     15 	GLfloat a_x = a.x, a_y = a.y, a_z = a.z;
     16 	GLfloat b_x = b.x, b_y = b.y, b_z = b.z;
     17 
     18 	/* from Wikipedia (https://en.wikipedia.org/wiki/Cross_product#Coordinate_notation) */
     19 	(*out_result).x = (a_y*b_z) - (a_z*b_y);
     20 	(*out_result).y = (a_z*b_x) - (a_x*b_z);
     21 	(*out_result).z = (a_x*b_y) - (a_y*b_x);
     22 }
     23