diff --git a/include/vector.h b/include/vector.h index d0e7270..714d125 100644 --- a/include/vector.h +++ b/include/vector.h @@ -2,82 +2,82 @@ #define __vector_h__ #include +namespace OpenArena{ + class Vec3d + { + public: + double x,y,z; + Vec3d(); //Default Constructor + Vec3d(const Vec3d&); //Copy Constructor + Vec3d(double, double); //From an angle + Vec3d(double, double, double); //From values + double lengthsquared() const; + double length() const; + void normalize(); + Vec3d normalized() const; -class Vec3d -{ -public: - double x,y,z; - Vec3d(); //Default Constructor - Vec3d(const Vec3d&); //Copy Constructor - Vec3d(double, double); //From an angle - Vec3d(double, double, double); //From values - double lengthsquared() const; - double length() const; - void normalize(); - Vec3d normalized() const; - - Vec3d cross(const Vec3d&) const; - void operator=(const Vec3d&); - Vec3d operator*(const Vec3d&) const; - Vec3d operator+(const Vec3d&) const; - Vec3d operator-(const Vec3d&) const; - Vec3d operator*(double) const; - Vec3d operator/(double) const; + Vec3d cross(const Vec3d&) const; + void operator=(const Vec3d&); + Vec3d operator*(const Vec3d&) const; + Vec3d operator+(const Vec3d&) const; + Vec3d operator-(const Vec3d&) const; + Vec3d operator*(double) const; + Vec3d operator/(double) const; + }; + + Vec3d Vector(double, double); + //Vec3d Angle2Vec3f() + class Vec2f + { + public: + float x,y; + Vec2f(); //Default Constructor + Vec2f(const Vec2f&); //Copy Constructor + Vec2f(double); // from an angle + Vec2f(double, double); //from values + + double lengthsquared() const; + double length() const; + void normalize(); + Vec2f normalized() const; + + Vec2f cross(const Vec2f&) const; + Vec2f operator=(const Vec2f&); + Vec2f operator*(const Vec2f&) const; + Vec2f operator+(const Vec2f&) const; + Vec2f operator-(const Vec2f&) const; + //Vec2f operator/(const Vec2f&) const; //Is this right? + Vec2f operator*(double) const; + Vec2f operator/(double) const; + }; + + typedef Vec3d Vec3f; + + class Vec2i + { + public: + int x,y; + Vec2i(); //Default Constructor + Vec2i(const Vec2i&); //Copy Constructor + Vec2i(int); // from an angle + Vec2i(int,int); //from values + + int lengthsquared() const; + int length() const; + void normalize(); + Vec2i normalized() const; + + Vec2i cross(const Vec2i&) const; + Vec2i operator=(const Vec2i&); + Vec2i operator*(const Vec2i&) const; + Vec2i operator+(const Vec2i&) const; + Vec2i operator-(const Vec2i&) const; + //Vec2i operator/(const Vec2i&) const; //Is this right? + Vec2i operator*(int) const; + Vec2i operator/(int) const; + bool operator==(const Vec2i&) const; + bool operator!=(const Vec2i&) const; + }; }; - -Vec3d Vector(double, double); -//Vec3d Angle2Vec3f() -class Vec2f -{ -public: - float x,y; - Vec2f(); //Default Constructor - Vec2f(const Vec2f&); //Copy Constructor - Vec2f(double); // from an angle - Vec2f(double, double); //from values - - double lengthsquared() const; - double length() const; - void normalize(); - Vec2f normalized() const; - - Vec2f cross(const Vec2f&) const; - Vec2f operator=(const Vec2f&); - Vec2f operator*(const Vec2f&) const; - Vec2f operator+(const Vec2f&) const; - Vec2f operator-(const Vec2f&) const; - //Vec2f operator/(const Vec2f&) const; //Is this right? - Vec2f operator*(double) const; - Vec2f operator/(double) const; -}; - -typedef Vec3d Vec3f; - -class Vec2i -{ -public: - int x,y; - Vec2i(); //Default Constructor - Vec2i(const Vec2i&); //Copy Constructor - Vec2i(int); // from an angle - Vec2i(int,int); //from values - - int lengthsquared() const; - int length() const; - void normalize(); - Vec2i normalized() const; - - Vec2i cross(const Vec2i&) const; - Vec2i operator=(const Vec2i&); - Vec2i operator*(const Vec2i&) const; - Vec2i operator+(const Vec2i&) const; - Vec2i operator-(const Vec2i&) const; - //Vec2i operator/(const Vec2i&) const; //Is this right? - Vec2i operator*(int) const; - Vec2i operator/(int) const; - bool operator==(const Vec2i&) const; - bool operator!=(const Vec2i&) const; -}; - #endif diff --git a/src/vector.cpp b/src/vector.cpp index 4fb85df..7eb05ec 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -1,249 +1,251 @@ #include "../include/vector.h" -Vec3d::Vec3d() -{ - x=0.0f; - y=0.0f; - z=0.0f; -} +namespace OpenArena{ + Vec3d::Vec3d() + { + x=0.0f; + y=0.0f; + z=0.0f; + } -Vec3d::Vec3d(const Vec3d& orig) -{ - operator=(orig); -} + Vec3d::Vec3d(const Vec3d& orig) + { + operator=(orig); + } -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 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) -{ - x = X; - y = Y; - z = Z; -} + Vec3d::Vec3d(double X, double Y, double Z) + { + x = X; + y = Y; + z = Z; + } -double Vec3d::lengthsquared()const -{ - return (x*x+y*y+z*z); -} + double Vec3d::lengthsquared()const + { + return (x*x+y*y+z*z); + } -double Vec3d::length() const -{ - return (double)sqrt(lengthsquared()); -} + double Vec3d::length() const + { + return (double)sqrt(lengthsquared()); + } -void Vec3d::normalize() -{ - x/=length(); - y/=length(); - z/=length(); -} + void Vec3d::normalize() + { + x/=length(); + y/=length(); + z/=length(); + } -void Vec3d::operator=(const Vec3d& v) -{ - x = v.x; - y = v.y; - z = v.z; -} + void Vec3d::operator=(const Vec3d& v) + { + x = v.x; + y = v.y; + z = v.z; + } -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::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 -{ - 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 + { + 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 -{ - return Vec3d(x+v.x, y+v.y, z+v.z); -} + Vec3d Vec3d::operator+(const Vec3d& v)const + { + return Vec3d(x+v.x, y+v.y, z+v.z); + } -Vec3d Vec3d::operator*(double f) const -{ - return Vec3d(x*f, y*f, z*f); -} + Vec3d Vec3d::operator*(double f) const + { + return Vec3d(x*f, y*f, z*f); + } -Vec3d Vec3d::operator-(const Vec3d& v)const -{ - return Vec3d(x-v.x, y-v.y, z-v.z); -} + Vec3d Vec3d::operator-(const Vec3d& v)const + { + return Vec3d(x-v.x, y-v.y, z-v.z); + } -Vec3d Vec3d::operator/(double k) const -{ - return Vec3d(x/k, y/k, z/k); -} + Vec3d Vec3d::operator/(double k) const + { + return Vec3d(x/k, y/k, z/k); + } -Vec3d Vec3d::normalized() const -{ - return Vec3d(x/length(), y/length(), z/length()); -} + Vec3d Vec3d::normalized() const + { + return Vec3d(x/length(), y/length(), z/length()); + } -Vec2f::Vec2f() -{ - x=0; - y=0; -} + Vec2f::Vec2f() + { + x=0; + y=0; + } -Vec2f::Vec2f(const Vec2f& rtOp) -{ - x=rtOp.x; - y=rtOp.y; -} + Vec2f::Vec2f(const Vec2f& rtOp) + { + x=rtOp.x; + y=rtOp.y; + } -Vec2f Vec2f::cross(const Vec2f& rtOp) const -{ - return Vec2f(y-rtOp.y, rtOp.x-x); -} + Vec2f Vec2f::cross(const Vec2f& rtOp) const + { + return Vec2f(y-rtOp.y, rtOp.x-x); + } -double Vec2f::length()const -{ - return sqrt(x*x+y*y); -} + double Vec2f::length()const + { + return sqrt(x*x+y*y); + } -double Vec2f::lengthsquared()const -{ - return (x*x+y*y); -} + double Vec2f::lengthsquared()const + { + return (x*x+y*y); + } -void Vec2f::normalize() -{ - x/=(float)length(); - y/=(float)length(); -} + void Vec2f::normalize() + { + x/=(float)length(); + y/=(float)length(); + } -Vec2f Vec2f::normalized() const -{ - return Vec2f(x/length(), y/length()); -} + Vec2f Vec2f::normalized() const + { + return Vec2f(x/length(), y/length()); + } -Vec2f Vec2f::operator*(double rtOp) const -{ - return Vec2f(x*rtOp, y*rtOp); -} + Vec2f Vec2f::operator*(double rtOp) const + { + return Vec2f(x*rtOp, y*rtOp); + } -Vec2f Vec2f::operator+(const Vec2f& rtOp) const -{ - return Vec2f(x+rtOp.x, y+rtOp.y); -} + Vec2f Vec2f::operator+(const Vec2f& rtOp) const + { + return Vec2f(x+rtOp.x, y+rtOp.y); + } -Vec2f Vec2f::operator*(const Vec2f& rtOp) const -{ - return Vec2f(x*rtOp.x, y*rtOp.y); -} + Vec2f Vec2f::operator*(const Vec2f& rtOp) const + { + return Vec2f(x*rtOp.x, y*rtOp.y); + } -Vec2f Vec2f::operator-(const Vec2f& rtOp) const -{ - return Vec2f(x-rtOp.x, y-rtOp.y); -} + Vec2f Vec2f::operator-(const Vec2f& rtOp) const + { + return Vec2f(x-rtOp.x, y-rtOp.y); + } -Vec2f Vec2f::operator/(double rtOp) const -{ - return Vec2f(x/rtOp, y/rtOp); -} + Vec2f Vec2f::operator/(double rtOp) const + { + return Vec2f(x/rtOp, y/rtOp); + } -Vec2f Vec2f::operator=(const Vec2f& rtOp) -{ - x=rtOp.x; - y=rtOp.y; - return Vec2f(x,y); -} + Vec2f Vec2f::operator=(const Vec2f& rtOp) + { + x=rtOp.x; + y=rtOp.y; + return Vec2f(x,y); + } -Vec2f::Vec2f(double X, double Y) -{ - x=(float)X; - y=(float)Y; -} -//////////// -Vec2i::Vec2i() -{ - x=0; - y=0; -} + Vec2f::Vec2f(double X, double Y) + { + x=(float)X; + y=(float)Y; + } + //////////// + Vec2i::Vec2i() + { + x=0; + y=0; + } -Vec2i::Vec2i(const Vec2i& rtOp) -{ - x=rtOp.x; - y=rtOp.y; -} + Vec2i::Vec2i(const Vec2i& rtOp) + { + x=rtOp.x; + y=rtOp.y; + } -Vec2i Vec2i::cross(const Vec2i& rtOp) const -{ - return Vec2i(y-rtOp.y, rtOp.x-x); -} + Vec2i Vec2i::cross(const Vec2i& rtOp) const + { + return Vec2i(y-rtOp.y, rtOp.x-x); + } -int Vec2i::length()const -{ - return (int)sqrt((float)(x*x+y*y)); -} + int Vec2i::length()const + { + return (int)sqrt((float)(x*x+y*y)); + } -int Vec2i::lengthsquared()const -{ - return (x*x+y*y); -} + int Vec2i::lengthsquared()const + { + return (x*x+y*y); + } -void Vec2i::normalize() -{ - x/=length(); - y/=length(); -} + void Vec2i::normalize() + { + x/=length(); + y/=length(); + } -Vec2i Vec2i::normalized() const -{ - return Vec2i(x/length(), y/length()); -} + Vec2i Vec2i::normalized() const + { + return Vec2i(x/length(), y/length()); + } -Vec2i Vec2i::operator*(int rtOp) const -{ - return Vec2i(x*rtOp, y*rtOp); -} + Vec2i Vec2i::operator*(int rtOp) const + { + return Vec2i(x*rtOp, y*rtOp); + } -Vec2i Vec2i::operator+(const Vec2i& rtOp) const -{ - return Vec2i(x+rtOp.x, y+rtOp.y); -} + Vec2i Vec2i::operator+(const Vec2i& rtOp) const + { + return Vec2i(x+rtOp.x, y+rtOp.y); + } -Vec2i Vec2i::operator*(const Vec2i& rtOp) const -{ - return Vec2i(x*rtOp.x, y*rtOp.y); -} + Vec2i Vec2i::operator*(const Vec2i& rtOp) const + { + return Vec2i(x*rtOp.x, y*rtOp.y); + } -Vec2i Vec2i::operator-(const Vec2i& rtOp) const -{ - return Vec2i(x-rtOp.x, y-rtOp.y); -} + Vec2i Vec2i::operator-(const Vec2i& rtOp) const + { + return Vec2i(x-rtOp.x, y-rtOp.y); + } -Vec2i Vec2i::operator/(int rtOp) const -{ - return Vec2i(x/rtOp, y/rtOp); -} + Vec2i Vec2i::operator/(int rtOp) const + { + return Vec2i(x/rtOp, y/rtOp); + } -Vec2i Vec2i::operator=(const Vec2i& rtOp) -{ - x=rtOp.x; - y=rtOp.y; - return Vec2i(x,y); -} + Vec2i Vec2i::operator=(const Vec2i& rtOp) + { + x=rtOp.x; + y=rtOp.y; + return Vec2i(x,y); + } -Vec2i::Vec2i(int X, int Y) -{ - x=X; - y=Y; -} + Vec2i::Vec2i(int X, int Y) + { + x=X; + y=Y; + } -bool Vec2i::operator==(const Vec2i& rtOp) const -{ - return x == rtOp.x && y == rtOp.y; -} + bool Vec2i::operator==(const Vec2i& rtOp) const + { + return x == rtOp.x && y == rtOp.y; + } -bool Vec2i::operator!=(const Vec2i& rtOp) const -{ - return !(x == rtOp.x && y == rtOp.y); -} + bool Vec2i::operator!=(const Vec2i& rtOp) const + { + return !(x == rtOp.x && y == rtOp.y); + } +}; \ No newline at end of file diff --git a/src/window.cpp b/src/window.cpp index 0415325..1affddf 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -411,7 +411,7 @@ Vec2i OpenArena::Window::GetMousePosition() } #endif #ifdef WIN32 -Vec2i OpenArena::Window::GetMousePosition() +OpenArena::Vec2i OpenArena::Window::GetMousePosition() { POINT pos; GetCursorPos(&pos);