00001
00002
00003
00004 #include "vector.h"
00005
00007 const math::vector3 math::vector3::ZERO( 0.0, 0.0, 0.0 );
00008 const math::vector3 math::vector3::X_AXIS( 1.0, 0.0, 0.0 );
00009 const math::vector3 math::vector3::Y_AXIS( 0.0, 1.0, 0.0 );
00010 const math::vector3 math::vector3::Z_AXIS( 0.0, 0.0, 1.0 );
00011
00013 math::vector3
00014 operator* ( real_t lhs, const math::vector3& rhs )
00015 {
00016 return math::vector3( (rhs.m_data[ 0 ] * lhs),
00017 (rhs.m_data[ 1 ] * lhs),
00018 (rhs.m_data[ 2 ] * lhs)
00019 );
00020 }
00021
00023 std::ostream&
00024 operator<< ( std::ostream& o, const math::vector3& vec )
00025 {
00026 return o << vec.m_data[ 0 ] << " " << vec.m_data[ 1 ]
00027 << " " << vec.m_data[ 2 ];
00028 }
00029
00030
00032 math::vector3
00033 math::cross( const math::vector3& u, const math::vector3& v )
00034 {
00035 return math::vector3(
00036 u.m_data[ 1 ] * v.m_data[ 2 ] - u.m_data[ 2 ] * v.m_data[ 1 ],
00037 u.m_data[ 2 ] * v.m_data[ 0 ] - u.m_data[ 0 ] * v.m_data[ 2 ],
00038 u.m_data[ 0 ] * v.m_data[ 1 ] - u.m_data[ 1 ] * v.m_data[ 0 ]
00039 );
00040 }
00041
00043 void
00044 math::add( math::vector3& dest, const math::vector3& lhs,
00045 const math::vector3& rhs )
00046 {
00047 dest.m_data[ 0 ] = lhs.m_data[ 0 ] + rhs.m_data[ 0 ];
00048 dest.m_data[ 1 ] = lhs.m_data[ 1 ] + rhs.m_data[ 1 ];
00049 dest.m_data[ 2 ] = lhs.m_data[ 2 ] + rhs.m_data[ 2 ];
00050 }
00051
00053 void
00054 math::subtract( math::vector3& dest, const math::vector3& lhs,
00055 const math::vector3& rhs )
00056 {
00057 dest.m_data[ 0 ] = lhs.m_data[ 0 ] - rhs.m_data[ 0 ];
00058 dest.m_data[ 1 ] = lhs.m_data[ 1 ] - rhs.m_data[ 1 ];
00059 dest.m_data[ 2 ] = lhs.m_data[ 2 ] - rhs.m_data[ 2 ];
00060 }
00061
00063 void
00064 math::multiply( math::vector3& dest, const math::vector3& lhs,
00065 const math::vector3& rhs )
00066 {
00067 dest.m_data[ 0 ] = lhs.m_data[ 0 ] * rhs.m_data[ 0 ];
00068 dest.m_data[ 1 ] = lhs.m_data[ 1 ] * rhs.m_data[ 1 ];
00069 dest.m_data[ 2 ] = lhs.m_data[ 2 ] * rhs.m_data[ 2 ];
00070 }
00071
00073 void
00074 math::divide( math::vector3& dest, const math::vector3& lhs,
00075 const math::vector3& rhs )
00076 {
00077 dest.m_data[ 0 ] = lhs.m_data[ 0 ] / rhs.m_data[ 0 ];
00078 dest.m_data[ 1 ] = lhs.m_data[ 1 ] / rhs.m_data[ 1 ];
00079 dest.m_data[ 2 ] = lhs.m_data[ 2 ] / rhs.m_data[ 2 ];
00080 }
00081
00083 void
00084 math::multiply( math::vector3& dest, const math::vector3& lhs, real_t rhs )
00085 {
00086 dest.m_data[ 0 ] = lhs.m_data[ 0 ] * rhs;
00087 dest.m_data[ 1 ] = lhs.m_data[ 1 ] * rhs;
00088 dest.m_data[ 2 ] = lhs.m_data[ 2 ] * rhs;
00089 }
00090
00092 void
00093 math::multiply( math::vector3& dest, real_t lhs, const math::vector3& rhs )
00094 {
00095 dest.m_data[ 0 ] = rhs.m_data[ 0 ] * lhs;
00096 dest.m_data[ 1 ] = rhs.m_data[ 1 ] * lhs;
00097 dest.m_data[ 2 ] = rhs.m_data[ 2 ] * lhs;
00098 }
00099
00101 real_t
00102 math::dot( const math::vector3& lhs, const math::vector3& rhs )
00103 {
00104 return (
00105 (lhs.m_data[ 0 ] * rhs.m_data[ 0 ]) +
00106 (lhs.m_data[ 1 ] * rhs.m_data[ 1 ]) +
00107 (lhs.m_data[ 2 ] * rhs.m_data[ 2 ])
00108 );
00109 }