Vector3SSE.cpp
Go to the documentation of this file.00001 /**<!--------------------------------------------------------------------> 00002 @file Vector3SSE.cpp 00003 @author Travis Fischer (fisch0920@gmail.com) 00004 @date Fall 2008 00005 00006 @brief 00007 Specialized implementation of Vector3, accelerated to support efficient 00008 SIMD vectorization via SSE intrinsics 00009 00010 @note this file is not meant to be #included directly 00011 @see Vector.h for more details 00012 <!-------------------------------------------------------------------->**/ 00013 00014 #include <Vector.h> 00015 #include <common.h> 00016 00017 #if MILTON_ENABLE_SSE 00018 00019 // Cleans up vector (0's out entries that are less than epsilon) 00020 void Vector<3, real_t>::cleanup() { 00021 for(unsigned i = 3; i--;) { 00022 if (EQ(data[i], 0)) { 00023 data[i] = 0; 00024 } 00025 } 00026 } 00027 00028 /* Assume normal is normalized, incident vector is incoming and 00029 * resultant vector is exiting */ 00030 Vector<3, real_t> Vector<3, real_t>::reflectVector( 00031 const Vector<3, real_t> &normal) const 00032 { 00033 return -2 * normal * dot(normal) + *this; 00034 } 00035 00036 Vector<3, real_t> Vector<3, real_t>::refractVector( 00037 const Vector<3, real_t> &normal, 00038 real_t in, real_t out) const 00039 { 00040 const Vector3 &w = -*this; 00041 Vector3 norm; 00042 real_t n; 00043 00044 if (dot(normal) < 0) { // wi incident on front-side of surface 00045 ASSERT(out != 0); 00046 norm = normal; 00047 n = in / out; 00048 } else { // wi incident on back-side of surface 00049 ASSERT(in != 0); 00050 norm = -normal; 00051 n = out / in; 00052 } 00053 00054 const real_t d = w.dot(norm); 00055 const real_t det = 1 - n * n * (1 - d * d); 00056 00057 if (det < 0) 00058 return Vector3::zero(); 00059 00060 const Vector3 &wo = -n * w + norm * (n * d - sqrt(det)); 00061 ASSERT(wo.isUnit()); 00062 00063 return wo; 00064 } 00065 00066 void Vector<3, real_t>::getOrthonormalBasis(Vector<3, real_t> &U, 00067 Vector<3, real_t> &V) 00068 { 00069 normalize(); 00070 const Vector3 &normal = *this; 00071 Vector3 up = Vector3(0, 1, 0); 00072 00073 if (ABS(up.dot(normal)) > create_real(0.8)) 00074 up = Vector3(1, 0, 0); 00075 00076 U = up.cross(normal).getNormalized(); 00077 V = normal.cross(U).getNormalized(); 00078 } 00079 00080 #endif 00081
Generated on 28 Feb 2009 for Milton by
1.5.6