Google

Main Page   Class Hierarchy   Compound List   File List   Compound Members  

vector2.h

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 
00026 class csVector2
00027 {
00028 public:
00030   float x;
00032   float y;
00033 
00035   csVector2 () {}
00036 
00038   csVector2 (float x, float y) { csVector2::x = x; csVector2::y = y; }
00039 
00041   inline void Set (float ix, float iy)
00042   { x = ix; y = iy; }
00043 
00045   inline void Set (const csVector2& v)
00046   { x = v.x; y = v.y; }
00047 
00049   static float Norm (const csVector2& v);
00050 
00052   float Norm () const;
00053 
00055   float SquaredNorm () const
00056   { return x * x + y * y; }
00057 
00059   void Rotate (float angle);
00060 
00062   csVector2& operator+= (const csVector2& v)
00063   { x += v.x;  y += v.y;  return *this; }
00064 
00066   csVector2& operator-= (const csVector2& v)
00067   { x -= v.x;  y -= v.y;  return *this; }
00068 
00070   csVector2& operator*= (float f) { x *= f;  y *= f;  return *this; }
00071 
00073   csVector2& operator/= (float f) { f = 1.0f / f; x *= f;  y *= f;  return *this; }
00074 
00076   inline csVector2 operator+ () const { return *this; }
00077 
00079   inline csVector2 operator- () const { return csVector2(-x,-y); }
00080 
00082   friend csVector2 operator+ (const csVector2& v1, const csVector2& v2);
00084   friend csVector2 operator- (const csVector2& v1, const csVector2& v2);
00086   friend float operator* (const csVector2& v1, const csVector2& v2);
00088   friend csVector2 operator* (const csVector2& v, float f);
00090   friend csVector2 operator* (float f, const csVector2& v);
00092   friend csVector2 operator/ (const csVector2& v, float f);
00094   friend bool operator== (const csVector2& v1, const csVector2& v2);
00096   friend bool operator!= (const csVector2& v1, const csVector2& v2);
00097 
00099   inline friend bool operator< (const csVector2& v, float f)
00100   { return ABS(v.x)<f && ABS(v.y)<f; }
00101 
00103   inline friend bool operator> (float f, const csVector2& v)
00104   { return ABS(v.x)<f && ABS(v.y)<f; }
00105 };
00106 
00107 #endif // __CS_VECTOR2_H__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000