Changed Moved all vector classes into namespace OpenArena
~g2k
This commit is contained in:
@@ -2,10 +2,10 @@
|
|||||||
#define __vector_h__
|
#define __vector_h__
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
namespace OpenArena{
|
||||||
class Vec3d
|
class Vec3d
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
double x,y,z;
|
double x,y,z;
|
||||||
Vec3d(); //Default Constructor
|
Vec3d(); //Default Constructor
|
||||||
Vec3d(const Vec3d&); //Copy Constructor
|
Vec3d(const Vec3d&); //Copy Constructor
|
||||||
@@ -24,13 +24,13 @@ public:
|
|||||||
Vec3d operator*(double) const;
|
Vec3d operator*(double) const;
|
||||||
Vec3d operator/(double) const;
|
Vec3d operator/(double) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Vec3d Vector(double, double);
|
Vec3d Vector(double, double);
|
||||||
//Vec3d Angle2Vec3f()
|
//Vec3d Angle2Vec3f()
|
||||||
class Vec2f
|
class Vec2f
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
float x,y;
|
float x,y;
|
||||||
Vec2f(); //Default Constructor
|
Vec2f(); //Default Constructor
|
||||||
Vec2f(const Vec2f&); //Copy Constructor
|
Vec2f(const Vec2f&); //Copy Constructor
|
||||||
@@ -50,13 +50,13 @@ public:
|
|||||||
//Vec2f operator/(const Vec2f&) const; //Is this right?
|
//Vec2f operator/(const Vec2f&) const; //Is this right?
|
||||||
Vec2f operator*(double) const;
|
Vec2f operator*(double) const;
|
||||||
Vec2f operator/(double) const;
|
Vec2f operator/(double) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Vec3d Vec3f;
|
typedef Vec3d Vec3f;
|
||||||
|
|
||||||
class Vec2i
|
class Vec2i
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int x,y;
|
int x,y;
|
||||||
Vec2i(); //Default Constructor
|
Vec2i(); //Default Constructor
|
||||||
Vec2i(const Vec2i&); //Copy Constructor
|
Vec2i(const Vec2i&); //Copy Constructor
|
||||||
@@ -78,6 +78,6 @@ public:
|
|||||||
Vec2i operator/(int) const;
|
Vec2i operator/(int) const;
|
||||||
bool operator==(const Vec2i&) const;
|
bool operator==(const Vec2i&) const;
|
||||||
bool operator!=(const Vec2i&) const;
|
bool operator!=(const Vec2i&) const;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
274
src/vector.cpp
274
src/vector.cpp
@@ -1,249 +1,251 @@
|
|||||||
#include "../include/vector.h"
|
#include "../include/vector.h"
|
||||||
|
|
||||||
Vec3d::Vec3d()
|
namespace OpenArena{
|
||||||
{
|
Vec3d::Vec3d()
|
||||||
|
{
|
||||||
x=0.0f;
|
x=0.0f;
|
||||||
y=0.0f;
|
y=0.0f;
|
||||||
z=0.0f;
|
z=0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec3d::Vec3d(const Vec3d& orig)
|
Vec3d::Vec3d(const Vec3d& orig)
|
||||||
{
|
{
|
||||||
operator=(orig);
|
operator=(orig);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec3d::Vec3d(double xr=0, double zr=0)
|
Vec3d::Vec3d(double xr=0, double zr=0)
|
||||||
{
|
{
|
||||||
x=(double)sin(90-xr);
|
x=(double)sin(90-xr);
|
||||||
y=(double)sin(xr);
|
y=(double)sin(xr);
|
||||||
z=(double)(y*tan(zr));
|
z=(double)(y*tan(zr));
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec3d::Vec3d(double X, double Y, double Z)
|
Vec3d::Vec3d(double X, double Y, double Z)
|
||||||
{
|
{
|
||||||
x = X;
|
x = X;
|
||||||
y = Y;
|
y = Y;
|
||||||
z = Z;
|
z = Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Vec3d::lengthsquared()const
|
double Vec3d::lengthsquared()const
|
||||||
{
|
{
|
||||||
return (x*x+y*y+z*z);
|
return (x*x+y*y+z*z);
|
||||||
}
|
}
|
||||||
|
|
||||||
double Vec3d::length() const
|
double Vec3d::length() const
|
||||||
{
|
{
|
||||||
return (double)sqrt(lengthsquared());
|
return (double)sqrt(lengthsquared());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vec3d::normalize()
|
void Vec3d::normalize()
|
||||||
{
|
{
|
||||||
x/=length();
|
x/=length();
|
||||||
y/=length();
|
y/=length();
|
||||||
z/=length();
|
z/=length();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vec3d::operator=(const Vec3d& v)
|
void Vec3d::operator=(const Vec3d& v)
|
||||||
{
|
{
|
||||||
x = v.x;
|
x = v.x;
|
||||||
y = v.y;
|
y = v.y;
|
||||||
z = v.z;
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
return Vec3d(x/k, y/k, z/k);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec3d Vec3d::normalized() const
|
Vec3d Vec3d::normalized() const
|
||||||
{
|
{
|
||||||
return Vec3d(x/length(), y/length(), z/length());
|
return Vec3d(x/length(), y/length(), z/length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Vec2f::Vec2f()
|
Vec2f::Vec2f()
|
||||||
{
|
{
|
||||||
x=0;
|
x=0;
|
||||||
y=0;
|
y=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2f::Vec2f(const Vec2f& rtOp)
|
Vec2f::Vec2f(const Vec2f& rtOp)
|
||||||
{
|
{
|
||||||
x=rtOp.x;
|
x=rtOp.x;
|
||||||
y=rtOp.y;
|
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);
|
return Vec2f(y-rtOp.y, rtOp.x-x);
|
||||||
}
|
}
|
||||||
|
|
||||||
double Vec2f::length()const
|
double Vec2f::length()const
|
||||||
{
|
{
|
||||||
return sqrt(x*x+y*y);
|
return sqrt(x*x+y*y);
|
||||||
}
|
}
|
||||||
|
|
||||||
double Vec2f::lengthsquared()const
|
double Vec2f::lengthsquared()const
|
||||||
{
|
{
|
||||||
return (x*x+y*y);
|
return (x*x+y*y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vec2f::normalize()
|
void Vec2f::normalize()
|
||||||
{
|
{
|
||||||
x/=(float)length();
|
x/=(float)length();
|
||||||
y/=(float)length();
|
y/=(float)length();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2f Vec2f::normalized() const
|
Vec2f Vec2f::normalized() const
|
||||||
{
|
{
|
||||||
return Vec2f(x/length(), y/length());
|
return Vec2f(x/length(), y/length());
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2f Vec2f::operator*(double rtOp) const
|
Vec2f Vec2f::operator*(double rtOp) const
|
||||||
{
|
{
|
||||||
return Vec2f(x*rtOp, y*rtOp);
|
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);
|
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);
|
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);
|
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);
|
return Vec2f(x/rtOp, y/rtOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2f Vec2f::operator=(const Vec2f& rtOp)
|
Vec2f Vec2f::operator=(const Vec2f& rtOp)
|
||||||
{
|
{
|
||||||
x=rtOp.x;
|
x=rtOp.x;
|
||||||
y=rtOp.y;
|
y=rtOp.y;
|
||||||
return Vec2f(x,y);
|
return Vec2f(x,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2f::Vec2f(double X, double Y)
|
Vec2f::Vec2f(double X, double Y)
|
||||||
{
|
{
|
||||||
x=(float)X;
|
x=(float)X;
|
||||||
y=(float)Y;
|
y=(float)Y;
|
||||||
}
|
}
|
||||||
////////////
|
////////////
|
||||||
Vec2i::Vec2i()
|
Vec2i::Vec2i()
|
||||||
{
|
{
|
||||||
x=0;
|
x=0;
|
||||||
y=0;
|
y=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2i::Vec2i(const Vec2i& rtOp)
|
Vec2i::Vec2i(const Vec2i& rtOp)
|
||||||
{
|
{
|
||||||
x=rtOp.x;
|
x=rtOp.x;
|
||||||
y=rtOp.y;
|
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);
|
return Vec2i(y-rtOp.y, rtOp.x-x);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Vec2i::length()const
|
int Vec2i::length()const
|
||||||
{
|
{
|
||||||
return (int)sqrt((float)(x*x+y*y));
|
return (int)sqrt((float)(x*x+y*y));
|
||||||
}
|
}
|
||||||
|
|
||||||
int Vec2i::lengthsquared()const
|
int Vec2i::lengthsquared()const
|
||||||
{
|
{
|
||||||
return (x*x+y*y);
|
return (x*x+y*y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vec2i::normalize()
|
void Vec2i::normalize()
|
||||||
{
|
{
|
||||||
x/=length();
|
x/=length();
|
||||||
y/=length();
|
y/=length();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2i Vec2i::normalized() const
|
Vec2i Vec2i::normalized() const
|
||||||
{
|
{
|
||||||
return Vec2i(x/length(), y/length());
|
return Vec2i(x/length(), y/length());
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2i Vec2i::operator*(int rtOp) const
|
Vec2i Vec2i::operator*(int rtOp) const
|
||||||
{
|
{
|
||||||
return Vec2i(x*rtOp, y*rtOp);
|
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);
|
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);
|
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);
|
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);
|
return Vec2i(x/rtOp, y/rtOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2i Vec2i::operator=(const Vec2i& rtOp)
|
Vec2i Vec2i::operator=(const Vec2i& rtOp)
|
||||||
{
|
{
|
||||||
x=rtOp.x;
|
x=rtOp.x;
|
||||||
y=rtOp.y;
|
y=rtOp.y;
|
||||||
return Vec2i(x,y);
|
return Vec2i(x,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2i::Vec2i(int X, int Y)
|
Vec2i::Vec2i(int X, int Y)
|
||||||
{
|
{
|
||||||
x=X;
|
x=X;
|
||||||
y=Y;
|
y=Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vec2i::operator==(const Vec2i& rtOp) const
|
bool Vec2i::operator==(const Vec2i& rtOp) const
|
||||||
{
|
{
|
||||||
return x == rtOp.x && y == rtOp.y;
|
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);
|
return !(x == rtOp.x && y == rtOp.y);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
@@ -411,7 +411,7 @@ Vec2i OpenArena::Window::GetMousePosition()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
Vec2i OpenArena::Window::GetMousePosition()
|
OpenArena::Vec2i OpenArena::Window::GetMousePosition()
|
||||||
{
|
{
|
||||||
POINT pos;
|
POINT pos;
|
||||||
GetCursorPos(&pos);
|
GetCursorPos(&pos);
|
||||||
|
|||||||
Reference in New Issue
Block a user