Created
May 25, 2015 13:21
-
-
Save TomMinor/29fd91f0b5e2532b3e0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdlib> | |
class Vec3 | |
{ | |
public: | |
// constructor | |
Vec3(float _x, float _y, float _z) | |
{ | |
m_x = _x; | |
m_y = _y; | |
m_z = _z; | |
} | |
// Prints out the contents of the vector | |
void print() | |
{ | |
std::cout << m_x << "," << m_y << "," << m_z << "\n"; | |
} | |
// Function to add the contents of a vector to this instance | |
Vec3 add(Vec3 _b) | |
{ | |
Vec3 tmp(0,0,0); | |
tmp.m_x = m_x + _b.m_x; | |
tmp.m_y = m_y + _b.m_y; | |
tmp.m_z = m_z + _b.m_z; | |
return tmp; | |
} | |
// Function to add the contents of a vector to this instance | |
Vec3 operator +(Vec3 _b) | |
{ | |
Vec3 tmp(0,0,0); | |
tmp.m_x = m_x + _b.m_x; | |
tmp.m_y = m_y + _b.m_y; | |
tmp.m_z = m_z + _b.m_z; | |
return tmp; | |
} | |
void addTo(Vec3 _b) | |
{ | |
m_x = m_x + _b.m_x; | |
m_y = m_y + _b.m_y; | |
m_z = m_z + _b.m_z; | |
} | |
void operator +=(Vec3 _b) | |
{ | |
m_x = m_x + _b.m_x; | |
m_y = m_y + _b.m_y; | |
m_z = m_z + _b.m_z; | |
} | |
float m_x; | |
float m_y; | |
float m_z; | |
}; | |
int main() | |
{ | |
Vec3 a(1,1,1); | |
Vec3 b(1,2,3); | |
//Vec3 c = a.add(b); | |
Vec3 c = a + b; | |
//c.addTo(b); | |
c += b; | |
a.print(); | |
b.print(); | |
c.print(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment