// File vector3d.h
#ifndef __VECTOR3D__ #define _VECTOR3D_
#include <math.h>
class Vector3D
{
public:
float
x, y, z;
Компьютерная графика. Полигональные модели
Vector3D () {}
Vector3D (float px, float py, float pz ) {
x = px;
y = py;
z = pz;
} .
Vector3D ( const Vector3D& v ) {
x = v.x; y = v.y; z = v.z;
}
Vector3D& operator = ( const Vector3D& v )
{
x = v.x; y = v.y; z = v.z;
return *tbis;
}
Vector3D operator + () const {
return *this;
}
Vector3D operator - () const {
return Vector3D (-x, -y, -z );
}
Vector3D& operator += ( const Vector3D& v ) {
x += v.x; V += v.y; z += v.z;
return *this;
}
Vector3D& operator -= ( const Vector3D& v ) {
x -= v.x; y -= v.y; z -= v.z;
return *this;
}
Vector3D& operator *= ( const Vector3D& v ) {
x *= v.x; y *= v.y; z *= v.z;
9. Преобразования в пространстве, проектирование
return *this;
}
Vector3D& operator *= (float f) {
x *= f;
y*= f; z*= f;
return *this;
}
Vector3D& operator /= ( const Vector3D& v ) {
x /= v.x; y /= v.y; z /= v.z;
return *this;
}
Vector3D& operator /= (float f)
{
x/= f;
y/=f;
z/= f;
return *this;
}
float& operator [] (int index ) {
return * (index + &x );
}
int operator == (const Vector3D& v ) const {
return x == v.x && y == v.y && z == v.z;
}
int operator != ( const Vector3D& v ) const
{
return x != v.x || y != v.y || z != v.z;
}
int operator < ( const Vector3D& v ) const
{
return (x < v.x) II ((x == v.x) && (y < v.y));
}
int operator > ( const Vector3D& v ) const
{
return (x > v.x) II ((x == v.x) && (y > v.y));
}
float length () const {
return (float) sqrt (x*x + y*y + z*z);
}
Компьютерная графика. Полигональные модели
friend Vector3D operator + (const Vector3D&,const Vector3D&); friend Vector3D operator - (const Vector3D&,const Vector3D&); friend Vector3D operator * (const Vector3D&,const Vector3D&); friend Vector3D operator * (float, const Vector3D&);
friend Vector3D operator * (const Vector3D&,float); friend Vector3D operator / (const Vector3D&,float); friend Vector3D operator / (const Vector3D&,const Vector3D&); friend float operator & (const Vector3D&,const Vector3D&); friend Vector3D operator A (const Vector3D&,const Vector3D&);