FlightGear next
light.hxx
Go to the documentation of this file.
1/*
2 * SPDX-FileName: light.hxx
3 * SPDX-FileComment: lighting routines
4 * SPDX-FileCopyrightText: Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8#pragma once
9
10#include <simgear/props/props.hxx>
11#include <simgear/structure/subsystem_mgr.hxx>
12#include <simgear/props/tiedpropertylist.hxx>
13#include <simgear/math/SGMath.hxx>
14
15// Define a structure containing the global lighting parameters
16class FGLight : public SGSubsystem {
17private:
21
22 // in geocentric coordinates
23 double _sun_lon = 0.0, _sun_lat = 0.0;
24 double _moon_lon = 0.0, _moon_gc_lat = 0.0;
25
26 // (in view coordinates)
27 SGVec4f _sun_vec = {0, 0, 0, 0};
28 SGVec4f _moon_vec = {0, 0, 0, 0};
29
30 // inverse (in view coordinates)
31 SGVec4f _sun_vec_inv = {0, 0, 0, 0};
32 SGVec4f _moon_vec_inv = {0, 0, 0, 0};
33
34 // the angle between the celestial object and the local horizontal
35 // (in radians)
36 double _sun_angle = 0.0 , _moon_angle = 0.0;
37
38 // the rotation around our vertical axis of the sun (relative to
39 // due south with positive numbers going in the counter clockwise
40 // direction.) This is the direction we'd need to face if we
41 // wanted to travel towards celestial object.
42 double _sun_rotation = 0.0, _moon_rotation = 0.0;
43
44 // update all solar system bodies of interest
45 void updateObjects();
46
47 // update the position of one solar system body
48 void updateBodyPos(bool sun_not_moon, double& lon, double& lat,
49 SGVec4f& vec, SGVec4f& vec_inv,
50 double& angle, SGPropertyNode_ptr AngleRad,
51 double& rotation);
52
53 SGPropertyNode_ptr _sunAngleRad;
54 SGPropertyNode_ptr _moonAngleRad;
55
56 simgear::TiedPropertyList _tiedProperties;
57
61 template <typename T>
62 void tie(SGPropertyNode* aNode, const char* aRelPath, const SGRawValue<T>& aRawValue)
63 {
64 _tiedProperties.Tie(aNode->getNode(aRelPath, true), aRawValue);
65 }
66
67public:
68 FGLight() = default;
69 virtual ~FGLight() = default;
70
71 // Subsystem API.
72 void bind() override;
73 void init() override;
74 void reinit() override;
75 void unbind() override;
76 void update(double dt) override;
77
78 // Subsystem identification.
79 static const char* staticSubsystemClassId() { return "lighting"; }
80
81
82 // Sun related functions
83
84 inline double get_sun_angle() const { return _sun_angle; }
85 inline void set_sun_angle(double a) { _sun_angle = a; }
86
87 inline double get_sun_rotation() const { return _sun_rotation; }
88 inline void set_sun_rotation(double r) { _sun_rotation = r; }
89
90 inline double get_sun_lon() const { return _sun_lon; }
91 inline void set_sun_lon(double l) { _sun_lon = l; }
92
93 inline double get_sun_lat() const { return _sun_lat; }
94 inline void set_sun_lat(double l) { _sun_lat = l; }
95
96 inline SGVec4f& sun_vec() { return _sun_vec; }
97 inline SGVec4f& sun_vec_inv() { return _sun_vec_inv; }
98
99
100 // Moon related functions
101
102 inline double get_moon_angle() const { return _moon_angle; }
103 inline void set_moon_angle(double a) { _moon_angle = a; }
104
105 inline double get_moon_rotation() const { return _moon_rotation; }
106 inline void set_moon_rotation(double r) { _moon_rotation = r; }
107
108 inline double get_moon_lon() const { return _moon_lon; }
109 inline void set_moon_lon(double l) { _moon_lon = l; }
110
111 inline double get_moon_gc_lat() const { return _moon_gc_lat; }
112 inline void set_moon_gc_lat(double l) { _moon_gc_lat = l; }
113
114 inline const SGVec4f& moon_vec() const { return _moon_vec; }
115 inline const SGVec4f& moon_vec_inv() const { return _moon_vec_inv; }
116};
double get_sun_lon() const
Definition light.hxx:90
void set_moon_gc_lat(double l)
Definition light.hxx:112
double get_moon_rotation() const
Definition light.hxx:105
void reinit() override
Definition light.cxx:28
void set_sun_rotation(double r)
Definition light.hxx:88
double get_sun_lat() const
Definition light.hxx:93
const SGVec4f & moon_vec_inv() const
Definition light.hxx:115
double get_moon_angle() const
Definition light.hxx:102
void unbind() override
Definition light.cxx:54
FGLight()=default
static const char * staticSubsystemClassId()
Definition light.hxx:79
double get_moon_lon() const
Definition light.hxx:108
void init() override
Definition light.cxx:21
void set_sun_lat(double l)
Definition light.hxx:94
void set_moon_rotation(double r)
Definition light.hxx:106
double get_moon_gc_lat() const
Definition light.hxx:111
SGVec4f & sun_vec_inv()
Definition light.hxx:97
double get_sun_rotation() const
Definition light.hxx:87
double get_sun_angle() const
Definition light.hxx:84
virtual ~FGLight()=default
void bind() override
Definition light.cxx:34
void set_moon_lon(double l)
Definition light.hxx:109
void update(double dt) override
Definition light.cxx:61
void set_moon_angle(double a)
Definition light.hxx:103
void set_sun_lon(double l)
Definition light.hxx:91
SGVec4f & sun_vec()
Definition light.hxx:96
void set_sun_angle(double a)
Definition light.hxx:85
const SGVec4f & moon_vec() const
Definition light.hxx:114