/* ======================================================================= cs171CommonVec.cpp: common vector-oriented stuff for CS 171A Based on the code written at Cornell University by Jim Arvo and adapted for the PCGV framework at Cornell University by James Durkin, Gordon Kindlmann and Philip Hubbard. ======================================================================= */ #include "cs171CommonVec.h" /* class cs171Vec3 ======================================================= */ /* public ---------------------------------------------------------------- */ /* Make this vector into a unit vector, and return the length it had before it was normalized. */ double cs171Vec3::normalize() { double d = len(); if(d > 0.0) { double c = 1.0 / d; x() *= c; y() *= c; z() *= c; } return(d); }