// Filename: lvector4.I // Created by: drose (08Mar00) // //////////////////////////////////////////////////////////////////// #include "cmath.h" template TypeHandle LVector4::_type_handle; //////////////////////////////////////////////////////////////////// // Function: LVector4::Default Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE LVector4:: LVector4() { } //////////////////////////////////////////////////////////////////// // Function: LVector4::Copy Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE LVector4:: LVector4(const LVecBase4 ©) : LVecBase4(copy) { } //////////////////////////////////////////////////////////////////// // Function: LVector4::Copy Assignment Operator // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE LVector4 &LVector4:: operator = (const LVecBase4 ©) { LVecBase4::operator = (copy); return *this; } //////////////////////////////////////////////////////////////////// // Function: LVector4::Copy Fill Operator // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE LVector4 &LVector4:: operator = (NumType fill_value) { LVecBase4::operator = (fill_value); return *this; } //////////////////////////////////////////////////////////////////// // Function: LVector4::Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE LVector4:: LVector4(NumType fill_value) : LVecBase4(fill_value) { } //////////////////////////////////////////////////////////////////// // Function: LVector4::Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE LVector4:: LVector4(NumType x, NumType y, NumType z, NumType w) : LVecBase4(x, y, z, w) { } //////////////////////////////////////////////////////////////////// // Function: LVector4::zero Named Constructor // Access: Public // Description: Returns a zero-length vector. //////////////////////////////////////////////////////////////////// template INLINE LVector4 LVector4:: zero() { return LVector4(0.0, 0.0, 0.0, 0.0); } //////////////////////////////////////////////////////////////////// // Function: LVector4::unit_x Named Constructor // Access: Public // Description: Returns a unit X vector. //////////////////////////////////////////////////////////////////// template INLINE LVector4 LVector4:: unit_x() { return LVector4(1.0, 0.0, 0.0, 0.0); } //////////////////////////////////////////////////////////////////// // Function: LVector4::unit_y Named Constructor // Access: Public // Description: Returns a unit Y vector. //////////////////////////////////////////////////////////////////// template INLINE LVector4 LVector4:: unit_y() { return LVector4(0.0, 1.0, 0.0, 0.0); } //////////////////////////////////////////////////////////////////// // Function: LVector4::unit_z Named Constructor // Access: Public // Description: Returns a unit Z vector. //////////////////////////////////////////////////////////////////// template INLINE LVector4 LVector4:: unit_z() { return LVector4(0.0, 0.0, 1.0, 0.0); } //////////////////////////////////////////////////////////////////// // Function: LVector4::unit_w Named Constructor // Access: Public // Description: Returns a unit W vector. //////////////////////////////////////////////////////////////////// template INLINE LVector4 LVector4:: unit_w() { return LVector4(0.0, 0.0, 0.0, 1.0); } //////////////////////////////////////////////////////////////////// // Function: LVector4::unary - // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE LVector4 LVector4:: operator - () const { return LVecBase4::operator - (); } //////////////////////////////////////////////////////////////////// // Function: LVector4::vector + vecbase // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE LVecBase4 LVector4:: operator + (const LVecBase4 &other) const { return LVecBase4::operator + (other); } //////////////////////////////////////////////////////////////////// // Function: LVector4::vector + vector // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE LVector4 LVector4:: operator + (const LVector4 &other) const { return LVecBase4::operator + (other); } //////////////////////////////////////////////////////////////////// // Function: LVector4::vector - vecbase // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE LVecBase4 LVector4:: operator - (const LVecBase4 &other) const { return LVecBase4::operator - (other); } //////////////////////////////////////////////////////////////////// // Function: LVector4::vector - vector // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE LVector4 LVector4:: operator - (const LVector4 &other) const { return LVecBase4::operator - (other); } //////////////////////////////////////////////////////////////////// // Function: LVector4::length // Access: Public // Description: Returns the length of the vector, by the Pythagorean // theorem. //////////////////////////////////////////////////////////////////// template INLINE NumType LVector4:: length() const { return csqrt((*this).dot(*this)); } //////////////////////////////////////////////////////////////////// // Function: LVector4::length_squared // Access: Public // Description: Returns the square of the vector's length, cheap and // easy. //////////////////////////////////////////////////////////////////// template INLINE NumType LVector4:: length_squared() const { return (*this).dot(*this); } //////////////////////////////////////////////////////////////////// // Function: LVector4::normalize // Access: Public // Description: Normalizes the vector in place. Returns true if the // vector was normalized, false if it was a zero-length // vector. //////////////////////////////////////////////////////////////////// template INLINE bool LVector4:: normalize() { NumType l2 = length_squared(); if (l2 == (NumType)0.0) { set(0.0, 0.0, 0.0, 0.0); return false; } else if (!IS_THRESHOLD_EQUAL(l2, 1.0, NEARLY_ZERO(NumType) * NEARLY_ZERO(NumType))) { (*this) /= csqrt(l2); } return true; } //////////////////////////////////////////////////////////////////// // Function: LVector4::operator * scalar // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE LVector4 LVector4:: operator * (NumType scalar) const { return LVector4(LVecBase4::operator * (scalar)); } //////////////////////////////////////////////////////////////////// // Function: LVector4::operator / scalar // Access: Public // Description: //////////////////////////////////////////////////////////////////// template INLINE LVector4 LVector4:: operator / (NumType scalar) const { return LVector4(LVecBase4::operator / (scalar)); } //////////////////////////////////////////////////////////////////// // Function: LVector4::init_type // Access: Public, Static // Description: //////////////////////////////////////////////////////////////////// template void LVector4:: init_type() { if (_type_handle == TypeHandle::none()) { LVecBase4::init_type(); string name = "LVector4<" + get_type_handle(NumType).get_name() + ">"; register_type(_type_handle, name, LVecBase4::get_class_type()); } } //////////////////////////////////////////////////////////////////// // Function: lcast_to // Description: Converts a vector from one numeric representation to // another one. This is usually invoked using the macro // LCAST. //////////////////////////////////////////////////////////////////// template INLINE LVector4 lcast_to(NumType2 *, const LVector4 &source) { return LVector4(source[0], source[1], source[2], source[3]); }