Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Viktor-Kolaric-ID.8311933-217CR-Resit-Assignment/CRVec3.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
115 lines (89 sloc)
1.84 KB
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 "CRVec3.h" | |
#include <iostream> | |
#include <math.h> | |
namespace CR217 | |
{ | |
//constructor | |
CRVec3::CRVec3() :x(0.0), y(0.0), z(0.0){} | |
CRVec3::CRVec3(float CRX, float CRY, float CRZ):x(CRX), y(CRY), z(CRZ) {} | |
//destructor | |
CRVec3::~CRVec3(){} | |
//constructor copy | |
CRVec3::CRVec3(const CRVec3& v):x(v.x), y(v.y), z(v.z){} | |
CRVec3& CRVec3::operator=(const CRVec3& v) | |
{ | |
x = v.x; | |
y = v.y; | |
z = v.z; | |
return *this; | |
} | |
void CRVec3::operator+=(const CRVec3& v) | |
{ | |
x += v.x; | |
y += v.y; | |
z += v.z; | |
} | |
CRVec3 CRVec3::operator+(const CRVec3& v)const | |
{ | |
return CRVec3(x + v.x, y + v.y, z + v.z); | |
} | |
void CRVec3::operator-=(const CRVec3& v) | |
{ | |
x -= v.x; | |
y -= v.y; | |
z -= v.z; | |
} | |
CRVec3 CRVec3::operator-(const CRVec3& v)const | |
{ | |
return CRVec3(x - v.x, y - v.y, z - v.z); | |
} | |
void CRVec3::operator*=(const float s) | |
{ | |
x *= s; | |
y *= s; | |
z *= s; | |
} | |
CRVec3 CRVec3::operator*(const float s) const | |
{ | |
return CRVec3(s * x, s * y, s * z); | |
} | |
void CRVec3::operator/=(const float s) | |
{ | |
x /= s; | |
y /= s; | |
z /= s; | |
} | |
CRVec3 CRVec3::operator/(const float s) const | |
{ | |
return CRVec3(x /s, y /s,z/s); | |
} | |
float CRVec3::operator*(const CRVec3& v) const | |
{ | |
return x*v.x+y*v.y+z*v.z; | |
} | |
float CRVec3::dot(const CRVec3& v) const | |
{ | |
return x*v.x + y*v.y + z * v.z; | |
} | |
CRVec3 CRVec3::cross(const CRVec3& v) const | |
{ | |
return CRVec3(y * v.z - z * v.y, | |
z * v.x - x * v.z, | |
x * v.y - y * v.x); | |
} | |
void CRVec3::operator %=(const CRVec3& v) | |
{ | |
*this = cross(v); | |
} | |
CRVec3 CRVec3::operator %(const CRVec3& v) const | |
{ | |
return CRVec3(y * v.z - z * v.y, | |
z * v.x - x * v.z, | |
x * v.y - y * v.x); | |
} | |
float CRVec3::magnitude() | |
{ | |
float magnitude=sqrt(x * x + y * y + z * z); | |
return magnitude; | |
} | |
} | |