Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
vector2.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2000 by Jorrit Tyberghein 00003 Largely rewritten by Ivan Avramovic <ivan@avramovic.com> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_VECTOR2_H__ 00021 #define __CS_VECTOR2_H__ 00022 00023 #include "csextern.h" 00024 00031 class csString; 00032 00036 class CS_CRYSTALSPACE_EXPORT csVector2 00037 { 00038 public: 00040 float x; 00042 float y; 00043 00045 csVector2 () {} 00046 00048 csVector2 (float v) 00049 : x (v), y (v) 00050 {} 00051 00053 csVector2 (float x, float y) 00054 : x (x), y (y) 00055 { } 00056 00058 csVector2 (const csVector2& o) 00059 : x (o.x), y (o.y) 00060 {} 00061 00063 csString Description() const; 00064 00066 inline void Set (float ix, float iy) 00067 { x = ix; y = iy; } 00068 00070 inline void Set (csVector2 const& v) 00071 { x = v.x; y = v.y; } 00072 00074 inline void Set (float const* v) { x = v[0]; y = v[1]; } 00075 00077 inline void Set (float v) { x = y = v; } 00078 00080 inline void Get (float* v) { v[0] = x; v[1] = y; } 00081 00083 static float Norm (csVector2 const& v); 00084 00086 float Norm () const; 00087 00089 inline float SquaredNorm () const 00090 { return x * x + y * y; } 00091 00093 void Rotate (float angle); 00094 00099 inline float IsLeft (const csVector2& p0, const csVector2& p1) 00100 { 00101 return (p1.x - p0.x)*(y - p0.y) - (x - p0.x)*(p1.y - p0.y); 00102 } 00103 00105 csVector2& operator+= (const csVector2& v) 00106 { x += v.x; y += v.y; return *this; } 00107 00109 csVector2& operator-= (const csVector2& v) 00110 { x -= v.x; y -= v.y; return *this; } 00111 00113 csVector2& operator*= (float f) { x *= f; y *= f; return *this; } 00114 00116 csVector2& operator/= (float f) 00117 { 00118 f = 1.0f / f; 00119 x *= f; 00120 y *= f; 00121 return *this; 00122 } 00123 00125 inline csVector2 operator+ () const { return *this; } 00126 00128 inline csVector2 operator- () const { return csVector2(-x,-y); } 00129 00131 friend CS_CRYSTALSPACE_EXPORT csVector2 operator+ (const csVector2& v1, 00132 const csVector2& v2); 00134 friend CS_CRYSTALSPACE_EXPORT csVector2 operator- (const csVector2& v1, 00135 const csVector2& v2); 00137 friend CS_CRYSTALSPACE_EXPORT float operator* (const csVector2& v1, 00138 const csVector2& v2); 00140 friend CS_CRYSTALSPACE_EXPORT csVector2 operator* (const csVector2& v, float f); 00142 friend CS_CRYSTALSPACE_EXPORT csVector2 operator* (float f, const csVector2& v); 00144 friend CS_CRYSTALSPACE_EXPORT csVector2 operator/ (const csVector2& v, float f); 00146 friend CS_CRYSTALSPACE_EXPORT bool operator== (const csVector2& v1, 00147 const csVector2& v2); 00149 friend CS_CRYSTALSPACE_EXPORT bool operator!= (const csVector2& v1, 00150 const csVector2& v2); 00151 00153 inline friend bool operator< (const csVector2& v, float f) 00154 { return ABS(v.x)<f && ABS(v.y)<f; } 00155 00157 inline friend bool operator> (float f, const csVector2& v) 00158 { return ABS(v.x)<f && ABS(v.y)<f; } 00159 00160 00162 inline float operator[] (int n) const { return !n?x:y; } 00164 inline float & operator[] (int n) { return !n?x:y; } 00165 }; 00166 00169 #endif // __CS_VECTOR2_H__
Generated for Crystal Space by doxygen 1.4.4