00001
00002
00003
00004
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
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 }