00001 // Filename: lvector4_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 //////////////////////////////////////////////////////////////////// 00021 // Function: LVector4::Default Constructor 00022 // Access: Public 00023 // Description: 00024 //////////////////////////////////////////////////////////////////// 00025 INLINE_LINMATH FLOATNAME(LVector4):: 00026 FLOATNAME(LVector4)() { 00027 } 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Function: LVector4::Copy Constructor 00031 // Access: Public 00032 // Description: 00033 //////////////////////////////////////////////////////////////////// 00034 INLINE_LINMATH FLOATNAME(LVector4):: 00035 FLOATNAME(LVector4)(const FLOATNAME(LVecBase4) ©) : FLOATNAME(LVecBase4)(copy) { 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function: LVector4::Copy Assignment Operator 00040 // Access: Public 00041 // Description: 00042 //////////////////////////////////////////////////////////////////// 00043 INLINE_LINMATH FLOATNAME(LVector4) &FLOATNAME(LVector4):: 00044 operator = (const FLOATNAME(LVecBase4) ©) { 00045 FLOATNAME(LVecBase4)::operator = (copy); 00046 return *this; 00047 } 00048 00049 //////////////////////////////////////////////////////////////////// 00050 // Function: LVector4::Copy Fill Operator 00051 // Access: Public 00052 // Description: 00053 //////////////////////////////////////////////////////////////////// 00054 INLINE_LINMATH FLOATNAME(LVector4) &FLOATNAME(LVector4):: 00055 operator = (FLOATTYPE fill_value) { 00056 FLOATNAME(LVecBase4)::operator = (fill_value); 00057 return *this; 00058 } 00059 00060 //////////////////////////////////////////////////////////////////// 00061 // Function: LVector4::Constructor 00062 // Access: Public 00063 // Description: 00064 //////////////////////////////////////////////////////////////////// 00065 INLINE_LINMATH FLOATNAME(LVector4):: 00066 FLOATNAME(LVector4)(FLOATTYPE fill_value) : 00067 FLOATNAME(LVecBase4)(fill_value) 00068 { 00069 } 00070 00071 //////////////////////////////////////////////////////////////////// 00072 // Function: LVector4::Constructor 00073 // Access: Public 00074 // Description: 00075 //////////////////////////////////////////////////////////////////// 00076 INLINE_LINMATH FLOATNAME(LVector4):: 00077 FLOATNAME(LVector4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w) : 00078 FLOATNAME(LVecBase4)(x, y, z, w) 00079 { 00080 } 00081 00082 //////////////////////////////////////////////////////////////////// 00083 // Function: LVector4::zero Named Constructor 00084 // Access: Public 00085 // Description: Returns a zero-length vector. 00086 //////////////////////////////////////////////////////////////////// 00087 INLINE_LINMATH const FLOATNAME(LVector4) &FLOATNAME(LVector4):: 00088 zero() { 00089 return (const FLOATNAME(LVector4) &)FLOATNAME(LVecBase4)::zero(); 00090 } 00091 00092 //////////////////////////////////////////////////////////////////// 00093 // Function: LVector4::unit_x Named Constructor 00094 // Access: Public 00095 // Description: Returns a unit X vector. 00096 //////////////////////////////////////////////////////////////////// 00097 INLINE_LINMATH const FLOATNAME(LVector4) &FLOATNAME(LVector4):: 00098 unit_x() { 00099 return (const FLOATNAME(LVector4) &)FLOATNAME(LVecBase4)::unit_x(); 00100 } 00101 00102 //////////////////////////////////////////////////////////////////// 00103 // Function: LVector4::unit_y Named Constructor 00104 // Access: Public 00105 // Description: Returns a unit Y vector. 00106 //////////////////////////////////////////////////////////////////// 00107 INLINE_LINMATH const FLOATNAME(LVector4) &FLOATNAME(LVector4):: 00108 unit_y() { 00109 return (const FLOATNAME(LVector4) &)FLOATNAME(LVecBase4)::unit_y(); 00110 } 00111 00112 //////////////////////////////////////////////////////////////////// 00113 // Function: LVector4::unit_z Named Constructor 00114 // Access: Public 00115 // Description: Returns a unit Z vector. 00116 //////////////////////////////////////////////////////////////////// 00117 INLINE_LINMATH const FLOATNAME(LVector4) &FLOATNAME(LVector4):: 00118 unit_z() { 00119 return (const FLOATNAME(LVector4) &)FLOATNAME(LVecBase4)::unit_z(); 00120 } 00121 00122 //////////////////////////////////////////////////////////////////// 00123 // Function: LVector4::unit_w Named Constructor 00124 // Access: Public 00125 // Description: Returns a unit W vector. 00126 //////////////////////////////////////////////////////////////////// 00127 INLINE_LINMATH const FLOATNAME(LVector4) &FLOATNAME(LVector4):: 00128 unit_w() { 00129 return (const FLOATNAME(LVector4) &)FLOATNAME(LVecBase4)::unit_w(); 00130 } 00131 00132 //////////////////////////////////////////////////////////////////// 00133 // Function: LVector4::unary - 00134 // Access: Public 00135 // Description: 00136 //////////////////////////////////////////////////////////////////// 00137 INLINE_LINMATH FLOATNAME(LVector4) FLOATNAME(LVector4):: 00138 operator - () const { 00139 return FLOATNAME(LVecBase4)::operator - (); 00140 } 00141 00142 //////////////////////////////////////////////////////////////////// 00143 // Function: LVector4::vector + vecbase 00144 // Access: Public 00145 // Description: 00146 //////////////////////////////////////////////////////////////////// 00147 INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVector4):: 00148 operator + (const FLOATNAME(LVecBase4) &other) const { 00149 return FLOATNAME(LVecBase4)::operator + (other); 00150 } 00151 00152 //////////////////////////////////////////////////////////////////// 00153 // Function: LVector4::vector + vector 00154 // Access: Public 00155 // Description: 00156 //////////////////////////////////////////////////////////////////// 00157 INLINE_LINMATH FLOATNAME(LVector4) FLOATNAME(LVector4):: 00158 operator + (const FLOATNAME(LVector4) &other) const { 00159 return FLOATNAME(LVecBase4)::operator + (other); 00160 } 00161 00162 //////////////////////////////////////////////////////////////////// 00163 // Function: LVector4::vector - vecbase 00164 // Access: Public 00165 // Description: 00166 //////////////////////////////////////////////////////////////////// 00167 INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVector4):: 00168 operator - (const FLOATNAME(LVecBase4) &other) const { 00169 return FLOATNAME(LVecBase4)::operator - (other); 00170 } 00171 00172 //////////////////////////////////////////////////////////////////// 00173 // Function: LVector4::vector - vector 00174 // Access: Public 00175 // Description: 00176 //////////////////////////////////////////////////////////////////// 00177 INLINE_LINMATH FLOATNAME(LVector4) FLOATNAME(LVector4):: 00178 operator - (const FLOATNAME(LVector4) &other) const { 00179 return FLOATNAME(LVecBase4)::operator - (other); 00180 } 00181 00182 //////////////////////////////////////////////////////////////////// 00183 // Function: LVector4::length 00184 // Access: Public 00185 // Description: Returns the length of the vector, by the Pythagorean 00186 // theorem. 00187 //////////////////////////////////////////////////////////////////// 00188 INLINE_LINMATH FLOATTYPE FLOATNAME(LVector4):: 00189 length() const { 00190 return csqrt((*this).dot(*this)); 00191 } 00192 00193 //////////////////////////////////////////////////////////////////// 00194 // Function: LVector4::length_squared 00195 // Access: Public 00196 // Description: Returns the square of the vector's length, cheap and 00197 // easy. 00198 //////////////////////////////////////////////////////////////////// 00199 INLINE_LINMATH FLOATTYPE FLOATNAME(LVector4):: 00200 length_squared() const { 00201 return (*this).dot(*this); 00202 } 00203 00204 //////////////////////////////////////////////////////////////////// 00205 // Function: LVector4::normalize 00206 // Access: Public 00207 // Description: Normalizes the vector in place. Returns true if the 00208 // vector was normalized, false if it was a zero-length 00209 // vector. 00210 //////////////////////////////////////////////////////////////////// 00211 INLINE_LINMATH bool FLOATNAME(LVector4):: 00212 normalize() { 00213 FLOATTYPE l2 = length_squared(); 00214 if (l2 == (FLOATTYPE)0.0f) { 00215 set(0.0f, 0.0f, 0.0f, 0.0f); 00216 return false; 00217 00218 } else if (!IS_THRESHOLD_EQUAL(l2, 1.0f, NEARLY_ZERO(FLOATTYPE) * NEARLY_ZERO(FLOATTYPE))) { 00219 (*this) /= csqrt(l2); 00220 } 00221 00222 return true; 00223 } 00224 00225 //////////////////////////////////////////////////////////////////// 00226 // Function: LVector4::operator * scalar 00227 // Access: Public 00228 // Description: 00229 //////////////////////////////////////////////////////////////////// 00230 INLINE_LINMATH FLOATNAME(LVector4) FLOATNAME(LVector4):: 00231 operator * (FLOATTYPE scalar) const { 00232 return FLOATNAME(LVector4)(FLOATNAME(LVecBase4)::operator * (scalar)); 00233 } 00234 00235 //////////////////////////////////////////////////////////////////// 00236 // Function: LVector4::operator / scalar 00237 // Access: Public 00238 // Description: 00239 //////////////////////////////////////////////////////////////////// 00240 INLINE_LINMATH FLOATNAME(LVector4) FLOATNAME(LVector4):: 00241 operator / (FLOATTYPE scalar) const { 00242 FLOATTYPE recip_scalar = 1.0f/scalar; 00243 return FLOATNAME(LVector4)(FLOATNAME(LVecBase4)::operator * (recip_scalar)); 00244 }