3
*************************************************************************
5
ArmageTron -- Just another Tron Lightcycle Game in 3D.
6
Copyright (C) 2000 Manuel Moos (manuel@moosnet.de)
8
**************************************************************************
10
This program is free software; you can redistribute it and/or
11
modify it under the terms of the GNU General Public License
12
as published by the Free Software Foundation; either version 2
13
of the License, or (at your option) any later version.
15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License
21
along with this program; if not, write to the Free Software
22
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
***************************************************************************
28
#ifndef ArmageTron_COORD_H
29
#define ArmageTron_COORD_H
37
explicit eCoord(REAL X=0,REAL Y=0):x(X),y(Y){};
40
inline bool operator==(const eCoord &a) const;
41
bool operator!=(const eCoord &a) const{return !operator==(a);}
42
eCoord operator-(const eCoord &a) const{return eCoord(x-a.x,y-a.y);}
43
eCoord operator-() const{return eCoord(-x,-y);}
44
eCoord operator+(const eCoord &a) const{return eCoord(x+a.x,y+a.y);}
45
eCoord operator*(REAL a) const {return eCoord(x*a,y*a);}
46
const eCoord& operator*=(REAL a) { x*=a; y*=a; return *this;}
47
REAL NormSquared() const {return x*x+y*y;}
48
REAL Norm() const {return sqrt(NormSquared());}
49
void Normalize() { *this *= 1/Norm(); }
50
const eCoord &operator=(const eCoord &a){ x=a.x;y=a.y; return *this; }
53
static REAL F(const eCoord &a,const eCoord &b){
54
return(a.x*b.x+a.y*b.y);
57
// change coordinates, so that a is at zero and c is at one.
58
// gives the coordinate of b.
59
static REAL V(const eCoord &a,const eCoord &b,const eCoord &c){
62
return(F(ab,ac)/F(ac,ac));
66
// returns a positive number if (a,*this) form a right-handed
67
// coordinate system, a negative number, if ...
68
// and 0, if a and *this are parallel.
69
REAL operator*(const eCoord &a) const{return -x*a.y+y*a.x;}
72
// complex multiplication: turns this by angle given in a
73
eCoord Turn(const eCoord &a) const{return eCoord(x*a.x-y*a.y,y*a.x+x*a.y);}
74
eCoord Turn(REAL a,REAL b) const{return Turn(eCoord(a,b));}
75
// complex conjugation
76
eCoord Conj() const{return eCoord(x,-y);}
79
void Print(std::ostream &s) const;
80
void Read(std::istream &s);
83
// handy function used to decide whether a*b is small enough to
84
// consider a and b lineary dependant (criterium: |a*b|<EPS*estim....)
85
REAL se_EstimatedRangeOfMult(const eCoord &a,const eCoord &b);
87
// returns a measure for the equality of two coords
88
REAL st_GetDifference( const eCoord & a, const eCoord & b );
90
inline bool eCoord::operator==(const eCoord &a) const{
91
return ((*this-a).NormSquared()<=(EPS*EPS)*se_EstimatedRangeOfMult(*this,a));
94
inline std::ostream &operator<< (std::ostream &s,const eCoord &c){
99
inline std::istream &operator>> (std::istream &s,eCoord &c){
104
extern const eCoord se_zeroCoord;