00001 // 00002 // $Id: planet_system.cpp 2 2008-03-01 20:58:50Z kulibali $ 00003 // 00004 // Copyright (c) 2008, The Periapsis Project. All rights reserved. 00005 // 00006 // Redistribution and use in source and binary forms, with or without 00007 // modification, are permitted provided that the following conditions are 00008 // met: 00009 // 00010 // * Redistributions of source code must retain the above copyright notice, 00011 // this list of conditions and the following disclaimer. 00012 // 00013 // * Redistributions in binary form must reproduce the above copyright 00014 // notice, this list of conditions and the following disclaimer in the 00015 // documentation and/or other materials provided with the distribution. 00016 // 00017 // * Neither the name of the The Periapsis Project nor the names of its 00018 // contributors may be used to endorse or promote products derived from 00019 // this software without specific prior written permission. 00020 // 00021 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00022 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00023 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00024 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 00025 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00026 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00027 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00028 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00029 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00030 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00031 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 // 00033 00034 #include "space/planet_system.hpp" 00035 #include "space/astronomy.hpp" 00036 00037 #include "math/math.hpp" 00038 #include "math/units.hpp" 00039 #include "platform/color.hpp" 00040 #include "platform/lowlevel.hpp" 00041 00042 using namespace gsgl; 00043 using namespace gsgl::data; 00044 using namespace gsgl::math; 00045 using namespace gsgl::scenegraph; 00046 using namespace gsgl::physics; 00047 00048 namespace periapsis 00049 { 00050 00051 namespace space 00052 { 00053 00054 BROKER_DEFINE_CREATOR(periapsis::space::planet_system); 00055 00056 static config_variable<gsgl::platform::color> PLANET_COORD_COLOR(L"space/planet_system/planet_coord_color", gsgl::platform::color(0.0f, 0.0f, 1.0f, 0.5f)); 00057 00058 00059 planet_system::planet_system(const config_record & conf) 00060 : orbital_frame(conf), cs(0) 00061 { 00062 get_draw_flags() |= node::NODE_NO_FRUSTUM_CHECK; 00063 cs = new utils::coord_system(this, 10000*units::METERS_PER_AU, 15, PLANET_COORD_COLOR); 00064 } // planet_system::planet_system() 00065 00066 00067 planet_system::~planet_system() 00068 { 00069 delete cs; 00070 } // planet_system::~planet_system() 00071 00072 00073 gsgl::real_t planet_system::get_priority(gsgl::scenegraph::context *) 00074 { 00075 if (get_name() == L"Earth Barysystem") 00076 { 00077 return utils::pos_in_eye_space(this).mag2() * 10; 00078 } 00079 else 00080 { 00081 return NODE_DRAW_IGNORE; 00082 } 00083 } // planet_system::get_priority() 00084 00085 00086 00087 00088 void planet_system::draw(gsgl::scenegraph::context *c) 00089 { 00090 if ((c->render_flags & context::RENDER_COORD_SYSTEMS) && get_name() == L"Earth Barysystem") 00091 { 00092 // the earth barysystem is still oriented to the ecliptic; we want to display the equatorial, but not move... 00093 glMultMatrixf(EQUATORIAL_WRT_ECLIPTIC.ptr()); CHECK_GL_ERRORS(); 00094 cs->draw(c); 00095 } 00096 } // planet_system::draw() 00097 00098 00099 } // namespace space 00100 00101 } // namespace periapsis