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

deepskyobj.cpp

Go to the documentation of this file.
00001 // deepskyobj.cpp
00002 //
00003 // Copyright (C) 2003, 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 <algorithm>
00011 #include <stdio.h>
00012 #include "celestia.h"
00013 #include <cassert>
00014 #include "astro.h"
00015 #include "deepskyobj.h"
00016 #include "galaxy.h"
00017 #include "nebula.h"
00018 #include "opencluster.h"
00019 #include <celutil/util.h>
00020 #include <celutil/debug.h>
00021 
00022 using namespace std;
00023 
00024 
00025 const float DSO_DEFAULT_ABS_MAGNITUDE = -1000.0f;
00026 
00027 
00028 DeepSkyObject::DeepSkyObject() :
00029     catalogNumber(InvalidCatalogNumber),
00030     position(0, 0, 0),
00031     orientation(1),
00032     radius(1),
00033     absMag(DSO_DEFAULT_ABS_MAGNITUDE),
00034     infoURL(NULL)
00035 {
00036 }
00037 
00038 DeepSkyObject::~DeepSkyObject()
00039 {
00040 }
00041 
00042 void DeepSkyObject::setCatalogNumber(uint32 n)
00043 {
00044     catalogNumber = n;
00045 }
00046 
00047 Point3d DeepSkyObject::getPosition() const
00048 {
00049     return position;
00050 }
00051 
00052 void DeepSkyObject::setPosition(const Point3d& p)
00053 {
00054     position = p;
00055 }
00056 
00057 Quatf DeepSkyObject::getOrientation() const
00058 {
00059     return orientation;
00060 }
00061 
00062 void DeepSkyObject::setOrientation(const Quatf& q)
00063 {
00064     orientation = q;
00065 }
00066 
00067 float DeepSkyObject::getRadius() const
00068 {
00069     return radius;
00070 }
00071 
00072 void DeepSkyObject::setRadius(float r)
00073 {
00074     radius = r;
00075 }
00076 
00077 float DeepSkyObject::getAbsoluteMagnitude() const
00078 {
00079     return absMag;
00080 }
00081 
00082 void DeepSkyObject::setAbsoluteMagnitude(float _absMag)
00083 {
00084     absMag = _absMag;
00085 }
00086 
00087 size_t DeepSkyObject::getDescription(char* buf, size_t bufLength) const
00088 {
00089     if (bufLength > 0)
00090         buf[0] = '\0';
00091     return 0;
00092 }
00093 
00094 string DeepSkyObject::getInfoURL() const
00095 {
00096     if (infoURL == NULL)
00097         return "";
00098     else
00099         return *infoURL;
00100 }
00101 
00102 void DeepSkyObject::setInfoURL(const string& s)
00103 {
00104     if (infoURL == NULL)
00105         infoURL = new string(s);
00106     else
00107         *infoURL = s;
00108 }
00109 
00110 bool DeepSkyObject::load(AssociativeArray* params, const string& resPath)
00111 {
00112     // Get position
00113     Vec3d position(0.0, 0.0, 0.0);
00114     if (params->getVector("Position", position))
00115     {
00116         setPosition(Point3d(position.x, position.y, position.z));
00117     }
00118     else
00119     {
00120         double distance = 1.0;
00121         double RA = 0.0;
00122         double dec = 0.0;
00123         params->getNumber("Distance", distance);
00124         params->getNumber("RA", RA);
00125         params->getNumber("Dec", dec);
00126         Point3d p = astro::equatorialToCelestialCart(RA, dec, distance);
00127         setPosition(p);
00128     }
00129 
00130     // Get orientation
00131     Vec3d axis(1.0, 0.0, 0.0);
00132     double angle = 0.0;
00133     params->getVector("Axis", axis);
00134     params->getNumber("Angle", angle);
00135     Quatf q(1);
00136     q.setAxisAngle(Vec3f((float) axis.x, (float) axis.y, (float) axis.z),
00137                    (float) degToRad(angle));
00138     setOrientation(q);
00139     
00140     double radius = 1.0;
00141     params->getNumber("Radius", radius);
00142     setRadius((float) radius);
00143 
00144     double absMag = 0.0;
00145     if (params->getNumber("AbsMag", absMag))
00146         setAbsoluteMagnitude((float) absMag);
00147 
00148     string infoURL;
00149     if (params->getString("InfoURL", infoURL))
00150         setInfoURL(infoURL);
00151 
00152     return true;
00153 }

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