Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

univcoord.cpp

Go to the documentation of this file.
00001 // univcoord.cpp
00002 //
00003 // Copyright (C) 2001, Chris Laurel <claurel@shatters.net>
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 
00010 #include <iostream>
00011 #include <cmath>
00012 #include <celmath/mathlib.h>
00013 #include "univcoord.h"
00014 
00015 
00016 UniversalCoord::UniversalCoord()
00017 {
00018 }
00019 
00020 UniversalCoord::UniversalCoord(BigFix _x, BigFix _y, BigFix _z) :
00021     x(_x), y(_y), z(_z)
00022 {
00023 }
00024 
00025 UniversalCoord::UniversalCoord(double _x, double _y, double _z) :
00026     x(_x), y(_y), z(_z)
00027 {
00028 }
00029 
00030 UniversalCoord::UniversalCoord(const Point3d& p) :
00031     x(p.x), y(p.y), z(p.z)
00032 {
00033 }
00034 
00035 UniversalCoord::UniversalCoord(const Point3f& p) :
00036     x(p.x), y(p.y), z(p.z)
00037 {
00038 }
00039 
00040 UniversalCoord::operator Point3d() const
00041 {
00042     return Point3d((double) x, (double) y, (double) z);
00043 }
00044 
00045 UniversalCoord::operator Point3f() const
00046 {
00047     return Point3f((float) x, (float) y, (float) z);
00048 }
00049 
00050 double UniversalCoord::distanceTo(const UniversalCoord& uc)
00051 {
00052     return sqrt(square((double) (uc.x - x)) +
00053                 square((double) (uc.y - y)) +
00054                 square((double) (uc.z - z)));
00055 }
00056 
00057 Vec3d operator-(const UniversalCoord& uc0, const UniversalCoord& uc1)
00058 {
00059     return Vec3d((double) (uc0.x - uc1.x),
00060                  (double) (uc0.y - uc1.y),
00061                  (double) (uc0.z - uc1.z));
00062 }
00063 
00064 Vec3d operator-(const UniversalCoord& uc, const Point3d& p)
00065 {
00066     return Vec3d((double) (uc.x - (BigFix) p.x),
00067                  (double) (uc.y - (BigFix) p.y),
00068                  (double) (uc.z - (BigFix) p.z));
00069 }
00070 
00071 Vec3d operator-(const Point3d& p, const UniversalCoord& uc)
00072 {
00073     return Vec3d((double) ((BigFix) p.x - uc.x),
00074                  (double) ((BigFix) p.y - uc.y),
00075                  (double) ((BigFix) p.z - uc.z));
00076 }
00077 
00078 Vec3f operator-(const UniversalCoord& uc, const Point3f& p)
00079 {
00080     return Vec3f((float) (uc.x - (BigFix) p.x),
00081                  (float) (uc.y - (BigFix) p.y),
00082                  (float) (uc.z - (BigFix) p.z));
00083 }
00084 
00085 Vec3f operator-(const Point3f& p, const UniversalCoord& uc)
00086 {
00087     return Vec3f((float) ((BigFix) p.x - uc.x),
00088                  (float) ((BigFix) p.y - uc.y),
00089                  (float) ((BigFix) p.z - uc.z));
00090 }
00091 
00092 UniversalCoord operator+(const UniversalCoord& uc, const Vec3d& v)
00093 {
00094     return UniversalCoord(uc.x + (BigFix) v.x,
00095                           uc.y + (BigFix) v.y,
00096                           uc.z + (BigFix) v.z);
00097 }
00098 
00099 UniversalCoord operator+(const UniversalCoord& uc, const Vec3f& v)
00100 {
00101     return UniversalCoord(uc.x + BigFix((double) v.x),
00102                           uc.y + BigFix((double) v.y),
00103                           uc.z + BigFix((double) v.z));
00104 }
00105 
00106 UniversalCoord operator-(const UniversalCoord& uc, const Vec3d& v)
00107 {
00108     return UniversalCoord(uc.x - BigFix(v.x),
00109                           uc.y - BigFix(v.y),
00110                           uc.z - BigFix(v.z));
00111 }
00112 
00113 UniversalCoord operator-(const UniversalCoord& uc, const Vec3f& v)
00114 {
00115     return UniversalCoord(uc.x - BigFix((double) v.x),
00116                           uc.y - BigFix((double) v.y),
00117                           uc.z - BigFix((double) v.z));
00118 }
00119 
00120 UniversalCoord operator+(const UniversalCoord& uc0, const UniversalCoord& uc1)
00121 {
00122     return UniversalCoord(uc0.x + uc1.x, uc0.y + uc1.y, uc0.z + uc1.z);
00123 }
00124 
00125 UniversalCoord UniversalCoord::difference(const UniversalCoord& uc) const
00126 {
00127     return UniversalCoord(x - uc.x, y - uc.y, z - uc.z);
00128 }

Generated on Sat Jan 14 22:30:29 2006 for Celestia by  doxygen 1.4.1