Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

vector4.inl

Go to the documentation of this file.
00001 /*
00002     Sheep - A Rigid Body Dynamics Engine
00003     Copyright (C) 2001-2004 Francois Beaune
00004     Contact: http://toxicengine.sourceforge.net/
00005 
00006     This file is part of Sheep.
00007 
00008     Sheep is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     Sheep is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with Sheep; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 inline
00024 Vector4::Vector4() {}
00025 
00026 inline
00027 Vector4::Vector4(Real r) :
00028     m_x(r),
00029     m_y(r),
00030     m_z(r),
00031     m_w(r) {}
00032 
00033 inline
00034 Vector4::Vector4(const Vector4 &v) :
00035     m_x(v.m_x),
00036     m_y(v.m_y),
00037     m_z(v.m_z),
00038     m_w(v.m_w) {}
00039 
00040 inline
00041 Vector4::Vector4(Real x, Real y, Real z, Real w) :
00042     m_x(x),
00043     m_y(y),
00044     m_z(z),
00045     m_w(w) {}
00046 
00047 inline
00048 Vector4 &Vector4::operator=(Real r) {
00049     m_x = m_y = m_z = m_w = r;
00050 
00051     return *this;
00052 }
00053 
00054 inline
00055 Vector4 &Vector4::operator=(const Vector4 &v) {
00056     m_x = v.m_x;
00057     m_y = v.m_y;
00058     m_z = v.m_z;
00059     m_w = v.m_w;
00060 
00061     return *this;
00062 }
00063 
00064 inline
00065 Vector4 Vector4::operator+(const Vector4 &v) const {
00066     return Vector4(
00067         m_x + v.m_x,
00068         m_y + v.m_y,
00069         m_z + v.m_z,
00070         m_w + v.m_w);
00071 }
00072 
00073 inline
00074 Vector4 Vector4::operator-(const Vector4 &v) const {
00075     return Vector4(
00076         m_x - v.m_x,
00077         m_y - v.m_y,
00078         m_z - v.m_z,
00079         m_w - v.m_w);
00080 }
00081 
00082 inline
00083 Vector4 Vector4::operator-() const {
00084     return Vector4(-m_x, -m_y, -m_z, -m_w);
00085 }
00086 
00087 inline
00088 Vector4 Vector4::operator*(Real r) const {
00089     return Vector4(
00090         m_x * r,
00091         m_y * r,
00092         m_z * r,
00093         m_w * r);
00094 }
00095 
00096 inline
00097 Vector4 Vector4::operator/(Real r) const {
00098     const Real inv_r = 1.0 / r;
00099 
00100     return Vector4(
00101         m_x * inv_r,
00102         m_y * inv_r,
00103         m_z * inv_r,
00104         m_w * inv_r);
00105 }
00106 
00107 inline
00108 Vector4 &Vector4::operator+=(const Vector4 &v) {
00109     m_x += v.m_x;
00110     m_y += v.m_y;
00111     m_z += v.m_z;
00112     m_w += v.m_w;
00113 
00114     return *this;
00115 }
00116 
00117 inline
00118 Vector4 &Vector4::operator-=(const Vector4 &v) {
00119     m_x -= v.m_x;
00120     m_y -= v.m_y;
00121     m_z -= v.m_z;
00122     m_w -= v.m_w;
00123 
00124     return *this;
00125 }
00126 
00127 inline
00128 Vector4 &Vector4::operator*=(Real r) {
00129     m_x *= r;
00130     m_y *= r;
00131     m_z *= r;
00132     m_w *= r;
00133 
00134     return *this;
00135 }
00136 
00137 inline
00138 Vector4 &Vector4::operator/=(Real r) {
00139     const Real inv_r = 1.0 / r;
00140 
00141     m_x *= inv_r;
00142     m_y *= inv_r;
00143     m_z *= inv_r;
00144     m_w *= inv_r;
00145 
00146     return *this;
00147 }
00148 
00149 inline
00150 Real Vector4::operator*(const Vector4 &v) const {
00151     return
00152         m_x * v.m_x +
00153         m_y * v.m_y +
00154         m_z * v.m_z +
00155         m_w * v.m_w;
00156 }
00157 
00158 inline
00159 Real Vector4::SquareNorm() const {
00160     return m_x * m_x + m_y * m_y + m_z * m_z + m_w * m_w;
00161 }
00162 
00163 inline
00164 Real Vector4::Norm() const {
00165     return sqrt(SquareNorm());
00166 }
00167 
00168 inline
00169 Vector4 Vector4::Normalized() const {
00170     const Real n = Norm();
00171     return n == 0.0 ? Vector4(1.0, 0.0, 0.0, 0.0) : *this / n;
00172 }
00173 
00174 inline
00175 void Vector4::Normalize() {
00176     const Real n = Norm();
00177 
00178     if(n == 0.0) {
00179         m_x = 1.0;
00180         m_y = m_z = m_w = 0.0;
00181     } else {
00182         const Real inv_n = 1.0 / n;
00183         m_x *= inv_n;
00184         m_y *= inv_n;
00185         m_z *= inv_n;
00186         m_w *= inv_n;
00187     }
00188 }
00189 
00190 inline
00191 bool Vector4::IsUnitLength(Real e /*= EPS*/) const {
00192     return feq(SquareNorm(), 1.0, e);
00193 }
00194 
00195 inline
00196 Vector4 operator*(Real r, const Vector4 &v) {
00197     return v * r;
00198 }

Generated on Tue May 11 01:31:53 2004 for toxic by doxygen 1.3.6