![]() |
http://www.sim.no/ http://www.coin3d.org/ |
00001 #ifndef COIN_SBVEC4F_H 00002 #define COIN_SBVEC4F_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 SbVec4d; 00035 class SbVec4b; 00036 class SbVec4s; 00037 class SbVec4i32; 00038 class SbVec3f; 00039 00040 class COIN_DLL_API SbVec4f { 00041 public: 00042 SbVec4f(void) { } 00043 SbVec4f(const float v[4]) { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; vec[3] = v[3]; } 00044 SbVec4f(float x, float y, float z, float w) { vec[0] = x; vec[1] = y; vec[2] = z; vec[3] = w; } 00045 explicit SbVec4f(const SbVec4d & v) { setValue(v); } 00046 explicit SbVec4f(const SbVec4b & v) { setValue(v); } 00047 explicit SbVec4f(const SbVec4s & v) { setValue(v); } 00048 explicit SbVec4f(const SbVec4i32 & v) { setValue(v); } 00049 00050 SbVec4f & setValue(const float v[4]) { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; vec[3] = v[3]; return *this; } 00051 SbVec4f & setValue(float x, float y, float z, float w) { vec[0] = x; vec[1] = y; vec[2] = z; vec[3] = w; return *this; } 00052 SbVec4f & setValue(const SbVec4d & v); 00053 SbVec4f & setValue(const SbVec4b & v); 00054 SbVec4f & setValue(const SbVec4s & v); 00055 SbVec4f & setValue(const SbVec4i32 & v); 00056 00057 const float * getValue(void) const { return vec; } 00058 void getValue(float & x, float & y, float & z, float & w) const { x = vec[0]; y = vec[1]; z = vec[2]; w = vec[3]; } 00059 00060 float & operator [] (int i) { return vec[i]; } 00061 const float & operator [] (int i) const { return vec[i]; } 00062 00063 SbBool equals(const SbVec4f & v, float tolerance) const; 00064 float dot(const SbVec4f & v) const { return vec[0] * v[0] + vec[1] * v[1] + vec[2] * v[2] + vec[3] * v[3]; } 00065 void getReal(SbVec3f & v) const; 00066 float length(void) const; 00067 float sqrLength(void) const { return vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2] + vec[3] * vec[3]; } 00068 void negate(void) { vec[0] = -vec[0]; vec[1] = -vec[1]; vec[2] = -vec[2]; vec[3] = -vec[3]; } 00069 float normalize(void); 00070 00071 SbVec4f & operator *= (float d) { vec[0] *= d; vec[1] *= d; vec[2] *= d; vec[3] *= d; return *this; } 00072 SbVec4f & operator /= (float d) { SbDividerChk("SbVec4f::operator/=(float)", d); return operator *= (1.0f / d); } 00073 SbVec4f & operator += (const SbVec4f & v) { vec[0] += v[0]; vec[1] += v[1]; vec[2] += v[2]; vec[3] += v[3]; return *this; } 00074 SbVec4f & operator -= (const SbVec4f & v) { vec[0] -= v[0]; vec[1] -= v[1]; vec[2] -= v[2]; vec[3] -= v[3]; return *this; } 00075 SbVec4f operator - (void) const { return SbVec4f(-vec[0], -vec[1], -vec[2], -vec[3]); } 00076 00077 void print(FILE * fp) const; 00078 00079 protected: 00080 float vec[4]; 00081 00082 }; // SbVec4f 00083 00084 COIN_DLL_API inline SbVec4f operator * (const SbVec4f & v, float d) { 00085 SbVec4f val(v); val *= d; return val; 00086 } 00087 00088 COIN_DLL_API inline SbVec4f operator * (float d, const SbVec4f & v) { 00089 SbVec4f val(v); val *= d; return val; 00090 } 00091 00092 COIN_DLL_API inline SbVec4f operator / (const SbVec4f & v, float d) { 00093 SbDividerChk("operator/(SbVec4f,float)", d); 00094 SbVec4f val(v); val /= d; return val; 00095 } 00096 00097 COIN_DLL_API inline SbVec4f operator + (const SbVec4f & v1, const SbVec4f & v2) { 00098 SbVec4f v(v1); v += v2; return v; 00099 } 00100 00101 COIN_DLL_API inline SbVec4f operator - (const SbVec4f & v1, const SbVec4f & v2) { 00102 SbVec4f v(v1); v -= v2; return v; 00103 } 00104 00105 COIN_DLL_API inline int operator == (const SbVec4f & v1, const SbVec4f & v2) { 00106 return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]) && (v1[3] == v2[3])); 00107 } 00108 00109 COIN_DLL_API inline int operator != (const SbVec4f & v1, const SbVec4f & v2) { 00110 return !(v1 == v2); 00111 } 00112 00113 #endif // !COIN_SBVEC4F_H
Copyright © 1998-2010 by Kongsberg Oil & Gas Technologies. All rights reserved.
Generated on Mon May 10 00:34:49 2010 for Coin by Doxygen 1.6.3.