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