00001 // Filename: lvector2_src.I 00002 // Created by: drose (08Mar00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function: LVector2::Default Constructor 00021 // Access: Public 00022 // Description: 00023 //////////////////////////////////////////////////////////////////// 00024 INLINE_LINMATH FLOATNAME(LVector2):: 00025 FLOATNAME(LVector2)() { 00026 } 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: LVector2::Copy Constructor 00030 // Access: Public 00031 // Description: 00032 //////////////////////////////////////////////////////////////////// 00033 INLINE_LINMATH FLOATNAME(LVector2):: 00034 FLOATNAME(LVector2)(const FLOATNAME(LVecBase2) ©) : FLOATNAME(LVecBase2)(copy) { 00035 } 00036 00037 //////////////////////////////////////////////////////////////////// 00038 // Function: LVector2::Copy Assignment Operator 00039 // Access: Public 00040 // Description: 00041 //////////////////////////////////////////////////////////////////// 00042 INLINE_LINMATH FLOATNAME(LVector2) &FLOATNAME(LVector2):: 00043 operator = (const FLOATNAME(LVecBase2) ©) { 00044 FLOATNAME(LVecBase2)::operator = (copy); 00045 return *this; 00046 } 00047 00048 //////////////////////////////////////////////////////////////////// 00049 // Function: LVector2::Copy Fill Operator 00050 // Access: Public 00051 // Description: 00052 //////////////////////////////////////////////////////////////////// 00053 INLINE_LINMATH FLOATNAME(LVector2) &FLOATNAME(LVector2):: 00054 operator = (FLOATTYPE fill_value) { 00055 FLOATNAME(LVecBase2)::operator = (fill_value); 00056 return *this; 00057 } 00058 00059 //////////////////////////////////////////////////////////////////// 00060 // Function: LVector2::Constructor 00061 // Access: Public 00062 // Description: 00063 //////////////////////////////////////////////////////////////////// 00064 INLINE_LINMATH FLOATNAME(LVector2):: 00065 FLOATNAME(LVector2)(FLOATTYPE fill_value) : 00066 FLOATNAME(LVecBase2)(fill_value) 00067 { 00068 } 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: LVector2::Constructor 00072 // Access: Public 00073 // Description: 00074 //////////////////////////////////////////////////////////////////// 00075 INLINE_LINMATH FLOATNAME(LVector2):: 00076 FLOATNAME(LVector2)(FLOATTYPE x, FLOATTYPE y) : 00077 FLOATNAME(LVecBase2)(x, y) 00078 { 00079 } 00080 00081 //////////////////////////////////////////////////////////////////// 00082 // Function: LVector2::zero Named Constructor 00083 // Access: Public 00084 // Description: Returns a zero-length vector. 00085 //////////////////////////////////////////////////////////////////// 00086 INLINE_LINMATH const FLOATNAME(LVector2) &FLOATNAME(LVector2):: 00087 zero() { 00088 return (const FLOATNAME(LVector2) &)FLOATNAME(LVecBase2)::zero(); 00089 } 00090 00091 //////////////////////////////////////////////////////////////////// 00092 // Function: LVector2::unit_x Named Constructor 00093 // Access: Public 00094 // Description: Returns a unit X vector. 00095 //////////////////////////////////////////////////////////////////// 00096 INLINE_LINMATH const FLOATNAME(LVector2) &FLOATNAME(LVector2):: 00097 unit_x() { 00098 return (const FLOATNAME(LVector2) &)FLOATNAME(LVecBase2)::unit_x(); 00099 } 00100 00101 //////////////////////////////////////////////////////////////////// 00102 // Function: LVector2::unit_y Named Constructor 00103 // Access: Public 00104 // Description: Returns a unit Y vector. 00105 //////////////////////////////////////////////////////////////////// 00106 INLINE_LINMATH const FLOATNAME(LVector2) &FLOATNAME(LVector2):: 00107 unit_y() { 00108 return (const FLOATNAME(LVector2) &)FLOATNAME(LVecBase2)::unit_y(); 00109 } 00110 00111 //////////////////////////////////////////////////////////////////// 00112 // Function: LVector2::unary - 00113 // Access: Public 00114 // Description: 00115 //////////////////////////////////////////////////////////////////// 00116 INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LVector2):: 00117 operator - () const { 00118 return FLOATNAME(LVecBase2)::operator - (); 00119 } 00120 00121 //////////////////////////////////////////////////////////////////// 00122 // Function: LVector2::vector + vecbase 00123 // Access: Public 00124 // Description: 00125 //////////////////////////////////////////////////////////////////// 00126 INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVector2):: 00127 operator + (const FLOATNAME(LVecBase2) &other) const { 00128 return FLOATNAME(LVecBase2)::operator + (other); 00129 } 00130 00131 //////////////////////////////////////////////////////////////////// 00132 // Function: LVector2::vector + vector 00133 // Access: Public 00134 // Description: 00135 //////////////////////////////////////////////////////////////////// 00136 INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LVector2):: 00137 operator + (const FLOATNAME(LVector2) &other) const { 00138 return FLOATNAME(LVecBase2)::operator + (other); 00139 } 00140 00141 //////////////////////////////////////////////////////////////////// 00142 // Function: LVector2::vector - vecbase 00143 // Access: Public 00144 // Description: 00145 //////////////////////////////////////////////////////////////////// 00146 INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVector2):: 00147 operator - (const FLOATNAME(LVecBase2) &other) const { 00148 return FLOATNAME(LVecBase2)::operator - (other); 00149 } 00150 00151 //////////////////////////////////////////////////////////////////// 00152 // Function: LVector2::vector - vector 00153 // Access: Public 00154 // Description: 00155 //////////////////////////////////////////////////////////////////// 00156 INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LVector2):: 00157 operator - (const FLOATNAME(LVector2) &other) const { 00158 return FLOATNAME(LVecBase2)::operator - (other); 00159 } 00160 00161 //////////////////////////////////////////////////////////////////// 00162 // Function: LVector2::length 00163 // Access: Public 00164 // Description: Returns the length of the vector, by the Pythagorean 00165 // theorem. 00166 //////////////////////////////////////////////////////////////////// 00167 INLINE_LINMATH FLOATTYPE FLOATNAME(LVector2):: 00168 length() const { 00169 return csqrt((*this).dot(*this)); 00170 } 00171 00172 //////////////////////////////////////////////////////////////////// 00173 // Function: LVector2::length_squared 00174 // Access: Public 00175 // Description: Returns the square of the vector's length, cheap and 00176 // easy. 00177 //////////////////////////////////////////////////////////////////// 00178 INLINE_LINMATH FLOATTYPE FLOATNAME(LVector2):: 00179 length_squared() const { 00180 return (*this).dot(*this); 00181 } 00182 00183 //////////////////////////////////////////////////////////////////// 00184 // Function: LVector2::normalize 00185 // Access: Public 00186 // Description: Normalizes the vector in place. Returns true if the 00187 // vector was normalized, false if it was a zero-length 00188 // vector. 00189 //////////////////////////////////////////////////////////////////// 00190 INLINE_LINMATH bool FLOATNAME(LVector2):: 00191 normalize() { 00192 FLOATTYPE l2 = length_squared(); 00193 if (l2 == (FLOATTYPE)0.0f) { 00194 set(0.0f, 0.0f); 00195 return false; 00196 00197 } else if (!IS_THRESHOLD_EQUAL(l2, 1.0f, NEARLY_ZERO(FLOATTYPE) * NEARLY_ZERO(FLOATTYPE))) { 00198 (*this) /= csqrt(l2); 00199 } 00200 00201 return true; 00202 } 00203 00204 //////////////////////////////////////////////////////////////////// 00205 // Function: LVector2::operator * scalar 00206 // Access: Public 00207 // Description: 00208 //////////////////////////////////////////////////////////////////// 00209 INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LVector2):: 00210 operator * (FLOATTYPE scalar) const { 00211 return FLOATNAME(LVector2)(FLOATNAME(LVecBase2)::operator * (scalar)); 00212 } 00213 00214 //////////////////////////////////////////////////////////////////// 00215 // Function: LVector2::operator / scalar 00216 // Access: Public 00217 // Description: 00218 //////////////////////////////////////////////////////////////////// 00219 INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LVector2):: 00220 operator / (FLOATTYPE scalar) const { 00221 FLOATTYPE recip_scalar = 1.0f/scalar; 00222 return FLOATNAME(LVector2)(FLOATNAME(LVecBase2)::operator * (recip_scalar)); 00223 }