-- $LastChangedDate: 2010-05-25 21:26:05 -0400 (Tue, 25 May 2010) $
-- LEGAL: COPYRIGHT (C) 2010 JIM E. BROOKS WWW.PALOMINO3D.ORG
-- Scene (Golden Gate Bridge).
-- scene_* scripts are called by Scene:Load() calling dofile().
-- See module.txt for documentation and pitfalls.

Scene.origin = sim.World:SphereVertex2WorldVertex( 37.518800077449, -122.37326847224, 2.0 )

Scene.objects = { }

-- Bridge.
Scene.objects.goldenGateBridge = {
    nodeSort = NodeSort:New( { shader="hw" } ),
    pos = Vec3( Scene.origin[LAT] + M2W(-400.0),
                Scene.origin[LON] + M2W(900.0),
                Scene.origin[ALT] + M2W(0.0) ),
    file = "models/scenery/GoldenGateBridge.osg.gz",
    load = sim.ModelCache.LOAD_SHARED,
    collidable = true,
    Rotate = function( obj ) obj:Rotate( XX, RADIAN_90 ); obj:Rotate( YY, RADIAN_180 ) end,
    scale = 1.4,
}

-- Alcatraz island.
Scene.objects.alcatraz = {
    pos = Vec3( Scene.origin[LAT] + M2W(300.0),
                Scene.origin[LON] + M2W(1200.0),
                Scene.origin[ALT] + M2W(0.0) ),
    file = "models/scenery/alcatraz.ac.gz",
    load = sim.ModelCache.LOAD_SHARED,
    collidable = true,
    Rotate = function( obj ) obj:Rotate( XX, RADIAN_90 ) end,
    scale = 1.4,
}

-- UFO.
-- Randomly show UFO, or do so always/never if -ufo/-no-ufo.
if ( sim.argvMap["-ufo"] or (not sim.argvMap["-no-ufo"] and math.random(10) <= 4) ) then
    Scene.objects.ufo = {
        pos = Vec3( Scene.origin[LAT] + M2W(0.0),
                    Scene.origin[LON] + M2W(-700.0),
                    Scene.origin[ALT] + M2W(130.0) ),
        file = "models/misc/ufo.ac.gz",
        load = sim.ModelCache.LOAD_SHARED,
        collidable = true,
        Rotate = function( obj ) obj:Rotate( XX, RADIAN_90 ); obj:Rotate( YY, RADIAN_90 ) end,
    }
    if ( sim.argvMap["-takeoff"] ) then
        Scene.objects.ufo.pos = Vec3( Scene.origin[LAT] + M2W(-30.0),
                                      Scene.origin[LON] + M2W(-100.0),
                                      Scene.origin[ALT] + M2W(40.0) )
    end
end

-- Light-house.
Scene.objects.lighthouse = {
    pos = Vec3( Scene.origin[LAT] + M2W(-2230.0),
                Scene.origin[LON] + M2W(220.0),
                Scene.origin[ALT] + M2W(55.0) ),
    file = "models/misc/lighthouse.ac.gz",
    load = sim.ModelCache.LOAD_SHARED,
    collidable = true,
    Rotate = function( obj ) obj:Rotate( XX, RADIAN_90 ); obj:Rotate( YY, Deg2Rad(-70.0) ) end,
    scale = 3.0,
}

-- Observatory.
Scene.objects.observatory = {
    pos = Vec3( Scene.origin[LAT] + M2W(-700.0),
                Scene.origin[LON] + M2W(2800.0),
                Scene.origin[ALT] + M2W(250.0) ),
    file = "models/misc/observatory.ac.gz",
    load = sim.ModelCache.LOAD_SHARED,
    collidable = true,
    Rotate = function( obj ) obj:Rotate( XX, RADIAN_90 ); obj:Rotate( YY, Deg2Rad(-70.0) ) end,
    scale = 1.5,
}

-- Sail-boat.
Scene.objects.sailboat = {
    nodeSort = NodeSort:New( { shader="hw" } ),
    pos = Vec3( Scene.origin[LAT] + M2W(-300.0),
                Scene.origin[LON] + M2W(700.0),
                Scene.origin[ALT] + M2W(0.0) ),
    file = "models/misc/sailboat.ac.gz",
    load = sim.ModelCache.LOAD_SHARED,
    collidable = true,
    Rotate = function( obj ) obj:Rotate( XX, RADIAN_90 ) end,
}

-- Radar.
Scene.objects.radar = {
    pos = Vec3( Scene.origin[LAT] + M2W(0.0),
                Scene.origin[LON] + M2W(2700.0),
                Scene.origin[ALT] + M2W(220.0) ),
    file = "models/misc/radar.ac.gz",
    load = sim.ModelCache.LOAD_SHARED,
    collidable = true,
    Rotate = function( obj ) obj:Rotate( XX, RADIAN_90 ); obj:Rotate( YY, Deg2Rad(-70.0) ) end,
    scale = 1.5,
}

Scene.objects.radar2 = Scene:CopyObject( Scene.objects.radar )
Scene.objects.radar2.pos = Vec3( Scene.origin[LAT] + M2W(800.0),
                                 Scene.origin[LON] + M2W(2750.0),
                                 Scene.origin[ALT] + M2W(210.0) )

-- Missile launcher.
Scene.objects.trailerLauncher = {
    pos = Vec3( Scene.origin[LAT] + M2W(-1350.0),
                Scene.origin[LON] + M2W(5100.0),
                Scene.origin[ALT] + M2W(295.0) ),
    file = "models/misc/trailerLauncher.osg.gz",
    load = sim.ModelCache.LOAD_SHARED,
    collidable = true,
    Rotate = function( obj ) obj:Rotate( ZZ, Deg2Rad(-50.0) ) end,
    scale = 0.2,
}

Scene.objects.missileLauncher = Scene:CopyObject( Scene.objects.trailerLauncher )
Scene.objects.missileLauncher.pos = Vec3( Scene.origin[LAT] + M2W(500.0),
                                          Scene.origin[LON] + M2W(2650.0),
                                          Scene.origin[ALT] + M2W(242.0) )
Scene.objects.missileLauncher.file = "models/misc/missileLauncher.osg.gz"
Scene.objects.missileLauncher.Rotate = function( obj ) obj:Rotate( XX, RADIAN_90 ); obj:Rotate( YY, Deg2Rad(20.0) ) end

-- Hook Scene:Load().
function Scene:PostLoad()
    -- Game class doesn't exist in manipulator-mode.
    if ( Game ) then
        -- Schedule animation of sailboat.
        Game:ScheduleAnimation( Actor:New( "Sailboat", Game.TEAM_NUM_NEUTRAL, self.objects.sailboat.object, Actor.DONT_SHOW_IN_HUD ),
                                sim.Base:GetElapsedTime() + 20*1000 )
    end
end
