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

SbVec3s.h

00001 #ifndef COIN_SBVEC3S_H
00002 #define COIN_SBVEC3S_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 SbVec3us;
00034 class SbVec3b;
00035 class SbVec3i32;
00036 class SbVec3f;
00037 class SbVec3d;
00038 
00039 class COIN_DLL_API SbVec3s {
00040 public:
00041   SbVec3s(void) { }
00042   SbVec3s(const short v[3]) { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; }
00043   SbVec3s(short x, short y, short z) { vec[0] = x; vec[1] = y; vec[2] = z; }
00044   explicit SbVec3s(const SbVec3us & v) { setValue(v); }
00045   explicit SbVec3s(const SbVec3b & v) { setValue(v); }
00046   explicit SbVec3s(const SbVec3i32 & v) { setValue(v); }
00047   explicit SbVec3s(const SbVec3f & v) { setValue(v); }
00048   explicit SbVec3s(const SbVec3d & v) { setValue(v); }
00049 
00050   SbVec3s & setValue(const short v[3]) { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; return *this; }
00051   SbVec3s & setValue(short x, short y, short z) { vec[0] = x; vec[1] = y; vec[2] = z; return *this; }
00052   SbVec3s & setValue(const SbVec3us & v);
00053   SbVec3s & setValue(const SbVec3b & v);
00054   SbVec3s & setValue(const SbVec3i32 & v);
00055   SbVec3s & setValue(const SbVec3f & v);
00056   SbVec3s & setValue(const SbVec3d & v);
00057 
00058   const short * getValue(void) const { return vec; }
00059   void getValue(short & x, short & y, short & z) const { x = vec[0]; y = vec[1]; z = vec[2]; }
00060 
00061   short & operator [] (int i) { return vec[i]; }
00062   const short & operator [] (int i) const { return vec[i]; }
00063 
00064   int32_t dot(const SbVec3s & v) const { return vec[0] * v[0] + vec[1] * v[1] + vec[2] * v[2]; }
00065   void negate(void) { vec[0] = -vec[0]; vec[1] = -vec[1]; vec[2] = -vec[2]; }
00066 
00067   SbVec3s & operator *= (int d) { vec[0] *= d; vec[1] *= d; vec[2] *= d; return *this; }
00068   SbVec3s & operator *= (double  d);
00069   SbVec3s & operator /= (int d) { SbDividerChk("SbVec3s::operator/=(int)", d); vec[0] /= d; vec[1] /= d; vec[2] /= d; return *this; }
00070   SbVec3s & operator /= (double d) { SbDividerChk("SbVec3s::operator/=(double)", d); return operator *= (1.0 / d); }
00071   SbVec3s & operator += (const SbVec3s & v) { vec[0] += v[0]; vec[1] += v[1]; vec[2] += v[2]; return *this; }
00072   SbVec3s & operator -= (const SbVec3s & v) { vec[0] -= v[0]; vec[1] -= v[1]; vec[2] -= v[2]; return *this; }
00073   SbVec3s operator - (void) const { return SbVec3s(-vec[0], -vec[1], -vec[2]); }
00074 
00075   void print(FILE * fp) const;
00076 
00077 protected:
00078   short vec[3];
00079 
00080 }; // SbVec3s
00081 
00082 COIN_DLL_API inline SbVec3s operator * (const SbVec3s & v, int d) {
00083   SbVec3s val(v); val *= d; return val;
00084 }
00085 
00086 COIN_DLL_API inline SbVec3s operator * (const SbVec3s & v, double d) {
00087   SbVec3s val(v); val *= d; return val;
00088 }
00089 
00090 COIN_DLL_API inline SbVec3s operator * (int d, const SbVec3s & v) {
00091   SbVec3s val(v); val *= d; return val;
00092 }
00093 
00094 COIN_DLL_API inline SbVec3s operator * (double d, const SbVec3s & v) {
00095   SbVec3s val(v); val *= d; return val;
00096 }
00097 
00098 COIN_DLL_API inline SbVec3s operator / (const SbVec3s & v, int d) {
00099   SbDividerChk("operator/(SbVec3s,int)", d);
00100   SbVec3s val(v); val /= d; return val;
00101 }
00102 
00103 COIN_DLL_API inline SbVec3s operator / (const SbVec3s & v, double d) {
00104   SbDividerChk("operator/(SbVec3s,double)", d);
00105   SbVec3s val(v); val /= d; return val;
00106 }
00107 
00108 COIN_DLL_API inline SbVec3s operator + (const SbVec3s & v1, const SbVec3s & v2) {
00109   SbVec3s v(v1); v += v2; return v;
00110 }
00111 
00112 COIN_DLL_API inline SbVec3s operator - (const SbVec3s & v1, const SbVec3s & v2) {
00113   SbVec3s v(v1); v -= v2; return v;
00114 }
00115 
00116 COIN_DLL_API inline int operator == (const SbVec3s & v1, const SbVec3s & v2) {
00117   return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]));
00118 }
00119 
00120 COIN_DLL_API inline int operator != (const SbVec3s & v1, const SbVec3s & v2) {
00121   return !(v1 == v2);
00122 }
00123 
00124 #endif // !COIN_SBVEC3S_H

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

Generated for Coin by Doxygen 1.7.3.