salut,
j'analyse un petit programme , j'ai des difficultés a comprendre certaines fonctions :
voici la classe
les classe que je ne comprends pas est :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129 #ifndef FGEVENTHANDLER_H #define FGEVENTHANDLER_H 1 #include <map> #include <osg/Quat> #include <osgGA/GUIEventHandler> #include <osgViewer/ViewerEventHandlers> #include "fg_os.hxx" namespace flightgear { class FGEventHandler : public osgGA::GUIEventHandler { public: FGEventHandler(); virtual ~FGEventHandler() {} virtual const char* className() const {return "FGEventHandler"; } #if 0 virtual void init(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us); #endif virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us); void setIdleHandler(fgIdleHandler idleHandler) { this->idleHandler = idleHandler; } fgIdleHandler getIdleHandler() const { return idleHandler; } void setDrawHandler(fgDrawHandler drawHandler) { this->drawHandler = drawHandler; } fgDrawHandler getDrawHandler() const { return drawHandler; } void setWindowResizeHandler(fgWindowResizeHandler windowResizeHandler) { this->windowResizeHandler = windowResizeHandler; } fgWindowResizeHandler getWindowResizeHandler() const { return windowResizeHandler; } void setKeyHandler(fgKeyHandler keyHandler) { this->keyHandler = keyHandler; } fgKeyHandler getKeyHandler() const { return keyHandler; } void setMouseClickHandler(fgMouseClickHandler mouseClickHandler) { this->mouseClickHandler = mouseClickHandler; } fgMouseClickHandler getMouseClickHandler() { return mouseClickHandler; } void setMouseMotionHandler(fgMouseMotionHandler mouseMotionHandler) { this->mouseMotionHandler = mouseMotionHandler; } fgMouseMotionHandler getMouseMotionHandler() { return mouseMotionHandler; } int getCurrentModifiers() const { return currentModifiers; } void setMouseWarped() { mouseWarped = true; } /** Whether or not resizing is supported. It might not be when * using multiple displays. */ bool getResizable() { return resizable; } void setResizable(bool _resizable) { resizable = _resizable; } protected: osg::ref_ptr<osg::Node> _node; fgIdleHandler idleHandler; fgDrawHandler drawHandler; fgWindowResizeHandler windowResizeHandler; fgKeyHandler keyHandler; fgMouseClickHandler mouseClickHandler; fgMouseMotionHandler mouseMotionHandler; osg::ref_ptr<osgViewer::StatsHandler> statsHandler; osg::ref_ptr<osgGA::GUIEventAdapter> statsEvent; int statsType; int currentModifiers; std::map<int, int> numlockKeyMap; void handleKey(const osgGA::GUIEventAdapter& ea, int& key, int& modifiers); bool resizable; bool mouseWarped; // workaround for osgViewer double scroll events bool scrollButtonPressed; int release_keys[128]; void handleStats(osgGA::GUIActionAdapter& us); }; void eventToWindowCoords(const osgGA::GUIEventAdapter* ea, double& x, double& y); void eventToWindowCoordsYDown(const osgGA::GUIEventAdapter* ea, double& x, double& y); } #endif
car ce sont des classes qui n'existent pas .
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 fgIdleHandler ; fgDrawHandler ;
dans
Code : Sélectionner tout - Visualiser dans une fenêtre à part #include "fg_os.hxx"il y a aussi une fonction important par rapport au sujet :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 fff#ifndef _FG_OS_HXX #define _FG_OS_HXX #ifdef HAVE_CONFIG_H # include <config.h> #endif #include <string> #include <vector> #include <osg/ref_ptr> #include <osg/Camera> #include <osg/GraphicsContext> enum { MOUSE_BUTTON_LEFT, MOUSE_BUTTON_MIDDLE, MOUSE_BUTTON_RIGHT }; enum { MOUSE_BUTTON_DOWN, MOUSE_BUTTON_UP }; enum { MOUSE_CURSOR_NONE, MOUSE_CURSOR_POINTER, MOUSE_CURSOR_WAIT, MOUSE_CURSOR_CROSSHAIR, MOUSE_CURSOR_LEFTRIGHT, MOUSE_CURSOR_TOPSIDE, MOUSE_CURSOR_BOTTOMSIDE, MOUSE_CURSOR_LEFTSIDE, MOUSE_CURSOR_RIGHTSIDE, MOUSE_CURSOR_TOPLEFT, MOUSE_CURSOR_TOPRIGHT, MOUSE_CURSOR_BOTTOMLEFT, MOUSE_CURSOR_BOTTOMRIGHT, }; enum { KEYMOD_NONE = 0, KEYMOD_RELEASED = 1, // Not a mod key, indicates "up" action KEYMOD_SHIFT = 2, KEYMOD_CTRL = 4, KEYMOD_ALT = 8, KEYMOD_META = 16, KEYMOD_SUPER = 32, KEYMOD_HYPER = 64, KEYMOD_MAX = 128 }; // A note on key codes: none are defined here. FlightGear has no // hard-coded interpretations of codes other than modifier keys, so we // can get away with that. The only firm requirement is that the // codes passed to the fgKeyHandler function be correctly interpreted // by the PUI library. Users who need to hard-code key codes // (probably not a good idea in any case) can use the pu.hxx header // for definitions. // // OS integration functions // void fgOSInit(int* argc, char** argv); void fgOSOpenWindow(bool stencil); void fgOSFullScreen(); void fgOSMainLoop(); void fgOSExit(int code); void fgSetMouseCursor(int cursor); int fgGetMouseCursor(); void fgWarpMouse(int x, int y); int fgGetKeyModifiers(); void fgRequestRedraw(); // // Callbacks and registration API // namespace osg { class Camera; class GraphicsContext; } namespace osgGA { class GUIEventAdapter; } typedef void (*fgIdleHandler)(); typedef void (*fgDrawHandler)(); typedef void (*fgWindowResizeHandler)(int w, int h); typedef void (*fgKeyHandler)(int key, int keymod, int mousex, int mousey); typedef void (*fgMouseClickHandler)(int button, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter*); typedef void (*fgMouseMotionHandler)(int x, int y); void fgRegisterIdleHandler(fgIdleHandler func); void fgRegisterDrawHandler(fgDrawHandler func); void fgRegisterWindowResizeHandler(fgWindowResizeHandler func); void fgRegisterKeyHandler(fgKeyHandler func); void fgRegisterMouseClickHandler(fgMouseClickHandler func); void fgRegisterMouseMotionHandler(fgMouseMotionHandler func); #endif // _FG_OS_HXX
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259 static void fgIdleFunction ( void ) { static osg::ref_ptr<GeneralInitOperation> genOp; if ( idle_state == 0 ) { idle_state++; // Pick some window on which to do queries. // XXX Perhaps all this graphics initialization code should be // moved to renderer.cxx? genOp = new GeneralInitOperation; osg::Camera* guiCamera = getGUICamera(CameraGroup::getDefault()); WindowSystemAdapter* wsa = WindowSystemAdapter::getWSA(); osg::GraphicsContext* gc = 0; if (guiCamera) gc = guiCamera->getGraphicsContext(); if (gc) { gc->add(genOp.get()); } else { wsa->windows[0]->gc->add(genOp.get()); } guiStartInit(gc); } else if ( idle_state == 1 ) { if (genOp.valid()) { if (!genOp->isFinished()) return; genOp = 0; } if (!guiFinishInit()) return; idle_state++; fgSplashProgress("reading aircraft list"); } else if ( idle_state == 2 ) { idle_state++; // Read the list of available aircraft fgReadAircraft(); fgSplashProgress("reading airport & navigation data"); } else if ( idle_state == 3 ) { idle_state++; fgInitNav(); fgSplashProgress("setting up scenery"); } else if ( idle_state == 4 ) { idle_state++; // based on the requested presets, calculate the true starting // lon, lat fgInitPosition(); fgInitTowerLocationListener(); SGTime *t = fgInitTime(); globals->set_time_params( t ); // Do some quick general initializations if( !fgInitGeneral()) { SG_LOG( SG_GENERAL, SG_ALERT, "General initialization failed ..." ); exit(-1); } //////////////////////////////////////////////////////////////////// // Initialize the property-based built-in commands //////////////////////////////////////////////////////////////////// fgInitCommands(); //////////////////////////////////////////////////////////////////// // Initialize the material manager //////////////////////////////////////////////////////////////////// globals->set_matlib( new SGMaterialLib ); simgear::SGModelLib::init(globals->get_fg_root()); //////////////////////////////////////////////////////////////////// // Initialize the TG scenery subsystem. //////////////////////////////////////////////////////////////////// globals->set_scenery( new FGScenery ); globals->get_scenery()->init(); globals->get_scenery()->bind(); globals->set_tile_mgr( new FGTileMgr ); //////////////////////////////////////////////////////////////////// // Initialize the general model subsystem. //////////////////////////////////////////////////////////////////// globals->set_model_mgr(new FGModelMgr); globals->get_model_mgr()->init(); globals->get_model_mgr()->bind(); fgSplashProgress("loading aircraft"); } else if ( idle_state == 5 ) { idle_state++; //////////////////////////////////////////////////////////////////// // Initialize the 3D aircraft model subsystem (has a dependency on // the scenery subsystem.) //////////////////////////////////////////////////////////////////// globals->set_aircraft_model(new FGAircraftModel); globals->get_aircraft_model()->init(); globals->get_aircraft_model()->bind(); //////////////////////////////////////////////////////////////////// // Initialize the view manager subsystem. //////////////////////////////////////////////////////////////////// FGViewMgr *viewmgr = new FGViewMgr; globals->set_viewmgr( viewmgr ); viewmgr->init(); viewmgr->bind(); fgSplashProgress("generating sky elements"); } else if ( idle_state == 6 ) { idle_state++; // Initialize the sky SGPath ephem_data_path( globals->get_fg_root() ); ephem_data_path.append( "Astro" ); SGEphemeris *ephem = new SGEphemeris( ephem_data_path.c_str() ); ephem->update( globals->get_time_params()->getMjd(), globals->get_time_params()->getLst(), 0.0 ); globals->set_ephem( ephem ); // TODO: move to environment mgr thesky = new SGSky; SGPath texture_path(globals->get_fg_root()); texture_path.append("Textures"); texture_path.append("Sky"); for (int i = 0; i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) { SGCloudLayer * layer = new SGCloudLayer(texture_path.str()); thesky->add_cloud_layer(layer); } SGPath sky_tex_path( globals->get_fg_root() ); sky_tex_path.append( "Textures" ); sky_tex_path.append( "Sky" ); thesky->texture_path( sky_tex_path.str() ); // The sun and moon diameters are scaled down numbers of the // actual diameters. This was needed to fit both the sun and the // moon within the distance to the far clip plane. // Moon diameter: 3,476 kilometers // Sun diameter: 1,390,000 kilometers thesky->build( 80000.0, 80000.0, 463.3, 361.8, *globals->get_ephem(), fgGetNode("/environment", true)); // Initialize MagVar model SGMagVar *magvar = new SGMagVar(); globals->set_mag( magvar ); // kludge to initialize mag compass // (should only be done for in-flight // startup) // update magvar model globals->get_mag()->update( fgGetDouble("/position/longitude-deg") * SGD_DEGREES_TO_RADIANS, fgGetDouble("/position/latitude-deg") * SGD_DEGREES_TO_RADIANS, fgGetDouble("/position/altitude-ft") * SG_FEET_TO_METER, globals->get_time_params()->getJD() ); double var = globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES; fgSetDouble("/instrumentation/heading-indicator/offset-deg", -var); fgSetDouble("/instrumentation/heading-indicator-fg/offset-deg", -var); // airport = new ssgBranch; // airport->setName( "Airport Lighting" ); // lighting->addKid( airport ); // build our custom render states fgSplashProgress("initializing subsystems"); } else if ( idle_state == 7 ) { idle_state++; // Initialize audio support #ifdef ENABLE_AUDIO_SUPPORT // Start the intro music if ( fgGetBool("/sim/startup/intro-music") ) { SGPath mp3file( globals->get_fg_root() ); mp3file.append( "Sounds/intro.mp3" ); SG_LOG( SG_GENERAL, SG_INFO, "Starting intro music: " << mp3file.str() ); # if defined( __CYGWIN__ ) string command = "start /m `cygpath -w " + mp3file.str() + "`"; # elif defined( _WIN32 ) string command = "start /m " + mp3file.str(); # else string command = "mpg123 " + mp3file.str() + "> /dev/null 2>&1"; # endif system ( command.c_str() ); } #endif // This is the top level init routine which calls all the // other subsystem initialization routines. If you are adding // a subsystem to flightgear, its initialization call should be // located in this routine. if( !fgInitSubsystems()) { SG_LOG( SG_GENERAL, SG_ALERT, "Subsystem initialization failed ..." ); exit(-1); } fgSplashProgress("setting up time & renderer"); } else if ( idle_state == 8 ) { idle_state = 1000; // Initialize the time offset (warp) after fgInitSubsystem // (which initializes the lighting interpolation tables.) fgInitTimeOffset(); // setup OpenGL view parameters globals->get_renderer()->init(); SG_LOG( SG_GENERAL, SG_INFO, "Panel visible = " << fgPanelVisible() ); globals->get_renderer()->resize( fgGetInt("/sim/startup/xsize"), fgGetInt("/sim/startup/ysize") ); fgSplashProgress("loading scenery objects"); int session = fgGetInt("/sim/session",0); session++; fgSetInt("/sim/session",session); } if ( idle_state == 1000 ) { // We've finished all our initialization steps, from now on we // run the main loop. fgSetBool("sim/sceneryloaded", false); fgRegisterIdleHandler( fgMainLoop ); } } static void upper_case_property(const char *name) { using namespace simgear; SGPropertyNode *p = fgGetNode(name, false); if (!p) { p = fgGetNode(name, true); p->setStringValue(""); } else { props::Type t = p->getType(); if (t == props::NONE || t == props::UNSPECIFIED) p->setStringValue(""); else assert(t == props::STRING); } p->addChangeListener(new FGMakeUpperCase); }
est ce un rapport avec le callback, je ne comprends pas que l'on puisse crée une classe qui n'existe pas .
au juste est ce que c'est une classe ou une fonction ?
merci !
Partager