00001 // $Id: vector3d.h 751 2006-03-31 15:43:49Z alex $ 00002 // vector3d.h 00003 // 00004 // Author : Mike 00005 // Purpose : Definition file for vector3d class 00006 // Version : 1.0 00007 // Started : 29/11/95 00008 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE 00009 ================================XARAHEADERSTART=========================== 00010 00011 Xara LX, a vector drawing and manipulation program. 00012 Copyright (C) 1993-2006 Xara Group Ltd. 00013 Copyright on certain contributions may be held in joint with their 00014 respective authors. See AUTHORS file for details. 00015 00016 LICENSE TO USE AND MODIFY SOFTWARE 00017 ---------------------------------- 00018 00019 This file is part of Xara LX. 00020 00021 Xara LX is free software; you can redistribute it and/or modify it 00022 under the terms of the GNU General Public License version 2 as published 00023 by the Free Software Foundation. 00024 00025 Xara LX and its component source files are distributed in the hope 00026 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00027 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00028 See the GNU General Public License for more details. 00029 00030 You should have received a copy of the GNU General Public License along 00031 with Xara LX (see the file GPL in the root directory of the 00032 distribution); if not, write to the Free Software Foundation, Inc., 51 00033 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00034 00035 00036 ADDITIONAL RIGHTS 00037 ----------------- 00038 00039 Conditional upon your continuing compliance with the GNU General Public 00040 License described above, Xara Group Ltd grants to you certain additional 00041 rights. 00042 00043 The additional rights are to use, modify, and distribute the software 00044 together with the wxWidgets library, the wxXtra library, and the "CDraw" 00045 library and any other such library that any version of Xara LX relased 00046 by Xara Group Ltd requires in order to compile and execute, including 00047 the static linking of that library to XaraLX. In the case of the 00048 "CDraw" library, you may satisfy obligation under the GNU General Public 00049 License to provide source code by providing a binary copy of the library 00050 concerned and a copy of the license accompanying it. 00051 00052 Nothing in this section restricts any of the rights you have under 00053 the GNU General Public License. 00054 00055 00056 SCOPE OF LICENSE 00057 ---------------- 00058 00059 This license applies to this program (XaraLX) and its constituent source 00060 files only, and does not necessarily apply to other Xara products which may 00061 in part share the same code base, and are subject to their own licensing 00062 terms. 00063 00064 This license does not apply to files in the wxXtra directory, which 00065 are built into a separate library, and are subject to the wxWindows 00066 license contained within that directory in the file "WXXTRA-LICENSE". 00067 00068 This license does not apply to the binary libraries (if any) within 00069 the "libs" directory, which are subject to a separate license contained 00070 within that directory in the file "LIBS-LICENSE". 00071 00072 00073 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS 00074 ---------------------------------------------- 00075 00076 Subject to the terms of the GNU Public License (see above), you are 00077 free to do whatever you like with your modifications. However, you may 00078 (at your option) wish contribute them to Xara's source tree. You can 00079 find details of how to do this at: 00080 http://www.xaraxtreme.org/developers/ 00081 00082 Prior to contributing your modifications, you will need to complete our 00083 contributor agreement. This can be found at: 00084 http://www.xaraxtreme.org/developers/contribute/ 00085 00086 Please note that Xara will not accept modifications which modify any of 00087 the text between the start and end of this header (marked 00088 XARAHEADERSTART and XARAHEADEREND). 00089 00090 00091 MARKS 00092 ----- 00093 00094 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara 00095 designs are registered or unregistered trademarks, design-marks, and/or 00096 service marks of Xara Group Ltd. All rights in these marks are reserved. 00097 00098 00099 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK. 00100 http://www.xara.com/ 00101 00102 =================================XARAHEADEREND============================ 00103 */ 00104 00105 #ifndef INC_VEC3D 00106 #define INC_VEC3D 00107 00108 #include <math.h> 00109 00110 /******************************************************************************************** 00111 00112 > class Vector3D 00113 00114 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00115 Created: 17/08/94 00116 Purpose: Define all 3 vector operations we need. 00117 00118 ********************************************************************************************/ 00119 00120 class Vector3D 00121 { 00122 public: 00123 Vector3D() { x=y=z=0; } 00124 Vector3D(double p) { x=y=z=p; } 00125 Vector3D(double px, double py, double pz) { x=px; y=py; z=pz; } 00126 Vector3D(const Vector3D& v) { x=v.x; y=v.y; z=v.z; } 00127 00128 inline Vector3D operator+(const Vector3D& V) const { return Vector3D(x+V.x, y+V.y, z+V.z); } 00129 inline Vector3D operator-(const Vector3D& V) const { return Vector3D(x-V.x, y-V.y, z-V.z); } 00130 inline Vector3D operator*(const Vector3D& V) const { return Vector3D(x*V.x, y*V.y, z*V.z); } 00131 inline Vector3D operator/(const Vector3D& V) const { return Vector3D(x/V.x, y/V.y, z/V.z); } 00132 00133 inline Vector3D operator+(const double& V) const { return Vector3D(x+V, y+V, z+V); } 00134 inline Vector3D operator-(const double& V) const { return Vector3D(x-V, y-V, z-V); } 00135 inline Vector3D operator*(const double& V) const { return Vector3D(x*V, y*V, z*V); } 00136 inline Vector3D operator/(const double& V) const { return Vector3D(x/V, y/V, z/V); } 00137 00138 inline Vector3D operator+() const { return Vector3D(+x, +y, +z); } 00139 inline Vector3D operator-() const { return Vector3D(-x, -y, -z); } 00140 00141 inline BOOL operator==(const Vector3D& V) { return x==V.x && y==V.y && z==V.z; } 00142 inline BOOL operator!=(const Vector3D& V) { return x!=V.x || y!=V.y || z!=V.z; } 00143 00144 inline Vector3D& operator+=(const Vector3D& V); 00145 inline Vector3D& operator-=(const Vector3D& V); 00146 inline Vector3D& operator*=(const Vector3D& V); 00147 00148 inline double xcomp() const { return x; } 00149 inline double ycomp() const { return y; } 00150 inline double zcomp() const { return z; } 00151 00152 inline double Length() const { return ( sqrt(x*x + y*y + z*z) ); } 00153 inline double SumSquares() const { return ( x*x + y*y + z*z ); } 00154 inline double Dot(const Vector3D& p) const { return ( x*p.x + y*p.y + z*p.z ); } 00155 inline double SumMult(const Vector3D& p) const { return ( x*p.x + y*p.y + z*p.z); } 00156 inline double SqrDist(const Vector3D& p) const { return (p.x-x)*(p.x-x) + (p.y-y)*(p.y-y) + (p.z-z)*(p.z-z); } 00157 inline double DistanceTo(const Vector3D& p) const { return sqrt(SqrDist(p)); } 00158 00159 inline Vector3D Mix(const Vector3D &mix, double t) const; 00160 00161 void FaceForward(const Vector3D& p); 00162 double Normalise(); 00163 Vector3D NormaliseI(); 00164 Vector3D Cross(const Vector3D& q) const; 00165 00166 //Vector3D TransformP(const Matrix3D& mat) const; 00167 //Vector3D TransformN(const Matrix3D& mat) const; 00168 //Vector3D TransformD(const Matrix3D& mat) const; 00169 00170 static Vector3D Half(const Vector3D&, const Vector3D&); 00171 static Vector3D TorusUV(double srad, double trad, double u, double v); 00172 00173 public: 00174 double x; 00175 double y; 00176 double z; 00177 }; 00178 00179 00180 00181 00182 /******************************************************************************************** 00183 00184 ********************************************************************************************/ 00185 00186 inline Vector3D& Vector3D::operator+=(const Vector3D& p) 00187 { 00188 x += p.x; 00189 y += p.y; 00190 z += p.z; 00191 return *this; 00192 } 00193 00194 inline Vector3D& Vector3D::operator-=(const Vector3D& p) 00195 { 00196 x -= p.x; 00197 y -= p.y; 00198 z -= p.z; 00199 return *this; 00200 } 00201 00202 inline Vector3D& Vector3D::operator*=(const Vector3D& p) 00203 { 00204 x *= p.x; 00205 y *= p.y; 00206 z *= p.z; 00207 return *this; 00208 } 00209 00210 inline Vector3D Vector3D::Mix(const Vector3D &mix, double t) const 00211 { 00212 Vector3D v; 00213 v.x = (1.0-t)*x + t*mix.x; 00214 v.y = (1.0-t)*y + t*mix.y; 00215 v.z = (1.0-t)*z + t*mix.z; 00216 return v; 00217 } 00218 00219 #endif