Changed Moved all vector classes into namespace OpenArena

~g2k
This commit is contained in:
2006-06-18 14:46:31 -04:00
parent fcc82248f4
commit 7e4b388fee
3 changed files with 281 additions and 279 deletions

View File

@@ -2,10 +2,10 @@
#define __vector_h__
#include <cmath>
class Vec3d
{
public:
namespace OpenArena{
class Vec3d
{
public:
double x,y,z;
Vec3d(); //Default Constructor
Vec3d(const Vec3d&); //Copy Constructor
@@ -24,13 +24,13 @@ public:
Vec3d operator*(double) const;
Vec3d operator/(double) const;
};
};
Vec3d Vector(double, double);
//Vec3d Angle2Vec3f()
class Vec2f
{
public:
Vec3d Vector(double, double);
//Vec3d Angle2Vec3f()
class Vec2f
{
public:
float x,y;
Vec2f(); //Default Constructor
Vec2f(const Vec2f&); //Copy Constructor
@@ -50,13 +50,13 @@ public:
//Vec2f operator/(const Vec2f&) const; //Is this right?
Vec2f operator*(double) const;
Vec2f operator/(double) const;
};
};
typedef Vec3d Vec3f;
typedef Vec3d Vec3f;
class Vec2i
{
public:
class Vec2i
{
public:
int x,y;
Vec2i(); //Default Constructor
Vec2i(const Vec2i&); //Copy Constructor
@@ -78,6 +78,6 @@ public:
Vec2i operator/(int) const;
bool operator==(const Vec2i&) const;
bool operator!=(const Vec2i&) const;
};
};
#endif

View File

@@ -1,249 +1,251 @@
#include "../include/vector.h"
Vec3d::Vec3d()
{
namespace OpenArena{
Vec3d::Vec3d()
{
x=0.0f;
y=0.0f;
z=0.0f;
}
}
Vec3d::Vec3d(const Vec3d& orig)
{
Vec3d::Vec3d(const Vec3d& orig)
{
operator=(orig);
}
}
Vec3d::Vec3d(double xr=0, double zr=0)
{
Vec3d::Vec3d(double xr=0, double zr=0)
{
x=(double)sin(90-xr);
y=(double)sin(xr);
z=(double)(y*tan(zr));
}
}
Vec3d::Vec3d(double X, double Y, double Z)
{
Vec3d::Vec3d(double X, double Y, double Z)
{
x = X;
y = Y;
z = Z;
}
}
double Vec3d::lengthsquared()const
{
double Vec3d::lengthsquared()const
{
return (x*x+y*y+z*z);
}
}
double Vec3d::length() const
{
double Vec3d::length() const
{
return (double)sqrt(lengthsquared());
}
}
void Vec3d::normalize()
{
void Vec3d::normalize()
{
x/=length();
y/=length();
z/=length();
}
}
void Vec3d::operator=(const Vec3d& v)
{
void Vec3d::operator=(const Vec3d& v)
{
x = v.x;
y = v.y;
z = v.z;
}
}
Vec3d Vec3d::cross(const Vec3d& v) const
{
Vec3d Vec3d::cross(const Vec3d& v) const
{
return Vec3d(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x);
}
}
Vec3d Vec3d::operator*(const Vec3d& v) const
{
Vec3d Vec3d::operator*(const Vec3d& v) const
{
return Vec3d(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x);
}
}
Vec3d Vec3d::operator+(const Vec3d& v)const
{
Vec3d Vec3d::operator+(const Vec3d& v)const
{
return Vec3d(x+v.x, y+v.y, z+v.z);
}
}
Vec3d Vec3d::operator*(double f) const
{
Vec3d Vec3d::operator*(double f) const
{
return Vec3d(x*f, y*f, z*f);
}
}
Vec3d Vec3d::operator-(const Vec3d& v)const
{
Vec3d Vec3d::operator-(const Vec3d& v)const
{
return Vec3d(x-v.x, y-v.y, z-v.z);
}
}
Vec3d Vec3d::operator/(double k) const
{
Vec3d Vec3d::operator/(double k) const
{
return Vec3d(x/k, y/k, z/k);
}
}
Vec3d Vec3d::normalized() const
{
Vec3d Vec3d::normalized() const
{
return Vec3d(x/length(), y/length(), z/length());
}
}
Vec2f::Vec2f()
{
Vec2f::Vec2f()
{
x=0;
y=0;
}
}
Vec2f::Vec2f(const Vec2f& rtOp)
{
Vec2f::Vec2f(const Vec2f& rtOp)
{
x=rtOp.x;
y=rtOp.y;
}
}
Vec2f Vec2f::cross(const Vec2f& rtOp) const
{
Vec2f Vec2f::cross(const Vec2f& rtOp) const
{
return Vec2f(y-rtOp.y, rtOp.x-x);
}
}
double Vec2f::length()const
{
double Vec2f::length()const
{
return sqrt(x*x+y*y);
}
}
double Vec2f::lengthsquared()const
{
double Vec2f::lengthsquared()const
{
return (x*x+y*y);
}
}
void Vec2f::normalize()
{
void Vec2f::normalize()
{
x/=(float)length();
y/=(float)length();
}
}
Vec2f Vec2f::normalized() const
{
Vec2f Vec2f::normalized() const
{
return Vec2f(x/length(), y/length());
}
}
Vec2f Vec2f::operator*(double rtOp) const
{
Vec2f Vec2f::operator*(double rtOp) const
{
return Vec2f(x*rtOp, y*rtOp);
}
}
Vec2f Vec2f::operator+(const Vec2f& rtOp) const
{
Vec2f Vec2f::operator+(const Vec2f& rtOp) const
{
return Vec2f(x+rtOp.x, y+rtOp.y);
}
}
Vec2f Vec2f::operator*(const Vec2f& rtOp) const
{
Vec2f Vec2f::operator*(const Vec2f& rtOp) const
{
return Vec2f(x*rtOp.x, y*rtOp.y);
}
}
Vec2f Vec2f::operator-(const Vec2f& rtOp) const
{
Vec2f Vec2f::operator-(const Vec2f& rtOp) const
{
return Vec2f(x-rtOp.x, y-rtOp.y);
}
}
Vec2f Vec2f::operator/(double rtOp) const
{
Vec2f Vec2f::operator/(double rtOp) const
{
return Vec2f(x/rtOp, y/rtOp);
}
}
Vec2f Vec2f::operator=(const Vec2f& rtOp)
{
Vec2f Vec2f::operator=(const Vec2f& rtOp)
{
x=rtOp.x;
y=rtOp.y;
return Vec2f(x,y);
}
}
Vec2f::Vec2f(double X, double Y)
{
Vec2f::Vec2f(double X, double Y)
{
x=(float)X;
y=(float)Y;
}
////////////
Vec2i::Vec2i()
{
}
////////////
Vec2i::Vec2i()
{
x=0;
y=0;
}
}
Vec2i::Vec2i(const Vec2i& rtOp)
{
Vec2i::Vec2i(const Vec2i& rtOp)
{
x=rtOp.x;
y=rtOp.y;
}
}
Vec2i Vec2i::cross(const Vec2i& rtOp) const
{
Vec2i Vec2i::cross(const Vec2i& rtOp) const
{
return Vec2i(y-rtOp.y, rtOp.x-x);
}
}
int Vec2i::length()const
{
int Vec2i::length()const
{
return (int)sqrt((float)(x*x+y*y));
}
}
int Vec2i::lengthsquared()const
{
int Vec2i::lengthsquared()const
{
return (x*x+y*y);
}
}
void Vec2i::normalize()
{
void Vec2i::normalize()
{
x/=length();
y/=length();
}
}
Vec2i Vec2i::normalized() const
{
Vec2i Vec2i::normalized() const
{
return Vec2i(x/length(), y/length());
}
}
Vec2i Vec2i::operator*(int rtOp) const
{
Vec2i Vec2i::operator*(int rtOp) const
{
return Vec2i(x*rtOp, y*rtOp);
}
}
Vec2i Vec2i::operator+(const Vec2i& rtOp) const
{
Vec2i Vec2i::operator+(const Vec2i& rtOp) const
{
return Vec2i(x+rtOp.x, y+rtOp.y);
}
}
Vec2i Vec2i::operator*(const Vec2i& rtOp) const
{
Vec2i Vec2i::operator*(const Vec2i& rtOp) const
{
return Vec2i(x*rtOp.x, y*rtOp.y);
}
}
Vec2i Vec2i::operator-(const Vec2i& rtOp) const
{
Vec2i Vec2i::operator-(const Vec2i& rtOp) const
{
return Vec2i(x-rtOp.x, y-rtOp.y);
}
}
Vec2i Vec2i::operator/(int rtOp) const
{
Vec2i Vec2i::operator/(int rtOp) const
{
return Vec2i(x/rtOp, y/rtOp);
}
}
Vec2i Vec2i::operator=(const Vec2i& rtOp)
{
Vec2i Vec2i::operator=(const Vec2i& rtOp)
{
x=rtOp.x;
y=rtOp.y;
return Vec2i(x,y);
}
}
Vec2i::Vec2i(int X, int Y)
{
Vec2i::Vec2i(int X, int Y)
{
x=X;
y=Y;
}
}
bool Vec2i::operator==(const Vec2i& rtOp) const
{
bool Vec2i::operator==(const Vec2i& rtOp) const
{
return x == rtOp.x && y == rtOp.y;
}
}
bool Vec2i::operator!=(const Vec2i& rtOp) const
{
bool Vec2i::operator!=(const Vec2i& rtOp) const
{
return !(x == rtOp.x && y == rtOp.y);
}
}
};

View File

@@ -411,7 +411,7 @@ Vec2i OpenArena::Window::GetMousePosition()
}
#endif
#ifdef WIN32
Vec2i OpenArena::Window::GetMousePosition()
OpenArena::Vec2i OpenArena::Window::GetMousePosition()
{
POINT pos;
GetCursorPos(&pos);