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