[5809313] | 1 | // |
---|
| 2 | // vector3.h |
---|
| 3 | // |
---|
| 4 | // C++ class for 3-element vectors |
---|
| 5 | // |
---|
[f8e4c56] | 6 | // Copyright (C) 2000-2002, Mark R. Shinwell. |
---|
[97d93e1] | 7 | // Copyright (C) 2002 Olly Betts |
---|
[5809313] | 8 | // |
---|
| 9 | // This program is free software; you can redistribute it and/or modify |
---|
| 10 | // it under the terms of the GNU General Public License as published by |
---|
| 11 | // the Free Software Foundation; either version 2 of the License, or |
---|
| 12 | // (at your option) any later version. |
---|
| 13 | // |
---|
| 14 | // This program is distributed in the hope that it will be useful, |
---|
| 15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | // GNU General Public License for more details. |
---|
| 18 | // |
---|
| 19 | // You should have received a copy of the GNU General Public License |
---|
| 20 | // along with this program; if not, write to the Free Software |
---|
| 21 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 22 | // |
---|
| 23 | |
---|
| 24 | #ifndef Vector3_h |
---|
| 25 | #define Vector3_h |
---|
| 26 | |
---|
[156dc16] | 27 | #include <stdio.h> |
---|
| 28 | |
---|
[5809313] | 29 | class Vector3 { |
---|
[156dc16] | 30 | double x; //--FIXME |
---|
[5809313] | 31 | double y; |
---|
| 32 | double z; |
---|
| 33 | |
---|
| 34 | public: |
---|
| 35 | Vector3(); |
---|
| 36 | Vector3(double, double, double); |
---|
| 37 | ~Vector3(); |
---|
| 38 | |
---|
[97d93e1] | 39 | void Save(FILE* fp) const { //--Pres: FIXME |
---|
[421b7d2] | 40 | fwrite(&x, sizeof(double), 1, fp); |
---|
| 41 | fwrite(&y, sizeof(double), 1, fp); |
---|
| 42 | fwrite(&z, sizeof(double), 1, fp); |
---|
[156dc16] | 43 | } |
---|
| 44 | |
---|
| 45 | void Load(FILE* fp) { //--Pres: FIXME |
---|
[421b7d2] | 46 | fread(&x, sizeof(double), 1, fp); |
---|
| 47 | fread(&y, sizeof(double), 1, fp); |
---|
| 48 | fread(&z, sizeof(double), 1, fp); |
---|
[156dc16] | 49 | } |
---|
| 50 | |
---|
[97d93e1] | 51 | double getX() const { return x; } |
---|
| 52 | double getY() const { return y; } |
---|
| 53 | double getZ() const { return z; } |
---|
[5809313] | 54 | |
---|
[97d93e1] | 55 | double magnitude() const; |
---|
[5809313] | 56 | void normalise(); |
---|
| 57 | |
---|
| 58 | void set(double, double, double); |
---|
| 59 | |
---|
[156dc16] | 60 | friend Vector3 operator-(const Vector3& v) { |
---|
[421b7d2] | 61 | Vector3 o; |
---|
[156dc16] | 62 | o.x = -v.x; |
---|
| 63 | o.y = -v.y; |
---|
| 64 | o.z = -v.z; |
---|
| 65 | return o; |
---|
| 66 | } |
---|
[5809313] | 67 | Vector3& operator*=(const double); |
---|
| 68 | Vector3& operator/=(const double); |
---|
| 69 | Vector3& operator=(const Vector3&); |
---|
| 70 | |
---|
| 71 | friend Vector3 operator*(const double, const Vector3&); |
---|
[446e096] | 72 | friend Vector3 operator*(const Vector3& v, const double f) { |
---|
| 73 | return f * v; |
---|
| 74 | } |
---|
[156dc16] | 75 | friend Vector3 operator*(const Vector3&, const Vector3&); // cross product |
---|
[5809313] | 76 | friend Vector3 operator+(const Vector3&, const Vector3&); |
---|
[f8e4c56] | 77 | friend Vector3 operator-(const Vector3&, const Vector3&); |
---|
[5809313] | 78 | friend double dot(const Vector3&, const Vector3&); |
---|
| 79 | }; |
---|
| 80 | |
---|
| 81 | #endif |
---|