RayTracing
Vector3D.cpp
См. документацию.
00001 /* NAME: Kirill Vasil'evich Timofeev, 322
00002  * ASGN: N1
00003  */
00004 
00005 #include "Vector3D.h"
00006 #include <math.h>
00007 
00008 Vector3D::Vector3D()
00009 {
00010     X = 0;
00011     Y = 0;
00012     Z = 0;
00013 }
00014 
00015 Vector3D::~Vector3D(){}
00016 
00017 Vector3D::Vector3D(const float x, const float y, const float z)
00018 {
00019     X = x;
00020     Y = y;
00021     Z = z;
00022 }
00023 
00024 Vector3D::Vector3D(const Vector3D &V)
00025 {
00026     X = V.X;
00027     Y = V.Y;
00028     Z = V.Z;
00029 }
00030 
00031 Vector3D Vector3D::operator+ (const Vector3D &V)
00032 {
00033     return Vector3D(X + V.X, Y + V.Y, Z + V.Z);
00034 }
00035 
00036 Vector3D Vector3D::operator+= (const Vector3D &V)
00037 {
00038     return Vector3D(X += V.X, Y += V.Y, Z += V.Z);
00039 }
00040 
00041 Vector3D Vector3D::operator* (const float t)
00042 {
00043     return Vector3D(t * X, t * Y, t * Z);
00044 }
00045 
00046 Vector3D Vector3D::operator- (const Vector3D &V)
00047 {
00048     return Vector3D(X - V.X, Y - V.Y, Z - V.Z);
00049 }
00050 
00051 Vector3D Vector3D::operator- ()
00052 {
00053     return Vector3D(-X, -Y, -Z);
00054 }
00055 
00056 float Vector3D::operator* (Vector3D &V)
00057 {
00058     return (X*V.X + Y*V.Y + Z*V.Z);
00059 }
00060 
00061 float Vector3D::Length()
00062 {
00063     return sqrt(X*X + Y*Y + Z*Z);
00064 }
00065 
00066 float Vector3D::SqrLen()
00067 {
00068     return (X*X + Y*Y + Z*Z);
00069 }
00070 
00071 Vector3D Vector3D::NormVect()
00072 {
00073     float d = Length();
00074     return Vector3D(X/d, Y/d, Z/d);
00075 }
00076