00001 // $Id: vector3d.cpp 751 2006-03-31 15:43:49Z alex $ 00002 // vector3d.cpp 00003 // 00004 // Author : Mike 00005 // Purpose : Implementation file for class Vector3D. 00006 // Version : 1.0 00007 // Started : 30/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 #include "camtypes.h" 00106 #include "macros.h" 00107 #include "vector3d.h" 00108 00109 00110 void Vector3D::FaceForward(const Vector3D& q) 00111 { 00112 if (Dot(q)<0.0) return; 00113 x = -x; 00114 y = -y; 00115 z = -z; 00116 } 00117 00118 00119 double Vector3D::Normalise() 00120 { 00121 double l,m; 00122 l = sqrt(x*x + y*y + z*z); 00123 if (l!=0) 00124 { 00125 m=1.0/l; 00126 x*=m; 00127 y*=m; 00128 z*=m; 00129 } 00130 else 00131 { 00132 x=1.0; 00133 y=0; 00134 z=0; 00135 }; 00136 00137 return l; 00138 } 00139 00140 Vector3D Vector3D::NormaliseI() 00141 { 00142 double l,m; 00143 l = sqrt(x*x + y*y + z*z); 00144 if (l!=0) 00145 { 00146 m=1.0/l; 00147 x*=m; 00148 y*=m; 00149 z*=m; 00150 } 00151 else 00152 { 00153 x=0; 00154 y=0; 00155 z=0; 00156 }; 00157 00158 return *this; 00159 } 00160 00161 Vector3D Vector3D::Half(const Vector3D& p,const Vector3D& q) 00162 { 00163 return ((p+q).NormaliseI()); 00164 } 00165 00166 00167 Vector3D Vector3D::Cross(const Vector3D& q) const 00168 { 00169 Vector3D r; 00170 r.x = y*q.z - z*q.y; 00171 r.y = z*q.x - x*q.z; 00172 r.z = x*q.y - y*q.x; 00173 return r; 00174 } 00175 00176 00177 Vector3D Vector3D::TorusUV(double srad, double trad, double u, double v) 00178 { 00179 Vector3D p; 00180 double theta,phi; 00181 00182 theta = XS_2PI*u; 00183 phi = XS_2PI*v; 00184 00185 p.x = srad + trad*cos(theta); 00186 p.y = trad*sin(theta); 00187 00188 p.z = p.x*sin(phi); 00189 p.x = p.x*cos(phi); 00190 00191 // translate into the positive octant 00192 p.x += srad+trad; 00193 p.y += trad; 00194 p.z += srad+trad; 00195 00196 return p; 00197 }