OpenCOVER
coVRLighting.h
Go to the documentation of this file.
1/* This file is part of COVISE.
2
3 You can use it under the terms of the GNU Lesser General Public License
4 version 2.1 or later, see lgpl-2.1.txt.
5
6 * License: LGPL 2+ */
7
8#ifndef CO_VR_LIGHTING_H
9#define CO_VR_LIGHTING_H
10
23#include <util/common.h>
24#include <map>
25
26#include <osg/Vec4>
27#include <osg/LightSource>
28#include <osg/ref_ptr>
29namespace opencover {
30namespace ui {
31class Menu;
32class Button;
33class Slider;
34}
35}
36
37namespace opencover
38{
39
40class COVEREXPORT coVRLighting
41{
42 static coVRLighting *s_instance;
44
45public:
46 ui::Menu *lightingMenu_ = nullptr;
47 ui::Button *switchHeadlight_;
49
50 ui::Button *switchOtherlights_;
52
54 float specularlightStrength = 0.f;
55
56 ui::Button *switchSpotlight_;
58
59 multimap<string, osg::LightSource *> m;
60
61public:
62
63 enum { MaxNumLights = 8 };
64
65 typedef struct
66 {
67 float r, g, b;
68 } RGB;
69 typedef struct
70 {
71 float x, y, z, w;
72 } XYZW;
73 typedef struct
74 {
75 float x, y, z, expo, angle;
76 } SpotDef;
77 typedef struct
78 {
79 RGB diff, spec, amb;
82 } LightDef;
83
84 osg::ref_ptr<osg::LightSource> light1;
85 osg::ref_ptr<osg::LightSource> light2;
86
87 // rescue values of specular lights
88 osg::Vec4 headlightSpec, light1Spec, light2Spec, spotlightSpec;
89
97 osg::LightSource *createLightSource(const char *configName,
98 const LightDef &defValue,
99 bool force);
100
104 // void initMenuLight();
105
106 void initMenu();
107
108 struct Light
109 {
110 Light(osg::LightSource *ls, osg::Node *r)
111 {
112 source = ls;
113 root = r;
114 }
115 osg::ref_ptr<osg::LightSource> source;
116 osg::ref_ptr<osg::Node> root;
117 bool on;
118 };
119 vector<Light> lightList;
120
121 void config();
122 void init();
123
124public:
125 osg::ref_ptr<osg::LightSource> headlight;
126 osg::ref_ptr<osg::LightSource> spotlight;
127 osg::ref_ptr<osg::LightSource> shadowlight;
129
130 virtual ~coVRLighting();
131
132 void update();
133
134 // add light to scene
135 int addLight(osg::LightSource *ls, osg::Group *parent = NULL, osg::Node *root = NULL, const char *menuName = NULL);
136
137 // remove light from scene
138 osg::LightSource *removeLight(osg::LightSource *ls);
139
140 // switch light
141 // if limitToBranch is set, switch inside it only
142 osg::LightSource *switchLight(osg::LightSource *ls, bool on, osg::Node *limitToBranch = NULL);
143
144 // switch lights other than headlight and spot light
145 void switchOtherLights(bool on);
146
147 osg::LightSource *getShadowLight(){return shadowlight;};
148 void setShadowLight(osg::LightSource *ls);
149
150 bool isLightEnabled(size_t ln) const;
151};
152}
153#endif
Definition: ARToolKit.h:33
Definition: coVRLighting.h:41
ui::Slider * strengthSpecularlight_
Definition: coVRLighting.h:53
osg::ref_ptr< osg::LightSource > headlight
Definition: coVRLighting.h:125
bool headlightState
Definition: coVRLighting.h:48
osg::LightSource * removeLight(osg::LightSource *ls)
osg::LightSource * switchLight(osg::LightSource *ls, bool on, osg::Node *limitToBranch=NULL)
int addLight(osg::LightSource *ls, osg::Group *parent=NULL, osg::Node *root=NULL, const char *menuName=NULL)
osg::ref_ptr< osg::LightSource > spotlight
Definition: coVRLighting.h:126
bool isLightEnabled(size_t ln) const
void setShadowLight(osg::LightSource *ls)
osg::LightSource * createLightSource(const char *configName, const LightDef &defValue, bool force)
bool spotlightState
Definition: coVRLighting.h:57
multimap< string, osg::LightSource * > m
Definition: coVRLighting.h:59
vector< Light > lightList
Definition: coVRLighting.h:119
osg::Vec4 headlightSpec
Definition: coVRLighting.h:88
osg::ref_ptr< osg::LightSource > shadowlight
Definition: coVRLighting.h:127
osg::ref_ptr< osg::LightSource > light2
Definition: coVRLighting.h:85
ui::Button * switchHeadlight_
Definition: coVRLighting.h:47
ui::Button * switchOtherlights_
Definition: coVRLighting.h:50
osg::LightSource * getShadowLight()
Definition: coVRLighting.h:147
bool otherlightsState
Definition: coVRLighting.h:51
static coVRLighting * instance()
osg::ref_ptr< osg::LightSource > light1
Definition: coVRLighting.h:84
ui::Button * switchSpotlight_
Definition: coVRLighting.h:56
void switchOtherLights(bool on)
Definition: coVRLighting.h:66
float b
Definition: coVRLighting.h:67
Definition: coVRLighting.h:70
float w
Definition: coVRLighting.h:71
Definition: coVRLighting.h:74
float angle
Definition: coVRLighting.h:75
Definition: coVRLighting.h:78
RGB amb
Definition: coVRLighting.h:79
XYZW pos
Definition: coVRLighting.h:80
SpotDef spot
Definition: coVRLighting.h:81
Definition: coVRLighting.h:109
Light(osg::LightSource *ls, osg::Node *r)
Definition: coVRLighting.h:110
osg::ref_ptr< osg::LightSource > source
Definition: coVRLighting.h:115
osg::ref_ptr< osg::Node > root
Definition: coVRLighting.h:116
bool on
Definition: coVRLighting.h:117