Vector.hh

00001 /**********************************************************************
00002  * blaRAY -- photon mapper/raytracer
00003  * (C) 2008 by Tomasz bla Fortuna <bla@thera.be>, <bla@af.gliwice.pl>
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation, either version 3 of the License, or
00008  * any later version.
00009  *
00010  * See Docs/LICENSE
00011  *********************/
00012 
00013 #ifndef _VECTOR_H_
00014 #define _VECTOR_H_
00015 
00016 #include <stdexcept>
00017 #include <string>
00018 #include "General/Debug.hh"
00019 #include "General/Types.hh"
00020 #include "Math/Matrix.hh"
00021 #include "Math/Tuple.hh"
00022 
00023 namespace Math {
00024 
00034         class Vector : public Tuple<Double, false, 3> {
00035         public:
00036                 enum {X, Y, Z};
00038                 inline Vector(Double x, Double y, Double z) {
00039                         D[0] = x;
00040                         D[1] = y;
00041                         D[2] = z;
00042                 }
00043 
00045                 inline Vector() {
00046                         D[0] = D[1] = D[2] = 0.0;
00047                 }
00048 
00050                 inline Vector(const Tuple<Double, false, 3> &T) {
00051                         D[0] = T[0]; /* Can it be more optimal? Rather no... */
00052                         D[1] = T[1];
00053                         D[2] = T[2];
00054                 }
00055 
00057                 friend std::ostream &operator<<(std::ostream &os, const Vector &V);
00058 
00060                 inline void Set(Double x, Double y, Double z)
00061                 {
00062                         this->D[0] = x;
00063                         this->D[1] = y;
00064                         this->D[2] = z;
00065                 }
00066 
00071                 void Transform(const Matrix &M);
00072 
00077                 Vector operator*(const Matrix &M) const;
00078                 using Tuple<Double, false, 3>::operator*;
00079 
00082                 Vector Cross(const Vector &M) const;
00083 
00086                 inline Double Dot(const Vector &M) const {
00087                         return  D[0] * M.D[0] +
00088                                 D[1] * M.D[1] +
00089                                 D[2] * M.D[2];
00090                 }
00091 
00092 
00093         };
00094 };
00095 
00096 #endif

Generated on Wed Mar 12 00:34:58 2008 for blaRAY by  doxygen 1.5.5