| VRS - The Virtual Rendering System |
| version 3.3 |
00001 /****************************************************************************** 00002 * VRS - The Virtual Rendering System 00003 * Copyright (C) 2003 Computer Graphics Systems Group at the 00004 * Hasso-Plattner-Institute (HPI), Potsdam, Germany. 00005 * 00006 * This library is free software; you can redistribute it and/or modify it 00007 * under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2.1 of the License, or (at 00009 * your option) any later version. This library is distributed in the hope 00010 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 00011 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU Lesser General Public License for more details. You should have received 00013 * a copy of the GNU Lesser+ General Public License along with this library; if 00014 * not, write to the FreeSoftware Foundation, Inc., 59 Temple Place, Suite 330, 00015 * Boston, MA, 02111-1307, USA. 00016 ******************************************************************************/ 00017 00018 // $Id: vector.h 4677 2005-02-20 12:29:38Z maass $ 00019 // $Date: 2005-02-20 13:29:38 +0100 (Sun, 20 Feb 2005) $ 00020 // $Revision: 4677 $ 00021 // $State$ 00022 // $Author: maass $ 00023 // 00024 // $Log$ 00025 // Revision 1.32 2005/02/20 12:29:38 maass 00026 // add documentation for the dotProduct method 00027 // 00028 // Revision 1.31 2005/01/03 01:43:08 klimetschek 00029 // - modified win32 project layout, splitted vrs.vcproj into vrs_container, vrs_core, vrs_sg, vrs_image, vrs_opengl and vrs_io 00030 // - removed vrs.vcproj 00031 // minor things: 00032 // - added all glutexamples to vrs4glut.sln 00033 // - fixed some problems in glutexamples 00034 // - removed all project references from all VS projects (using solution wide project dependencies instead) 00035 // 00036 // Revision 1.30 2004/11/05 13:58:10 basch 00037 // Class comment changed (Doxygen style) 00038 // 00039 // Revision 1.29 2004/10/04 06:07:22 baumann 00040 // moved serialization of VRS::Color and VRS::Vector into VRS::SerializationManager 00041 // 00042 // Revision 1.28 2004/05/24 14:54:09 bohnet 00043 // static member functions for conversions between Vector3f and Vector3d added 00044 // 00045 // Revision 1.27 2004/05/18 07:38:06 bohnet 00046 // Macros added for conversions between Vector3f and Vector3d 00047 // 00048 // Revision 1.26 2004/03/12 16:28:39 baumann 00049 // macros VRS_NAMESPACE_BEGIN/_END expanded and removed 00050 // 00051 // Revision 1.25 2004/01/19 17:07:21 baumann 00052 // moved VRS::Document from vrs/ to vrs/io/ 00053 // 00054 // Revision 1.24 2004/01/19 13:14:41 baumann 00055 // #include <vrs/io/document.h> added or removed 00056 // 00057 // Revision 1.23 2004/01/19 11:43:57 baumann 00058 // serialization mechanism improved 00059 // 00060 // Revision 1.22 2003/07/02 11:32:07 kirsch 00061 // explicitely declared std namespace where appropriate 00062 // 00063 // Revision 1.21 2003/06/23 15:27:37 baumann 00064 // VRS_CORE_API removed from template functions 00065 // 00066 // Revision 1.20 2003/06/23 14:20:45 baumann 00067 // moved friends outside the class scope 00068 // 00069 // Revision 1.19 2003/06/23 13:26:22 baumann 00070 // - new template classes Vector3Base<T> and Matrix4x4Base<T> added 00071 // - Vector is now a "typedef Vector3Base<double> Vector" 00072 // - Matrix is now a "typedef Matrix4x4Base<double> Matrix" 00073 // - method Matrix::rep() renamed to Matrix::pointer() 00074 // - enums Matrix::MatrixType { MT_Identity, MT_Scale, MT_Translate, MT_Unknown, 00075 // MT_Check } changed to Matrix::MatrixType { MT_Identity, MT_Scale, 00076 // MT_Translate, MT_Unknown, MT_Check } 00077 // 00078 // Revision 1.18 2003/05/16 05:19:34 baumann 00079 // - new method: bool Vector::isOrigin() const; 00080 // - added keyword "explicit" to some ctors of some base classes 00081 // (e.g. Color, Vector, Bounds, Matrix, Area, ...) 00082 // - function abs(const Vector& v) removed (Vector::abs() still exists!) 00083 // - function abs2(const Vector& v) removed (Vector::abs2() still exists!) 00084 // - vertexdata.tli added 00085 // 00086 // Revision 1.17 2003/05/15 10:03:57 baumann 00087 // - new class VertexData<DIM, T> added 00088 // - class Color is now derived from VertexData<4, double> 00089 // - renamed method Color::rep() to Color::pointer() 00090 // - class Vector is now derived from VertexData<3, double> 00091 // - renamed method Vector::rep() to Vector::pointer() 00092 // - class VertexAttributeGL<DIM, T> removed 00093 // 00094 // Revision 1.16 2002/10/29 10:32:52 baumann 00095 // macros VRS_CLASSNAME_* and VRS_IMPL_TYPEINFO_* removed 00096 // 00097 // Revision 1.15 2002/04/08 09:47:29 baumann 00098 // makeCWTriangleNormal() and makeCCWTriangleNormal() removed 00099 // "static const Vector Vector::origin;" added 00100 // 00101 // Revision 1.14 2002/03/25 12:12:03 baumann 00102 // keyword "explicit" removed again 00103 // 00104 // Revision 1.13 2002/03/25 09:21:47 baumann 00105 // keyword "explicit" added to constructor with only one argument 00106 // 00107 // Revision 1.12 2002/03/21 21:43:16 baumann 00108 // code clean up 00109 // 00110 // Revision 1.11 2002/02/19 10:34:13 kosta 00111 // undone all changes since 2002-02-15 00112 // 00113 // Revision 1.8 2002/02/13 16:28:11 kosta 00114 // implementation of the serialize()-method moved outside the class declaration 00115 // 00116 // Revision 1.7 2002/02/05 07:48:25 kosta 00117 // new persistency macros: 00118 // VRS_SERIALIZABLE(CLASS_NAME); 00119 // VRS_SERIALIZABLE_ABSTRACT_CLASS(CLASS_NAME); 00120 // VRS_SERIALIZABLE_NO_SO_CLASS(CLASS_NAME) 00121 // 00122 // Revision 1.6 2002/02/04 11:54:37 kosta 00123 // persistency rewritten (for better namespace support) 00124 // 00125 // Revision 1.5 2002/01/15 16:25:54 kosta 00126 // macros rewritten for a better namespace support 00127 // 00128 // Revision 1.4 2001/12/05 15:51:44 kersting 00129 // added abs, abs2 and dotProduct method 00130 // 00131 // Revision 1.3 2001/11/15 13:13:58 kirsch 00132 // GCC fix: removed accidental inlines for abs() and abs2() 00133 // 00134 // Revision 1.2 2001/11/13 16:36:31 kirsch 00135 // changed line feed to unix style (removed control-M) 00136 // 00137 // Revision 1.1.1.1 2001/06/08 08:09:20 kirsch 00138 // imported alpha-version by olli 00139 // 00140 00141 #ifndef VRS_VECTOR_H 00142 #define VRS_VECTOR_H 00143 00144 #include <vrs/vertexdata.h> 00145 #include <cmath> // for ::sqrt() and ::fabs() 00146 #include <iostream> 00147 00148 namespace VRS { 00149 00150 class Document; 00151 00153 template<typename T> 00154 class Vector3Base : public VertexData<3, T> { 00155 00156 public: 00157 explicit Vector3Base(T x = T(0.0), T y = T(0.0), T z = T(0.0)); 00158 00159 bool operator==(const Vector3Base& other) const; 00160 bool operator!=(const Vector3Base& other) const; 00161 bool operator< (const Vector3Base& other) const; 00163 00164 T& operator[](unsigned int index); 00165 T operator[](unsigned int index) const; 00167 00168 Vector3Base& operator+=(const Vector3Base& other); 00169 Vector3Base& operator-=(const Vector3Base& other); 00170 Vector3Base& operator*=(const Vector3Base& other); // cross product 00171 Vector3Base& operator*=(T scalar); 00172 Vector3Base& operator/=(T scalar); 00173 00174 Vector3Base operator+(const Vector3Base& other) const; 00175 Vector3Base operator-(const Vector3Base& other) const; 00176 Vector3Base operator*(const Vector3Base& other) const; // cross product 00177 Vector3Base operator*(T scalar) const; 00178 Vector3Base operator/(T scalar) const; 00179 Vector3Base operator-() const; 00180 00181 Vector3Base normalized() const; 00182 bool normalize(); 00187 T abs() const; 00188 T abs2() const; 00189 T dotProduct(const Vector3Base& other) const; 00191 Vector3Base crossProduct(const Vector3Base& other) const; 00197 static const Vector3Base& origin; 00198 static void convertVector3dToVector3f(const Vector3Base<double>&, Vector3Base<float>&); 00199 static void convertVector3fToVector3d(const Vector3Base<float>&, Vector3Base<double>&); 00200 bool isOrigin() const; 00201 00202 private: 00203 typedef VertexData<3, T> BASE; 00204 }; 00205 00206 00207 template<typename T> 00208 Vector3Base<T> operator*(T scalar, const Vector3Base<T>& vec); 00209 00210 template<typename T> 00211 T dotProduct(const Vector3Base<T>& vec1, const Vector3Base<T>& vec2); 00212 00213 template<typename T> 00214 Vector3Base<T> crossProduct(const Vector3Base<T>& vec1, const Vector3Base<T>& vec2); 00215 00216 template<typename T> 00217 std::ostream& operator<<(std::ostream& os, const Vector3Base<T>& vec); 00218 00219 template<typename T> 00220 std::istream& operator>>(std::istream& is, Vector3Base<T>& vec); 00221 00222 typedef Vector3Base<float> Vector3f; 00223 typedef Vector3Base<double> Vector3d; 00224 00225 typedef Vector3d Vector; 00226 00227 00228 } // namespace VRS 00229 00230 #include <vrs/vector.tli> 00231 00232 #endif // VRS_VECTOR_H