Coin Logo http://www.sim.no/
http://www.coin3d.org/

SbVec3f.h
00001 #ifndef COIN_SBVEC3F_H
00002 #define COIN_SBVEC3F_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 
00029 #include <Inventor/SbBasic.h>
00030 #ifndef NDEBUG
00031 #include <Inventor/errors/SoDebugError.h>
00032 #endif // !NDEBUG
00033 
00034 class SbPlane;
00035 class SbVec3d;
00036 class SbVec3b;
00037 class SbVec3s;
00038 class SbVec3i32;
00039 
00040 class COIN_DLL_API SbVec3f {
00041 public:
00042   SbVec3f(void) { }
00043   SbVec3f(const float v[3]) { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; }
00044   SbVec3f(float x, float y, float z) { vec[0] = x; vec[1] = y; vec[2] = z; }
00045   explicit SbVec3f(const SbVec3d & v) { setValue(v); }
00046   explicit SbVec3f(const SbVec3b & v) { setValue(v); }
00047   explicit SbVec3f(const SbVec3s & v) { setValue(v); }
00048   explicit SbVec3f(const SbVec3i32 & v) { setValue(v); }
00049   SbVec3f(const SbPlane & p0, const SbPlane & p1, const SbPlane & p2);
00050 
00051   SbVec3f & setValue(const float v[3]) { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; return *this; }
00052   SbVec3f & setValue(float x, float y, float z) { vec[0] = x; vec[1] = y; vec[2] = z; return *this; }
00053   SbVec3f & setValue(const SbVec3f & barycentric,
00054                      const SbVec3f & v0,
00055                      const SbVec3f & v1,
00056                      const SbVec3f & v2);
00057   SbVec3f & setValue(const SbVec3d & v);
00058   SbVec3f & setValue(const SbVec3b & v);
00059   SbVec3f & setValue(const SbVec3s & v);
00060   SbVec3f & setValue(const SbVec3i32 & v);
00061 
00062   const float * getValue(void) const { return vec; }
00063   void getValue(float & x, float & y, float & z) const { x = vec[0]; y = vec[1]; z = vec[2]; }
00064 
00065   float & operator [] (int i) { return vec[i]; }
00066   const float & operator [] (int i) const { return vec[i]; }
00067 
00068   SbBool equals(const SbVec3f & v, float tolerance) const;
00069   SbVec3f cross(const SbVec3f & v) const;
00070   float dot(const SbVec3f & v) const { return vec[0] * v[0] + vec[1] * v[1] + vec[2] * v[2]; }
00071   SbVec3f getClosestAxis(void) const;
00072   float length(void) const;
00073   float sqrLength(void) const { return vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]; }
00074   float normalize(void);
00075   void negate(void) { vec[0] = -vec[0]; vec[1] = -vec[1]; vec[2] = -vec[2]; }
00076 
00077   SbVec3f & operator *= (float d) { vec[0] *= d; vec[1] *= d; vec[2] *= d; return *this; }
00078   SbVec3f & operator /= (float d) { SbDividerChk("SbVec3f::operator/=(float)", d); return operator *= (1.0f / d); }
00079   SbVec3f & operator += (const SbVec3f & v) { vec[0] += v[0]; vec[1] += v[1]; vec[2] += v[2]; return *this; }
00080   SbVec3f & operator -= (const SbVec3f & v) { vec[0] -= v[0]; vec[1] -= v[1]; vec[2] -= v[2]; return *this; }
00081   SbVec3f operator - (void) const { return SbVec3f(-vec[0], -vec[1], -vec[2]); }
00082 
00083   void print(FILE * fp) const;
00084 
00085 protected:
00086   float vec[3];
00087 
00088 }; // SbVec3f
00089 
00090 COIN_DLL_API inline SbVec3f operator * (const SbVec3f & v, float d) {
00091   SbVec3f val(v); val *= d; return val;
00092 }
00093 
00094 COIN_DLL_API inline SbVec3f operator * (float d, const SbVec3f & v) {
00095   SbVec3f val(v); val *= d; return val;
00096 }
00097 
00098 COIN_DLL_API inline SbVec3f operator / (const SbVec3f & v, float d) {
00099   SbDividerChk("operator/(SbVec3f,float)", d);
00100   SbVec3f val(v); val /= d; return val;
00101 }
00102 
00103 COIN_DLL_API inline SbVec3f operator + (const SbVec3f & v1, const SbVec3f & v2) {
00104   SbVec3f v(v1); v += v2; return v;
00105 }
00106 
00107 COIN_DLL_API inline SbVec3f operator - (const SbVec3f & v1, const SbVec3f & v2) {
00108   SbVec3f v(v1); v -= v2; return v;
00109 }
00110 
00111 COIN_DLL_API inline int operator == (const SbVec3f & v1, const SbVec3f & v2) {
00112   return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]));
00113 }
00114 
00115 COIN_DLL_API inline int operator != (const SbVec3f & v1, const SbVec3f & v2) {
00116   return !(v1 == v2);
00117 }
00118 
00119 #endif // !COIN_SBVEC3F_H

Copyright © 1998-2010 by Kongsberg Oil & Gas Technologies. All rights reserved.

Generated on Fri Dec 11 2015 03:24:52 for Coin by Doxygen 1.7.6.1.