/*****************************************************************************
 * $LastChangedDate: 2011-04-10 17:44:55 -0400 (Sun, 10 Apr 2011) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   Moon.
 *//*
 * LEGAL:   COPYRIGHT (C) 2008 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *****************************************************************************/

#define SKY_MOON_CC 1
#include "base/module.hh"
using namespace base;
#include "gfx/module.hh"
#include "gfx/osg.hh"
using namespace gfx;
#include "world/module.hh"
#include "world/debug.hh"  // ASSERT_LAT_LON_DEG()
using namespace world;
#include "fx/module.hh"
#include "fx/texture.hh"
using namespace fx;
#include "sky/module.hh"
#include "sky/moon.hh"
#include "sky/defs.hh"
#include "sky/sky_dome_painter.hh"

namespace sky {

////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////  Moon  //////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

/*****************************************************************************
 * ctor/dtor.
 * SkyDome must be passed since Sky ctor calls Stars ctor,
 * so calling GET_SKY_DOME() would cause an infinite cycle.
 *****************************************************************************/
Moon::Moon( SkyDome& skyDome, const Degree lat, const Degree lon )
:   Sprite(Sprite::Args( skyDome.ComputeVertexOnDome(lat,lon,0.95f),  // pos
                         skyDome.GetRadius() * sky::defs::SKY_DOME_MOON_RATIO,  // radius
                         Texture::NewTextureAsStateSet("textures/moon.png"),
                         RGBA(1.0f,1.0f,1.0f,1.0f))),
    mSkyDome(skyDome)
{
CHECK_TYPESIG(&skyDome,TYPESIG_SKY_DOME);
}

Moon::~Moon()
{
    // NOP
}

/*****************************************************************************
 * Set position of Moon by (lat,lon).
 *****************************************************************************/
void
Moon::SetPosition( const Degree lat, const Degree lon )
{
ASSERT_LAT_LON_DEG(lat,lon);
CHECK_TYPESIG(&mSkyDome,TYPESIG_SKY_DOME);

    // 0.95 to be slightly inside dome.
    Sprite::SetPosition( mSkyDome.ComputeVertexOnDome( lat, lon, 0.95f ) );
}

/*****************************************************************************
 * For scene-graph to render optimally, nodes should be sorted by state.
 * GetStateBits() is meant to be used as an arg to World::Attach(object,stateBits).
 *****************************************************************************/
NodeSort
Moon::GetNodeSort( void )
{
    // Transparent sprite without its visiblility affected by fog/lighting.
    return NodeSort( NodeSort::Attribs(NodeSort::Attribs::TRANSPARENT) );
}

} // namespace sky
