]> git.mxchange.org Git - simgear.git/blob - simgear/sky/sky.cxx
Complete overhaul of the sky/sun/moon/stars/planets. It is now an ssg
[simgear.git] / simgear / sky / sky.cxx
1 // sky.cxx -- ssg based sky model
2 //
3 // Written by Curtis Olson, started December 1997.
4 // SSG-ified by Curtis Olson, February 2000.
5 //
6 // Copyright (C) 1997-2000  Curtis L. Olson  - curt@flightgear.org
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 //
22 // $Id$
23
24
25 #include <plib/ssg.h>           // plib include
26
27 #include "sky.hxx"
28
29
30 // Constructor
31 SGSky::SGSky( void ) {
32 }
33
34
35 // Destructor
36 SGSky::~SGSky( void ) {
37 }
38
39
40 // initialize the sky and connect the components to the scene graph at
41 // the provided branch
42 ssgBranch * SGSky::build(  double sun_size, double moon_size,
43                            int nplanets, sgdVec3 *planet_data,
44                            double planet_dist,
45                            int nstars, sgdVec3 *star_data, double star_dist )
46 {
47     sky_selector = new ssgSelector;
48     sky_transform = new ssgTransform;
49
50     dome = new SGSkyDome;
51     sky_transform -> addKid( dome->build() );
52
53     planets = new SGStars;
54     sky_transform -> addKid( planets->build(nplanets, planet_data,
55                                             planet_dist)
56                              );
57
58     stars = new SGStars;
59     sky_transform -> addKid( stars->build(nstars, star_data, star_dist) );
60     
61     moon = new SGMoon;
62     sky_transform -> addKid( moon->build(tex_path, moon_size) );
63
64     oursun = new SGSun;
65     sky_transform -> addKid( oursun->build(tex_path, sun_size) );
66
67     sky_selector->addKid( sky_transform );
68     sky_selector->clrTraversalMaskBits( SSGTRAV_HOT );
69
70     return sky_selector;
71 }
72
73
74 // repaint the sky components based on current value of sun_angle,
75 // sky, and fog colors.
76 //
77 // sun angle in degrees relative to verticle
78 // 0 degrees = high noon
79 // 90 degrees = sun rise/set
80 // 180 degrees = darkest midnight
81 bool SGSky::repaint( sgVec4 sky_color, sgVec4 fog_color,
82                      double sun_angle, double moon_angle,
83                      int nplanets, sgdVec3 *planet_data,
84                      int nstars, sgdVec3 *star_data )
85 {
86     dome->repaint( sky_color, fog_color, sun_angle );
87     oursun->repaint( sun_angle );
88     moon->repaint( moon_angle );
89     planets->repaint( sun_angle, nplanets, planet_data );
90     stars->repaint( sun_angle, nstars, star_data );
91
92     return true;
93 }
94
95
96 // reposition the sky at the specified origin and orientation
97 //
98 // lon specifies a rotation about the Z axis
99 // lat specifies a rotation about the new Y axis
100 // spin specifies a rotation about the new Z axis (this allows
101 // additional orientation for the sunrise/set effects and is used by
102 // the skydome and perhaps clouds.
103 bool SGSky::reposition( sgVec3 view_pos, sgVec3 zero_elev, 
104                         double lon, double lat, double spin,
105                         double gst, 
106                         double sun_ra, double sun_dec, double sun_dist,
107                         double moon_ra, double moon_dec, double moon_dist )
108 {
109     double angle = gst * 15;    // degrees
110     dome->reposition( zero_elev, lon, lat, spin );
111     oursun->reposition( view_pos, angle, sun_ra, sun_dec, sun_dist );
112     moon->reposition( view_pos, angle, moon_ra, moon_dec, moon_dist );
113     planets->reposition( view_pos, angle );
114     stars->reposition( view_pos, angle );
115
116     return true;
117 }