Skip to content
Permalink
master
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
#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;
}
}