Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

vec4.C

Go to the documentation of this file.
00001 /*!
00002  *  \file Vec4.C
00003  *  \brief Contains implementations of non-inlined functions for the Vec4 class.
00004  *  \libgfx Most of the code in this file has been adapted from libgfx.
00005  *
00006  */
00007 
00008 #include "mlib/points.H"
00009 #include "mlib/global.H"
00010 #include "mlib/vec4.H"
00011 
00012 std::ostream &
00013 mlib::operator<<(std::ostream &out, const Vec4& v)
00014 {
00015    return out <<v[0] <<" " <<v[1] <<" " <<v[2] <<" " <<v[3];
00016 }
00017 
00018 std::istream &
00019 mlib::operator>>(std::istream &in, Vec4& v)
00020 {
00021    return in >> v[0] >> v[1] >> v[2] >> v[3];
00022 }
00023 
00024 mlib::Vec4
00025 mlib::cross(const Vec4& a, const Vec4& b, const Vec4& c)
00026 {
00027    // Code adapted from VecLib4d.c in Graphics Gems V
00028 
00029    double d1 = (b[2] * c[3]) - (b[3] * c[2]);
00030    double d2 = (b[1] * c[3]) - (b[3] * c[1]);
00031    double d3 = (b[1] * c[2]) - (b[2] * c[1]);
00032    double d4 = (b[0] * c[3]) - (b[3] * c[0]);
00033    double d5 = (b[0] * c[2]) - (b[2] * c[0]);
00034    double d6 = (b[0] * c[1]) - (b[1] * c[0]);
00035    
00036    return Vec4(- a[1] * d1 + a[2] * d2 - a[3] * d3,
00037                  a[0] * d1 - a[2] * d4 + a[3] * d5,
00038                - a[0] * d2 + a[1] * d4 - a[3] * d6,
00039                  a[0] * d3 - a[1] * d5 + a[2] * d6);
00040 }
00041 
00042 mlib::Vec3<mlib::Wvec>
00043 mlib::proj(const Vec4& v)
00044 {
00045    Vec3<Wvec> u(v[0], v[1], v[2]);
00046    if( v[3]!=1.0 && v[3]!=0.0 ) u /= v[3];
00047    return u;
00048 }

Generated on Mon Sep 18 11:39:34 2006 for jot by  doxygen 1.4.4