![]() |
http://www.sim.no/ http://www.coin3d.org/ |
00001 #ifndef COIN_SBVEC3D_H 00002 #define COIN_SBVEC3D_H 00003 00004 /**************************************************************************\ 00005 * 00006 * This file is part of the Coin 3D visualization library. 00007 * Copyright (C) by Kongsberg Oil & Gas Technologies. 00008 * 00009 * This library is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU General Public License 00011 * ("GPL") version 2 as published by the Free Software Foundation. 00012 * See the file LICENSE.GPL at the root directory of this source 00013 * distribution for additional information about the GNU GPL. 00014 * 00015 * For using Coin with software that can not be combined with the GNU 00016 * GPL, and for taking advantage of the additional benefits of our 00017 * support services, please contact Kongsberg Oil & Gas Technologies 00018 * about acquiring a Coin Professional Edition License. 00019 * 00020 * See http://www.coin3d.org/ for more information. 00021 * 00022 * Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY. 00023 * http://www.sim.no/ sales@sim.no coin-support@coin3d.org 00024 * 00025 \**************************************************************************/ 00026 00027 #include <stdio.h> 00028 #include <Inventor/SbBasic.h> 00029 #ifndef NDEBUG 00030 #include <Inventor/errors/SoDebugError.h> 00031 #endif // !NDEBUG 00032 00033 class SbVec3f; 00034 class SbVec3b; 00035 class SbVec3s; 00036 class SbVec3i32; 00037 class SbDPPlane; 00038 00039 class COIN_DLL_API SbVec3d { 00040 public: 00041 SbVec3d(void) { } 00042 SbVec3d(const double v[3]) { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; } 00043 SbVec3d(double x, double y, double z) { vec[0] = x; vec[1] = y; vec[2] = z; } 00044 explicit SbVec3d(const SbVec3f & v) { setValue(v); } 00045 explicit SbVec3d(const SbVec3b & v) { setValue(v); } 00046 explicit SbVec3d(const SbVec3s & v) { setValue(v); } 00047 explicit SbVec3d(const SbVec3i32 & v) { setValue(v); } 00048 SbVec3d(const SbDPPlane & p0, const SbDPPlane & p1, const SbDPPlane & p2); 00049 00050 SbVec3d & setValue(const double v[3]) { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; return *this; } 00051 SbVec3d & setValue(double x, double y, double z) { vec[0] = x; vec[1] = y; vec[2] = z; return *this; } 00052 SbVec3d & setValue(const SbVec3d & barycentric, 00053 const SbVec3d & v0, 00054 const SbVec3d & v1, 00055 const SbVec3d & v2); 00056 SbVec3d & setValue(const SbVec3f & v); 00057 SbVec3d & setValue(const SbVec3b & v); 00058 SbVec3d & setValue(const SbVec3s & v); 00059 SbVec3d & setValue(const SbVec3i32 & v); 00060 00061 const double * getValue(void) const { return vec; } 00062 void getValue(double & x, double & y, double & z) const { x = vec[0]; y = vec[1]; z = vec[2]; } 00063 00064 double & operator [] (const int i) { return vec[i]; } 00065 const double & operator [] (const int i) const { return vec[i]; } 00066 00067 SbVec3d cross(const SbVec3d & v) const; 00068 double dot(const SbVec3d & v) const { return vec[0] * v.vec[0] + vec[1] * v.vec[1] + vec[2] * v.vec[2]; } 00069 SbBool equals(const SbVec3d & v, double tolerance) const; 00070 SbVec3d getClosestAxis(void) const; 00071 double length(void) const; 00072 double sqrLength(void) const { return vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]; } 00073 void negate(void) { vec[0] = -vec[0]; vec[1] = -vec[1]; vec[2] = -vec[2]; } 00074 double normalize(void); 00075 00076 SbVec3d & operator *= (double d) { vec[0] *= d; vec[1] *= d; vec[2] *= d; return *this; } 00077 SbVec3d & operator /= (double d) { SbDividerChk("SbVec3d::operator/=(double)", d); return operator *= (1.0 / d); } 00078 SbVec3d & operator += (const SbVec3d & v) { vec[0] += v[0]; vec[1] += v[1]; vec[2] += v[2]; return *this; } 00079 SbVec3d & operator -= (const SbVec3d & v) { vec[0] -= v[0]; vec[1] -= v[1]; vec[2] -= v[2]; return *this; } 00080 SbVec3d operator - (void) const { return SbVec3d(-vec[0], -vec[1], -vec[2]); } 00081 00082 void print(FILE * fp) const; 00083 00084 private: 00085 double vec[3]; 00086 00087 }; // SbVec3d 00088 00089 COIN_DLL_API inline SbVec3d operator * (const SbVec3d & v, double d) { 00090 SbVec3d val(v); val *= d; return val; 00091 } 00092 00093 COIN_DLL_API inline SbVec3d operator * (double d, const SbVec3d & v) { 00094 SbVec3d val(v); val *= d; return val; 00095 } 00096 00097 COIN_DLL_API inline SbVec3d operator / (const SbVec3d & v, double d) { 00098 SbDividerChk("operator/(SbVec3d,double)", d); 00099 SbVec3d val(v); val /= d; return val; 00100 } 00101 00102 COIN_DLL_API inline SbVec3d operator + (const SbVec3d & v1, const SbVec3d & v2) { 00103 SbVec3d v(v1); v += v2; return v; 00104 } 00105 00106 COIN_DLL_API inline SbVec3d operator - (const SbVec3d & v1, const SbVec3d & v2) { 00107 SbVec3d v(v1); v -= v2; return v; 00108 } 00109 00110 COIN_DLL_API inline int operator == (const SbVec3d & v1, const SbVec3d & v2) { 00111 return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2])); 00112 } 00113 00114 COIN_DLL_API inline int operator != (const SbVec3d & v1, const SbVec3d & v2) { 00115 return !(v1 == v2); 00116 } 00117 00118 #endif // !COIN_SBVEC3D_H
Copyright © 1998-2010 by Kongsberg Oil & Gas Technologies. All rights reserved.
Generated on Thu Apr 28 2011 03:43:03 for Coin by Doxygen 1.7.4.