| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- // Filename: lvector4_src.I
- // Created by: drose (08Mar00)
- //
- ////////////////////////////////////////////////////////////////////
- //
- // PANDA 3D SOFTWARE
- // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
- //
- // All use of this software is subject to the terms of the Panda 3d
- // Software license. You should have received a copy of this license
- // along with this source code; you will also find a current copy of
- // the license at http://www.panda3d.org/license.txt .
- //
- // To contact the maintainers of this program write to
- // [email protected] .
- //
- ////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////
- // Function: LVector4::Default Constructor
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector4)::
- FLOATNAME(LVector4)() {
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector4::Copy Constructor
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector4)::
- FLOATNAME(LVector4)(const FLOATNAME(LVecBase4) ©) : FLOATNAME(LVecBase4)(copy) {
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector4::Copy Assignment Operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector4) &FLOATNAME(LVector4)::
- operator = (const FLOATNAME(LVecBase4) ©) {
- FLOATNAME(LVecBase4)::operator = (copy);
- return *this;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector4::Copy Fill Operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector4) &FLOATNAME(LVector4)::
- operator = (FLOATTYPE fill_value) {
- FLOATNAME(LVecBase4)::operator = (fill_value);
- return *this;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector4::Constructor
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector4)::
- FLOATNAME(LVector4)(FLOATTYPE fill_value) :
- FLOATNAME(LVecBase4)(fill_value)
- {
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector4::Constructor
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector4)::
- FLOATNAME(LVector4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w) :
- FLOATNAME(LVecBase4)(x, y, z, w)
- {
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector4::zero Named Constructor
- // Access: Public
- // Description: Returns a zero-length vector.
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH const FLOATNAME(LVector4) &FLOATNAME(LVector4)::
- zero() {
- return (const FLOATNAME(LVector4) &)FLOATNAME(LVecBase4)::zero();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector4::unit_x Named Constructor
- // Access: Public
- // Description: Returns a unit X vector.
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH const FLOATNAME(LVector4) &FLOATNAME(LVector4)::
- unit_x() {
- return (const FLOATNAME(LVector4) &)FLOATNAME(LVecBase4)::unit_x();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector4::unit_y Named Constructor
- // Access: Public
- // Description: Returns a unit Y vector.
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH const FLOATNAME(LVector4) &FLOATNAME(LVector4)::
- unit_y() {
- return (const FLOATNAME(LVector4) &)FLOATNAME(LVecBase4)::unit_y();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector4::unit_z Named Constructor
- // Access: Public
- // Description: Returns a unit Z vector.
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH const FLOATNAME(LVector4) &FLOATNAME(LVector4)::
- unit_z() {
- return (const FLOATNAME(LVector4) &)FLOATNAME(LVecBase4)::unit_z();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector4::unit_w Named Constructor
- // Access: Public
- // Description: Returns a unit W vector.
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH const FLOATNAME(LVector4) &FLOATNAME(LVector4)::
- unit_w() {
- return (const FLOATNAME(LVector4) &)FLOATNAME(LVecBase4)::unit_w();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector4::unary -
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector4) FLOATNAME(LVector4)::
- operator - () const {
- return FLOATNAME(LVecBase4)::operator - ();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector4::vector + vecbase
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVector4)::
- operator + (const FLOATNAME(LVecBase4) &other) const {
- return FLOATNAME(LVecBase4)::operator + (other);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector4::vector + vector
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector4) FLOATNAME(LVector4)::
- operator + (const FLOATNAME(LVector4) &other) const {
- return FLOATNAME(LVecBase4)::operator + (other);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector4::vector - vecbase
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVector4)::
- operator - (const FLOATNAME(LVecBase4) &other) const {
- return FLOATNAME(LVecBase4)::operator - (other);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector4::vector - vector
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector4) FLOATNAME(LVector4)::
- operator - (const FLOATNAME(LVector4) &other) const {
- return FLOATNAME(LVecBase4)::operator - (other);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector4::length
- // Access: Public
- // Description: Returns the length of the vector, by the Pythagorean
- // theorem.
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATTYPE FLOATNAME(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.
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATTYPE FLOATNAME(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.
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH bool FLOATNAME(LVector4)::
- normalize() {
- FLOATTYPE l2 = length_squared();
- if (l2 == (FLOATTYPE)0.0f) {
- set(0.0f, 0.0f, 0.0f, 0.0f);
- return false;
- } else if (!IS_THRESHOLD_EQUAL(l2, 1.0f, NEARLY_ZERO(FLOATTYPE) * NEARLY_ZERO(FLOATTYPE))) {
- (*this) /= csqrt(l2);
- }
- return true;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector4::operator * scalar
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector4) FLOATNAME(LVector4)::
- operator * (FLOATTYPE scalar) const {
- return FLOATNAME(LVector4)(FLOATNAME(LVecBase4)::operator * (scalar));
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector4::operator / scalar
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector4) FLOATNAME(LVector4)::
- operator / (FLOATTYPE scalar) const {
- FLOATTYPE recip_scalar = 1.0f/scalar;
- return FLOATNAME(LVector4)(FLOATNAME(LVecBase4)::operator * (recip_scalar));
- }
|