src/normals.cpp

Go to the documentation of this file.
00001 /* Crown and Cutlass
00002  * Normal Calculation Code
00003  */
00004 
00005 #include "ccmath.h"
00006 #include "normals.h"
00007 
00008 double vectorLength(float vector[3]) {
00009   return sqrt((vector[0]*vector[0]) +
00010         (vector[1]*vector[1]) +
00011         (vector[2]*vector[2]));
00012 }
00013 
00014 void normalize(float normalVector[3]) {
00015   double length;
00016 
00017   length = vectorLength(normalVector);
00018 
00019   for (int x = 0; x < 3; x++) {
00020     normalVector[x] /=length;
00021   }
00022 }
00023 
00024 void crossProduct(float point1[3], float point2[3], float point3[3], float normal[3]) {
00025   float vector1[3], vector2[3];
00026 
00027   vector1[0] = point1[0] - point2[0];
00028   vector1[1] = point1[1] - point2[1];
00029   vector1[2] = point1[2] - point2[2];
00030 
00031   vector2[0] = point2[0] - point3[0];
00032   vector2[1] = point2[1] - point3[1];
00033   vector2[2] = point2[2] - point3[2];
00034 
00035   normal[0] = vector1[1]*vector2[2] - vector1[2]*vector2[1];
00036   normal[1] = vector1[2]*vector2[0] - vector1[0]*vector2[2];
00037   normal[2] = vector1[0]*vector2[1] - vector1[1]*vector2[0];
00038 }

Generated on Mon Jan 8 22:34:12 2007 for CrownandCutlass by  doxygen 1.4.7