From 17565c41c1e76e05d161794163f60768c3802e5c Mon Sep 17 00:00:00 2001 From: Tom Hicks Date: Sat, 2 Jul 2005 01:46:50 -0400 Subject: [PATCH] Added: Class Vec2i ~g2k --- include/vector.h | 26 +++++++++++++++ src/vector.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) diff --git a/include/vector.h b/include/vector.h index 5afe067..d0e7270 100644 --- a/include/vector.h +++ b/include/vector.h @@ -54,4 +54,30 @@ public: 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 be3c214..4b5ef73 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -161,3 +161,89 @@ 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::cross(const Vec2i& rtOp) const +{ + return Vec2i(y-rtOp.y, rtOp.x-x); +} + +int Vec2i::length()const +{ + return (int)sqrt(x*x+y*y); +} + +int Vec2i::lengthsquared()const +{ + return (x*x+y*y); +} + +void Vec2i::normalize() +{ + 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+(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=(const Vec2i& rtOp) +{ + x=rtOp.x; + y=rtOp.x; + return Vec2i(x,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); +}