/// This file is part of the X3DToolKit library /// Copyright (C) 2002-2004 Yannick Le Goc (legoc@imag.fr) /// http://artis.imag.fr/Members/Yannick.Legoc/X3D/ /// This library is free software; you can redistribute it and/or /// modify it under the terms of the GNU Lesser General Public /// License as published by the Free Software Foundation; either /// version 2.1 of the License, or (at your option) any later version. /// This library is distributed in the hope that it will be useful, /// but WITHOUT ANY WARRANTY; without even the implied warranty of /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU /// Lesser General Public License for more details. /// You should have received a copy of the GNU Lesser General Public /// License along with this library; if not, write to the Free Software /// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #ifndef X3DTK_SFVEC3F_H #define X3DTK_SFVEC3F_H #include "Platform.h" #include #include namespace X3DTK { class SFString; class SFPoint3f; /*! \brief Class declared in providing a 3D vector. * * SFVec3f is a vector in an affin space, which is different from a point represented * by the SFPoint3f class. When multiplied by a SFMatrix34f, the translation is not applied. * * \ingroup base */ class SFVec3f { public: /// x coordinates. float x; /// y coordinates. float y; /// z coordinates. float z; /// Constructor. SFVec3f(); /// Constructor with x, y and z coordinates in parameters. SFVec3f(float x, float y, float z); /// Copy constructor SFVec3f(const SFVec3f &v); /// Overloaded assignment operator. SFVec3f &operator= (const SFVec3f &v); /// Overloaded operator. SFVec3f &operator+= (const SFVec3f &v); /// Overloaded operator. SFVec3f &operator-= (const SFVec3f &v); /// Explicit constructor from a string of which format is "x y z". explicit SFVec3f(const SFString &s); /// Conversion from point to vector. explicit SFVec3f(const SFPoint3f &P); /// Bracket operator. inline float &operator[](int i) {return (&x)[i];}; /// Bracket operator. inline const float &operator[](int i) const {return (&x)[i];}; /// Overloaded operator==. friend bool operator== (const SFVec3f &v1, const SFVec3f &v2); /// Overloaded operator!=. friend bool operator!= (const SFVec3f &v1, const SFVec3f &v2); /// Overloaded operator+. friend SFVec3f operator+ (const SFVec3f &v1, const SFVec3f &v2); /// Overloaded operator-. friend SFVec3f operator- (const SFVec3f &v1, const SFVec3f &v2); /// Overloaded operator-. friend SFVec3f operator- (const SFVec3f &v); /// Overloaded operator*. friend float operator* (const SFVec3f &v1, const SFVec3f &v2); /// Overloaded operator*. friend SFVec3f operator* (const float a, const SFVec3f &v); /// Cross product between two vectors. friend SFVec3f crossprod(const SFVec3f &v1, const SFVec3f &v2); /// Returns the norm of the vector. float norm() const; /// Normalizes the vector. SFVec3f normalize(); /// Returns the vector normalized but doesn't change the vector. SFVec3f normalized() const; /// Returns the pointed array. inline float *f_data() {return &x;}; /// Returns the pointed array. inline const float *f_data() const {return &x;}; /// Returns the pointed array. inline operator float *() {return &x;}; /// Returns the pointed array. inline operator const float *() const {return &x;}; /// Converts into string. SFString toSFString() const; /// Null vector. static const SFVec3f null; }; } #endif