//===========================================================================// // File: vector3d.cc // // Project: MUNGA Brick: Math Library // // Contents: Implementation details for vector classes // //---------------------------------------------------------------------------// // Date Who Modification // // -------- --- ---------------------------------------------------------- // // 11/19/94 JMA Initial coding. // //---------------------------------------------------------------------------// // Copyright (C) 1994-1995, Virtual World Entertainment, Inc. // // All Rights reserved worldwide // // This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL // //===========================================================================// #include #pragma hdrstop #if !defined(VECTOR3D_HPP) #include #endif #if !defined(LINMTRX_HPP) #include #endif #if !defined(CSTR_HPP) #include #endif //~~~~~~~~~~~~~~~~~~~~~~~~~~~~ AbstractVector3D ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #if defined(USE_SIGNATURE) int Is_Signature_Bad(const volatile AbstractVector3D *) { return False; } #endif // //########################################################################### //########################################################################### // AbstractVector3D& AbstractVector3D::operator=(const AbstractVector3D &vector) { Check_Pointer(this); Check(&vector); x = vector.x; y = vector.y; z = vector.z; return *this; } // //########################################################################### //########################################################################### // Logical Small_Enough(const AbstractVector3D &V,Scalar e) { Check(&V); return Small_Enough(V.x,e) && Small_Enough(V.y,e) && Small_Enough(V.z,e); } // //########################################################################### //########################################################################### // Logical Close_Enough( const AbstractVector3D &V1, const AbstractVector3D &V2, Scalar e ) { Check(&V1); Check(&V2); return Close_Enough(V1.x,V2.x,e) && Close_Enough(V1.y,V2.y,e) && Close_Enough(V1.z,V2.z,e); } // //########################################################################### //########################################################################### // Logical AbstractVector3D::TestInstance() const { return True; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Vector3D ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ const Vector3D Vector3D::Identity(0.0f,0.0f,0.0f); // //########################################################################### //########################################################################### // inline Vector3D& Vector3D::operator=(const LBE3Vector3D &vector) { Check_Pointer(this); Check(&vector); x = vector.x; y = vector.z; z = vector.y; return *this; } // //########################################################################### //########################################################################### // inline Vector3D& Vector3D::operator=(const TIVector3D &vector) { Check_Pointer(this); Check(&vector); x = vector.x; y = vector.y; z = -vector.z; return *this; } // //########################################################################### //########################################################################### // Vector3D& Vector3D::Negate(const Vector3D &V) { Check_Pointer(this); Check(&V); x = -V.x; y = -V.y; z = -V.z; return *this; } // //########################################################################### //########################################################################### // Vector3D& Vector3D::Add( const Vector3D& V1, const Vector3D& V2 ) { Check_Pointer(this); Check(&V1); Check(&V2); x = V1.x + V2.x; y = V1.y + V2.y; z = V1.z + V2.z; return *this; } // //########################################################################### //########################################################################### // Vector3D& Vector3D::AddScaled( const Vector3D& V1, const Vector3D& V2, Scalar scale ) { Check_Pointer(this); Check(&V1); Check(&V2); x = V1.x + V2.x*scale; y = V1.y + V2.y*scale; z = V1.z + V2.z*scale; return *this; } // //########################################################################### //########################################################################### // Vector3D& Vector3D::Subtract(const Vector3D& V1,const Vector3D& V2) { Check_Pointer(this); Check(&V1); Check(&V2); x = V1.x - V2.x; y = V1.y - V2.y; z = V1.z - V2.z; return *this; } // //########################################################################### //########################################################################### // Vector3D& Vector3D::Cross(const Vector3D& v1,const Vector3D& v2) { Check_Pointer(this); Check(&v1); Check(&v2); Verify(this != &v1); Verify(this != &v2); x = v1.y*v2.z - v1.z*v2.y; y = v1.z*v2.x - v1.x*v2.z; z = v1.x*v2.y - v1.y*v2.x; return *this; } // //########################################################################### //########################################################################### // Vector3D& Vector3D::Multiply(const Vector3D& V,Scalar Scale) { Check_Pointer(this); Check(&V); x = V.x * Scale; y = V.y * Scale; z = V.z * Scale; return *this; } // //########################################################################### //########################################################################### // Vector3D& Vector3D::Multiply(const Vector3D& V1,const Vector3D& V2) { Check_Pointer(this); Check(&V1); Check(&V2); x = V1.x * V2.x; y = V1.y * V2.y; z = V1.z * V2.z; return *this; } // //########################################################################### //########################################################################### // Vector3D& Vector3D::Divide(const Vector3D& V,Scalar Scale) { Check_Pointer(this); Check(&V); Verify(!Small_Enough(Scale)); x = V.x / Scale; y = V.y / Scale; z = V.z / Scale; return *this; } // //########################################################################### //########################################################################### // Vector3D& Vector3D::Divide(const Vector3D& V1,const Vector3D& V2) { Check_Pointer(this); Check(&V1); Check(&V2); Verify(!Small_Enough(V2.x)); Verify(!Small_Enough(V2.y)); Verify(!Small_Enough(V2.z)); x = V1.x / V2.x; y = V1.y / V2.y; z = V1.z / V2.z; return *this; } // //########################################################################### //########################################################################### // Vector3D& Vector3D::Multiply(const Vector3D& v,const AffineMatrix& m) { Check_Pointer(this); Check(&v); Check(&m); Verify(this != &v); x = v.x*m(0,0) + v.y*m(1,0) + v.z*m(2,0); y = v.x*m(0,1) + v.y*m(1,1) + v.z*m(2,1); z = v.x*m(0,2) + v.y*m(1,2) + v.z*m(2,2); return *this; } // //########################################################################### //########################################################################### // Vector3D& Vector3D::MultiplyByInverse( const Vector3D& v, const LinearMatrix& m ) { Check_Pointer(this); Check(&v); Check(&m); Verify(this != &v); x = v.x*m(0,0) + v.y*m(0,1) + v.z*m(0,2); y = v.x*m(1,0) + v.y*m(1,1) + v.z*m(1,2); z = v.x*m(2,0) + v.y*m(2,1) + v.z*m(2,2); return *this; } // //########################################################################### //########################################################################### // Vector3D& Vector3D::Normalize(const Vector3D &V) { Check(this); Scalar len = V.Length(); Verify(len); x = V.x / len; y = V.y / len; z = V.z / len; return *this; } // //########################################################################### //########################################################################### // Vector3D& Vector3D::Combine( const Vector3D& V1, Scalar t1, const Vector3D& V2, Scalar t2 ) { Check_Pointer(this); Check(&V1); Check(&V2); x = t1*V1.x + t2*V2.x; y = t1*V1.y + t2*V2.y; z = t1*V1.z + t2*V2.z; return *this; } // //########################################################################### //########################################################################### // ostream& operator<<(ostream& Stream, const Vector3D& V) { Check(&V); return Stream << setprecision(4) << '<' << V.x << ',' << V.y << ',' << V.z << '>'; } //~~~~~~~~~~~~~~~~~~~~~~~~~~ Vector3D functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // //########################################################################### //########################################################################### // void Convert_From_Ascii( const char *str, Vector3D *vector_3D ) { Check_Pointer(str); Check_Signature(vector_3D); CString parse_string(str); Check_Pointer(parse_string.GetNthToken(0)); vector_3D->x = atof(parse_string.GetNthToken(0)); Check_Pointer(parse_string.GetNthToken(1)); vector_3D->y = atof(parse_string.GetNthToken(1)); Check_Pointer(parse_string.GetNthToken(2)); vector_3D->z = atof(parse_string.GetNthToken(2)); Check(vector_3D); } // //########################################################################### //########################################################################### // LBE3Vector3D& LBE3Vector3D::operator=(const Vector3D& vector) { Check_Pointer(this); Check(&vector); x = vector.x; y = vector.z; z = vector.y; return *this; } // //########################################################################### //########################################################################### // LBE3Vector3D& LBE3Vector3D::operator=(const TIVector3D &vector) { Check_Pointer(this); Check(&vector); x = vector.x; y = -vector.z; z = vector.y; return *this; } // //########################################################################### //########################################################################### // TIVector3D& TIVector3D::operator=(const Vector3D &vector) { Check_Pointer(this); Check(&vector); x = vector.x; y = vector.y; z = -vector.z; return *this; } // //########################################################################### //########################################################################### // TIVector3D& TIVector3D::operator=(const LBE3Vector3D &vector) { Check_Pointer(this); Check(&vector); x = vector.x; y = vector.z; z = -vector.y; return *this; } #if defined(TEST_CLASS) # include "vector3d.tcp" #endif