Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct vec2{
- float x, y;
- vec2(float x, float y):
- x(x),
- y(y){}
- vec2():
- x(0.0f),
- y(0.0f){}
- vec2(float f):
- x(f),
- y(f){}
- vec2(const vec2 &v):
- x(v.x),
- y(v.y){}
- float operator[](const int v){
- if(v == 0){
- return x;
- }
- else{
- return y;
- }
- }
- vec2 operator=(const vec2 v){
- if (this == &v) {
- return *this;
- }
- x = v.x;
- y = v.y;
- return *this;
- }
- vec2 operator+(const vec2 v){
- return vec2(x+v.x, y+v.y);
- }
- vec2 operator+(const float s){
- return vec2(x+s, y+s);
- }
- vec2 operator-(const vec2 v){
- return vec2(x-v.x, y-v.y);
- }
- vec2 operator-(const float s){
- return vec2(x-s, y-s);
- }
- vec2 operator*(const vec2 &v){
- return vec2(x*v.x, y*v.y);
- }
- vec2 operator*(const float s){
- return vec2(x*s, y*s);
- }
- vec2 operator/(const vec2 &v){
- return vec2(x/v.x, y/v.y);
- }
- vec2 operator/(const float s){
- return vec2(x/s, y/s);
- }
- vec2 operator+=(const vec2 v){
- x += v.x;
- y += v.y;
- return *this;
- }
- vec2 operator+=(const float s){
- x += s;
- y += s;
- return *this;
- }
- vec2 operator-=(const vec2 v){
- x -= v.x;
- y -= v.y;
- return *this;
- }
- vec2 operator-=(const float s){
- x -= s;
- y -= s;
- return *this;
- }
- vec2 operator*=(const vec2 v){
- x *= v.x;
- y *= v.y;
- return *this;
- }
- vec2 operator*=(const float s){
- x *= s;
- y *= s;
- return *this;
- }
- vec2 operator/=(const vec2 v){
- x /= v.x;
- y /= v.y;
- return *this;
- }
- vec2 operator/=(const float s){
- x /= s;
- y /= s;
- return *this;
- }
- float length(){
- return sqrtf(dot());
- }
- float dot(){
- return x*x+y*y;
- }
- float dot(const vec2 v){
- return x*v.x+y*v.y;
- }
- void normalize(){
- float l = length();
- x /= l;
- y /= l;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement