00001 // 00002 // $Id: earth.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/earth.hpp" 00035 00036 using namespace gsgl; 00037 using namespace gsgl::data; 00038 using namespace gsgl::math; 00039 using namespace gsgl::scenegraph; 00040 00041 00042 namespace periapsis 00043 { 00044 00045 namespace space 00046 { 00047 00048 BROKER_DEFINE_CREATOR(periapsis::space::planet_earth); 00049 00050 const gsgl::real_t planet_earth::BARYSYSTEM_OFFSET = 4700000.0f; // distance from the earth's center to the barycentre of the earth-moon system 00051 00052 00053 planet_earth::planet_earth(const config_record & obj_config) 00054 : large_rocky_body(obj_config), moon(0) 00055 { 00056 } // earth::earth() 00057 00058 00059 planet_earth::~planet_earth() 00060 { 00061 moon = 0; 00062 } // earth::~earth() 00063 00064 00065 void planet_earth::update(context *c) 00066 { 00067 large_rocky_body::update(c); 00068 00069 // find the moon if we don't already have it 00070 if (!moon) 00071 { 00072 for (simple_array<node *>::iterator i = get_parent()->get_children().iter(); i.is_valid(); ++i) 00073 { 00074 if (*i && (*i)->get_name() == L"Moon") 00075 { 00076 moon = dynamic_cast<large_rocky_body *>(*i); 00077 break; 00078 } 00079 } 00080 } 00081 00082 // offset the center of the planet to the real position of the earth relative to the earth-moon barysystem 00083 // we're one frame off, though, which is unfortunate 00084 if (moon) 00085 { 00086 vector moon_dir = moon->get_translation(); // the moon's position in the frame of the earth-moon barysystem 00087 moon_dir.normalize(); 00088 00089 get_translation() = moon_dir * -BARYSYSTEM_OFFSET; 00090 } 00091 } // earth::update() 00092 00093 00094 } // namespace space 00095 00096 } // namespace periapsis