![]() |
#2
yuccn2013-05-07 13:06
|

#include"Vector.h"
#include<iostream>
using namespace std;
CVector::CVector()
{
x=0.0;
y=0.0;
z=0.0;
}
CVector::CVector(GLfloat x,GLfloat y,GLfloat z)
{
this->x=x;
this->y=y;
this->z=z;
}
CVector::~CVector()
{
}
CVector& CVector::operator=(const CVector& vector)
{
this->x=vector.x;
this->y=vector.y;
this->z=vector.z;
return *this;
}
CVector CVector::operator+(const CVector& vector)
{
return CVector(this->x+vector.x,this->y+vector.y,this->z+vector.z);
}
CVector CVector::operator-(const CVector& vector)
{
return CVector(this->x-vector.x,this->y-vector.y,this->z-vector.z);
}
CVector CVector::operator*(const CVector& vector)
{
GLfloat x,y,z;
x=this->y*vector.z-this->z*vector.y;
y=this->z*vector.x-this->x*vector.z;
z=this->x*vector.y-this->y*vector.x;
return CVector(x,y,z);
}
CVector CVector::operator*(GLfloat radius)
{
return CVector(this->x*radius,this->y*radius,this->z*radius);
}
CVector& CVector::operator*=(GLfloat radius)
{
this->x*=radius;
this->y*=radius;
this->z*=radius;
return *this;
}
CVector& CVector::operator-=(const CVector& vector)
{
this->x-=vector.x;
this->y-=vector.y;
this->z-=vector.z;
return *this;
}
CVector& CVector::operator+=(const CVector& vector)
{
this->x+=vector.x;
this->y+=vector.y;
this->z+=vector.z;
return *this;
}
std::ostream& operator<<(std::ostream& os,const CVector& vector)
{
return os<<"<"<<vector.x<<","<<vector.y<<","<<vector.z<<">";
}