~ubuntu-branches/ubuntu/trusty/openscenegraph/trusty

« back to all changes in this revision

Viewing changes to OpenSceneGraph/src/osgPlugins/cfg/CameraConfig.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-07-29 04:34:38 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 lenny)
  • Revision ID: james.westby@ubuntu.com-20080729043438-no1h9h0dpsrlzp1y
* Non-maintainer upload.
* No longer try to detect (using /proc/cpuinfo when available) how many
  CPUs are available, fixing the FTBFS (due to -j0) on various platforms
  (Closes: #477353). The right way to do it is to support parallel=n in
  DEB_BUILD_OPTIONS (see Debian Policy §4.9.1), and adequate support has
  been implemented.
* Add patch to fix FTBFS due to the build system now refusing to handle
  whitespaces (Policy CMP0004 say the logs), thanks to Andreas Putzo who
  provided it (Closes: #482239):
   - debian/patches/fix-cmp0004-build-failure.dpatch
* Remove myself from Uploaders, as requested a while ago, done by Luk in
  his 2.2.0-2.1 NMU, which was never acknowledged.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*-c++-*- Producer - Copyright (C) 2001-2004  Don Burns
 
2
 *
 
3
 * This library is open source and may be redistributed and/or modified under
 
4
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
 
5
 * (at your option) any later version.  The full license is in LICENSE file
 
6
 * included with this distribution, and on the openscenegraph.org website.
 
7
 *
 
8
 * This library is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * OpenSceneGraph Public License for more details.
 
12
 */
 
13
 
 
14
#include <osg/Notify>
 
15
#include <osg/ref_ptr>
 
16
#include <osg/io_utils>
 
17
 
 
18
#if defined(WIN32) && !defined(__CYGWIN__)
 
19
    #include <io.h>
 
20
    #include <windows.h>
 
21
    #include <winbase.h>
 
22
    // set up for windows so acts just like unix access().
 
23
    #define F_OK 4
 
24
#else // unix
 
25
    #include <unistd.h>
 
26
#endif
 
27
 
 
28
 
 
29
#ifdef _X11_IMPLEMENTATION
 
30
#  include <X11/Xlib.h>
 
31
#endif
 
32
 
 
33
#include <memory.h>
 
34
#include <stdlib.h>
 
35
#include <iostream>
 
36
 
 
37
#include "CameraConfig.h"
 
38
 
 
39
 
 
40
using namespace osgProducer;
 
41
 
 
42
 
 
43
unsigned int CameraConfig::getNumberOfScreens()
 
44
{
 
45
#if 0
 
46
    return RenderSurface::getNumberOfScreens();
 
47
#else
 
48
    return 1;
 
49
#endif
 
50
}
 
51
 
 
52
 
 
53
//////////////////
 
54
CameraConfig::CameraConfig() :
 
55
    _can_add_visual_attributes(false),
 
56
    _current_render_surface(NULL),
 
57
    _can_add_render_surface_attributes(false),
 
58
    _current_camera(NULL),
 
59
    _can_add_camera_attributes(false),
 
60
    _input_area(NULL),
 
61
    _can_add_input_area_entries(false),
 
62
    _offset_shearx(0.0f),
 
63
    _offset_sheary(0.0f),
 
64
    _postmultiply(false)
 
65
    
 
66
{
 
67
    _offset_matrix[0] = 1.0; _offset_matrix[1] = 0.0; _offset_matrix[2] = 0.0; _offset_matrix[3] = 0.0;
 
68
    _offset_matrix[4] = 0.0; _offset_matrix[5] = 1.0; _offset_matrix[6] = 0.0; _offset_matrix[7] = 0.0;
 
69
    _offset_matrix[8] = 0.0; _offset_matrix[9] = 0.0; _offset_matrix[10] = 1.0; _offset_matrix[11] = 0.0;
 
70
    _offset_matrix[12] = 0.0; _offset_matrix[13] = 0.0; _offset_matrix[14] = 0.0; _offset_matrix[15] = 1.0;
 
71
    
 
72
    _threadModelDirective = CameraGroup::getDefaultThreadModel();
 
73
 
 
74
}
 
75
 
 
76
 
 
77
void CameraConfig::beginVisual( void )
 
78
{
 
79
    _current_visual_chooser = new VisualChooser;
 
80
    _can_add_visual_attributes = true;
 
81
}
 
82
 
 
83
void CameraConfig::beginVisual( const char * name )
 
84
{
 
85
    std::pair<std::map<std::string,VisualChooser *>::iterator,bool> res = 
 
86
      _visual_map.insert(std::pair<std::string,VisualChooser *>(std::string(name), new VisualChooser));
 
87
    _current_visual_chooser = (res.first)->second;
 
88
    _can_add_visual_attributes = true;
 
89
}
 
90
 
 
91
void CameraConfig::setVisualSimpleConfiguration( void )
 
92
{
 
93
     if( !_current_visual_chooser.valid() || _can_add_visual_attributes == false )
 
94
     {
 
95
         std::cerr << "CameraConfig::setVisualSimpleConfiguration() : ERROR no current visual\n";
 
96
         return;
 
97
     }
 
98
     _current_visual_chooser->setSimpleConfiguration();
 
99
}
 
100
 
 
101
void CameraConfig::setVisualByID( unsigned int id )
 
102
{
 
103
     if( !_current_visual_chooser.valid() || _can_add_visual_attributes == false )
 
104
     {
 
105
         std::cerr << "CameraConfig::setVisualByID(id) : ERROR no current visual\n";
 
106
         return;
 
107
     }
 
108
     _current_visual_chooser->setVisualID( id );
 
109
}
 
110
 
 
111
void CameraConfig::addVisualAttribute( VisualChooser::AttributeName token, int param )
 
112
{
 
113
     if( !_current_visual_chooser.valid() || _can_add_visual_attributes == false )
 
114
     {     
 
115
         std::cerr << "CameraConfig::addVisualAttribute(token,param) : ERROR no current visual\n";
 
116
         return;
 
117
     }
 
118
     _current_visual_chooser->addAttribute( token, param );
 
119
}
 
120
 
 
121
void CameraConfig::addVisualAttribute( VisualChooser::AttributeName token )
 
122
{
 
123
     if( !_current_visual_chooser.valid()  || _can_add_visual_attributes == false)
 
124
     {
 
125
         std::cerr << "CameraConfig::addVisualAttribute(token) : ERROR no current visual\n";
 
126
         return;
 
127
     }
 
128
     _current_visual_chooser->addAttribute( token );
 
129
}
 
130
 
 
131
void CameraConfig::addVisualExtendedAttribute( unsigned int token )
 
132
{
 
133
     if( !_current_visual_chooser.valid()  || _can_add_visual_attributes == false)
 
134
     {
 
135
         std::cerr << "CameraConfig::addVisualExtendedAttribute(token) : ERROR no current visual\n";
 
136
         return;
 
137
     }
 
138
     _current_visual_chooser->addExtendedAttribute( token );
 
139
}
 
140
 
 
141
void CameraConfig::addVisualExtendedAttribute( unsigned int token, int param )
 
142
{
 
143
     if( !_current_visual_chooser.valid()  || _can_add_visual_attributes == false)
 
144
     {
 
145
         std::cerr << "CameraConfig::addVisualExtendedAttribute(token, param) : ERROR no current visual\n";
 
146
         return;
 
147
     }
 
148
     _current_visual_chooser->addExtendedAttribute( token, param );
 
149
}
 
150
 
 
151
void CameraConfig::endVisual( void )
 
152
{
 
153
    _can_add_visual_attributes = false;
 
154
}
 
155
 
 
156
VisualChooser *CameraConfig::findVisual( const char *name )
 
157
{
 
158
    std::map<std::string, VisualChooser *>::iterator p;
 
159
    p = _visual_map.find( std::string(name) );
 
160
    if( p == _visual_map.end() )
 
161
        return NULL;
 
162
    else
 
163
            return (*p).second;
 
164
}
 
165
 
 
166
void CameraConfig::beginRenderSurface( const char *name )
 
167
{
 
168
    std::pair<std::map<std::string,  osg::ref_ptr<RenderSurface> >::iterator,bool> res = 
 
169
      _render_surface_map.insert(std::pair<std::string, osg::ref_ptr< RenderSurface> >(
 
170
                                      std::string(name), 
 
171
                                      new RenderSurface));
 
172
    _current_render_surface = (res.first)->second.get();
 
173
    _current_render_surface->setWindowName( std::string(name) );
 
174
    _can_add_render_surface_attributes = true;
 
175
}
 
176
 
 
177
void CameraConfig::setRenderSurfaceVisualChooser( const char *name )
 
178
{
 
179
    VisualChooser *vc = findVisual( name );
 
180
    if( vc != NULL && _current_render_surface != NULL )
 
181
        _current_render_surface->setVisualChooser( vc );
 
182
}
 
183
 
 
184
void CameraConfig::setRenderSurfaceVisualChooser( void )
 
185
{
 
186
    if( _current_render_surface != NULL && _current_visual_chooser.valid() )
 
187
        _current_render_surface->setVisualChooser( _current_visual_chooser.get() );
 
188
}
 
189
 
 
190
void CameraConfig::setRenderSurfaceWindowRectangle( int x, int y,  unsigned int width, unsigned int height )
 
191
{
 
192
    if( _current_render_surface != NULL )
 
193
        _current_render_surface->setWindowRectangle( x, y, width, height );
 
194
}
 
195
 
 
196
void CameraConfig::setRenderSurfaceCustomFullScreenRectangle( int x, int y, unsigned int width, unsigned int height )
 
197
{
 
198
    if( _current_render_surface != NULL )
 
199
        _current_render_surface->setCustomFullScreenRectangle( x, y, width, height );
 
200
}
 
201
 
 
202
void CameraConfig::setRenderSurfaceOverrideRedirect( bool flag )
 
203
{
 
204
    if( _current_render_surface != NULL )
 
205
        _current_render_surface->useOverrideRedirect( flag );
 
206
}
 
207
 
 
208
void CameraConfig::setRenderSurfaceHostName( const std::string &name )
 
209
{
 
210
    if( _current_render_surface != NULL )
 
211
        _current_render_surface->setHostName( name );
 
212
}
 
213
 
 
214
void CameraConfig::setRenderSurfaceDisplayNum( int n )
 
215
{
 
216
    if( _current_render_surface != NULL )
 
217
        _current_render_surface->setDisplayNum( n );
 
218
}
 
219
 
 
220
void CameraConfig::setRenderSurfaceScreen( int n )
 
221
{
 
222
    if( _current_render_surface != NULL )
 
223
        _current_render_surface->setScreenNum( n );
 
224
}
 
225
 
 
226
void CameraConfig::setRenderSurfaceBorder( bool flag )
 
227
{
 
228
    if( _current_render_surface != NULL )
 
229
        _current_render_surface->useBorder( flag );
 
230
}
 
231
 
 
232
void CameraConfig::setRenderSurfaceDrawableType( RenderSurface::DrawableType drawableType )
 
233
{
 
234
    if( _current_render_surface != NULL )
 
235
        _current_render_surface->setDrawableType( drawableType );
 
236
}
 
237
 
 
238
void CameraConfig::setRenderSurfaceRenderToTextureMode( RenderSurface::RenderToTextureMode rttMode )
 
239
{
 
240
    if( _current_render_surface != NULL )
 
241
        _current_render_surface->setRenderToTextureMode( rttMode );
 
242
}
 
243
 
 
244
void CameraConfig::setRenderSurfaceReadDrawable( const char *name )
 
245
{
 
246
    if( _current_render_surface != NULL )
 
247
    {
 
248
        osgProducer::RenderSurface *readDrawable = findRenderSurface( name );
 
249
        if( readDrawable == NULL )
 
250
        {
 
251
            std::cerr << "setRenderSurfaceReadDrawable(): No Render Surface by name of \"" << name << "\" was found!\n";
 
252
            return;
 
253
        }
 
254
        _current_render_surface->setReadDrawable( readDrawable );
 
255
    }
 
256
}
 
257
 
 
258
void CameraConfig::setRenderSurfaceInputRectangle( float x0, float x1, float y0, float y1 )
 
259
{
 
260
    if( _current_render_surface != NULL )
 
261
        _current_render_surface->setInputRectangle( RenderSurface::InputRectangle(x0,x1,y0,y1) );
 
262
}
 
263
 
 
264
void CameraConfig::endRenderSurface( void )
 
265
{
 
266
    _can_add_render_surface_attributes = false;
 
267
}
 
268
 
 
269
RenderSurface *CameraConfig::findRenderSurface( const char *name )
 
270
{
 
271
    std::map<std::string,  osg::ref_ptr<RenderSurface> >::iterator p;
 
272
    p = _render_surface_map.find( std::string(name) );
 
273
    if( p == _render_surface_map.end() )
 
274
        return NULL;
 
275
    else
 
276
        return (*p).second.get();
 
277
}
 
278
 
 
279
unsigned int CameraConfig::getNumberOfRenderSurfaces()
 
280
{
 
281
    return _render_surface_map.size();
 
282
}
 
283
 
 
284
RenderSurface *CameraConfig::getRenderSurface( unsigned int index )
 
285
{
 
286
    if( index >= _render_surface_map.size() ) 
 
287
            return NULL;
 
288
    std::map <std::string,  osg::ref_ptr<RenderSurface> >::iterator p;
 
289
 
 
290
    unsigned int i = 0;
 
291
    for( p = _render_surface_map.begin(); p != _render_surface_map.end(); p++ )
 
292
        if( i++ == index ) 
 
293
                break;
 
294
    if(  p == _render_surface_map.end() )
 
295
            return NULL;
 
296
    return (p->second.get());
 
297
}
 
298
 
 
299
void CameraConfig::addCamera( std::string name, Camera *camera )
 
300
{
 
301
    std::pair<std::map<std::string, osg::ref_ptr<Camera> >::iterator,bool> res =
 
302
      _camera_map.insert(std::pair<std::string, osg::ref_ptr<Camera> >(name, camera));
 
303
    _current_camera = (res.first)->second.get();
 
304
    _can_add_camera_attributes = true;
 
305
 
 
306
    RenderSurface *rs = camera->getRenderSurface();
 
307
    if( rs->getWindowName() == osgProducer::RenderSurface::defaultWindowName )
 
308
    {
 
309
        char name[80];
 
310
        sprintf( name, "%s (%02d)", osgProducer::RenderSurface::defaultWindowName.c_str(), (int)_render_surface_map.size() );
 
311
        rs->setWindowName( name );
 
312
    }
 
313
    _render_surface_map.insert(std::pair<std::string, osg::ref_ptr<RenderSurface> >( rs->getWindowName(), rs ));
 
314
}
 
315
 
 
316
 
 
317
void CameraConfig::beginCamera( std::string name )
 
318
{
 
319
    Camera *camera = new Camera;
 
320
    std::pair<std::map<std::string,  osg::ref_ptr<Camera> >::iterator,bool> res = 
 
321
      _camera_map.insert(std::pair<std::string, osg::ref_ptr<Camera> >(name, camera));
 
322
    _current_camera = (res.first)->second.get();
 
323
    _can_add_camera_attributes = true;
 
324
}
 
325
 
 
326
void CameraConfig::setCameraRenderSurface( const char *name )
 
327
{
 
328
    RenderSurface *rs = findRenderSurface( name );
 
329
    if( rs == NULL )
 
330
    {
 
331
        std::cerr << "setCameraRenderSurface(): No Render Surface by name of \"" << name << "\" was found!\n";
 
332
        return;
 
333
    }
 
334
 
 
335
    if( rs != NULL && _current_camera != NULL )
 
336
        _current_camera->setRenderSurface( rs );
 
337
 
 
338
}
 
339
 
 
340
void CameraConfig::setCameraRenderSurface( void )
 
341
{
 
342
 
 
343
    if( _current_camera != NULL && _current_render_surface != NULL )
 
344
        _current_camera->setRenderSurface( _current_render_surface.get() );
 
345
 
 
346
}
 
347
 
 
348
void CameraConfig::setCameraProjectionRectangle( float x0, float x1, float y0, float y1 )
 
349
{
 
350
    if( _current_camera != NULL )
 
351
        _current_camera->setProjectionRectangle( x0, x1, y0, y1 );
 
352
}
 
353
 
 
354
void CameraConfig::setCameraProjectionRectangle( int x0, int x1, int y0, int y1 )
 
355
{
 
356
    if( _current_camera != NULL )
 
357
        _current_camera->setProjectionRectangle( x0, x1, y0, y1 );
 
358
}
 
359
 
 
360
void CameraConfig::setCameraOrtho( float left, float right, float bottom, float top, float nearClip, float farClip,
 
361
                        float xshear, float yshear )
 
362
{
 
363
    if( _current_camera != NULL )
 
364
        _current_camera->setLensOrtho( left, right, bottom, top, nearClip, farClip, xshear, yshear );
 
365
}
 
366
 
 
367
void CameraConfig::setCameraPerspective( float hfov, float vfov, float nearClip, float farClip,
 
368
                        float xshear, float yshear )
 
369
{
 
370
    if( _current_camera != 0 )
 
371
        _current_camera->setLensPerspective( hfov, vfov, nearClip, farClip, xshear, yshear );
 
372
}
 
373
 
 
374
void CameraConfig::setCameraFrustum( float left, float right, float bottom, float top, float nearClip, float farClip,
 
375
                        float xshear, float yshear )
 
376
{
 
377
    if( _current_camera != 0 )
 
378
        _current_camera->setLensFrustum( left, right, bottom, top, nearClip, farClip, xshear, yshear );
 
379
}
 
380
 
 
381
void CameraConfig::setCameraLensShear( osg::Matrix::value_type xshear, osg::Matrix::value_type yshear )
 
382
{
 
383
    if( _current_camera != NULL )
 
384
        _current_camera->setLensShear(xshear,yshear);
 
385
}
 
386
 
 
387
void CameraConfig::setCameraShareLens( bool shared )
 
388
{
 
389
    if( _current_camera != NULL )
 
390
        _current_camera->setShareLens( shared );
 
391
}
 
392
 
 
393
void CameraConfig::setCameraShareView( bool shared )
 
394
{
 
395
    if( _current_camera != NULL )
 
396
        _current_camera->setShareView( shared );
 
397
}
 
398
 
 
399
void CameraConfig::setCameraClearColor( float r, float g, float b, float a )
 
400
{
 
401
    if( _current_camera != NULL )
 
402
        _current_camera->setClearColor( r, g, b, a );
 
403
}
 
404
 
 
405
void CameraConfig::beginCameraOffset()
 
406
{
 
407
  osg::Matrix::value_type id[] = {
 
408
        1, 0, 0, 0,
 
409
        0, 1, 0, 0,
 
410
        0, 0, 1, 0,
 
411
        0, 0, 0, 1
 
412
        };
 
413
  memcpy( _offset_matrix, id, sizeof(osg::Matrix::value_type[16]));
 
414
    _offset_shearx = _offset_sheary = 0.0;
 
415
}
 
416
 
 
417
void CameraConfig::shearCameraOffset( osg::Matrix::value_type shearx, osg::Matrix::value_type sheary )
 
418
{
 
419
    _offset_shearx = shearx;
 
420
    _offset_sheary = sheary;
 
421
}
 
422
 
 
423
void CameraConfig::setCameraOffsetMultiplyMethod( Camera::Offset::MultiplyMethod method )
 
424
{
 
425
    if( _current_camera != NULL )
 
426
        _current_camera->setOffsetMultiplyMethod(method);
 
427
}
 
428
 
 
429
 
 
430
void CameraConfig::endCameraOffset()
 
431
{
 
432
    if( _current_camera != NULL )
 
433
        _current_camera->setOffset( _offset_matrix, _offset_shearx, _offset_sheary);
 
434
}
 
435
 
 
436
void  CameraConfig::endCamera( void )
 
437
{
 
438
    _can_add_camera_attributes = false;
 
439
}
 
440
 
 
441
Camera *CameraConfig::findCamera( const char *name )
 
442
{
 
443
    std::map<std::string,  osg::ref_ptr<Camera> >::iterator p;
 
444
    p = _camera_map.find( std::string(name) );
 
445
    if( p == _camera_map.end() )
 
446
        return NULL;
 
447
    else
 
448
        return (*p).second.get();
 
449
}
 
450
 
 
451
unsigned int CameraConfig::getNumberOfCameras() const
 
452
{
 
453
    return _camera_map.size();
 
454
}
 
455
 
 
456
const Camera *CameraConfig::getCamera( unsigned int n ) const
 
457
{
 
458
    if( n >= _camera_map.size() ) 
 
459
            return NULL;
 
460
 
 
461
    unsigned int i;
 
462
    std::map <std::string,  osg::ref_ptr<Camera> >::const_iterator p;
 
463
    for( i = 0, p = _camera_map.begin(); p != _camera_map.end(); p++ )
 
464
        if( i++ == n ) 
 
465
                break;
 
466
    if(  p == _camera_map.end() )
 
467
            return NULL;
 
468
    return p->second.get();
 
469
}
 
470
 
 
471
Camera *CameraConfig::getCamera( unsigned int n )
 
472
{
 
473
    if( n >= _camera_map.size() ) 
 
474
            return NULL;
 
475
 
 
476
    unsigned int i;
 
477
    std::map <std::string,  osg::ref_ptr<Camera> >::iterator p;
 
478
    for( i = 0, p = _camera_map.begin(); p != _camera_map.end(); p++ )
 
479
        if( i++ == n ) 
 
480
                break;
 
481
    if(  p == _camera_map.end() )
 
482
            return NULL;
 
483
    return p->second.get();
 
484
}
 
485
 
 
486
void CameraConfig::beginInputArea()
 
487
{
 
488
    _input_area = new InputArea;
 
489
    _can_add_input_area_entries = true;
 
490
}
 
491
 
 
492
void CameraConfig::addInputAreaEntry( char *renderSurfaceName )
 
493
{    
 
494
    osgProducer::RenderSurface *rs = findRenderSurface( renderSurfaceName );
 
495
    if( rs == NULL )
 
496
    {
 
497
        std::cerr << "setInputAreaEntry(): No Render Surface by name of \"" << renderSurfaceName << "\" was found!\n";
 
498
        return;
 
499
    }
 
500
    if( _input_area != NULL && _can_add_input_area_entries == true )
 
501
        _input_area->addRenderSurface( rs );
 
502
}
 
503
 
 
504
void CameraConfig::endInputArea() 
 
505
{
 
506
    _can_add_input_area_entries = false;
 
507
}
 
508
 
 
509
void CameraConfig::setInputArea(InputArea *ia) 
 
510
 
511
    _input_area=ia; 
 
512
}
 
513
 
 
514
InputArea *CameraConfig::getInputArea() 
 
515
 
516
    return _input_area.get(); 
 
517
}
 
518
 
 
519
const InputArea *CameraConfig::getInputArea() const 
 
520
 
521
    return _input_area.get(); 
 
522
}
 
523
 
 
524
#if 0
 
525
void CameraConfig::realize( void )
 
526
{
 
527
    std::map <std::string,  osg::ref_ptr<RenderSurface> >::iterator p;
 
528
    for( p = _render_surface_map.begin(); p != _render_surface_map.end(); p++ )
 
529
    {
 
530
        ((*p).second)->realize();
 
531
    }
 
532
}
 
533
#endif
 
534
 
 
535
std::string findFile( std::string );
 
536
 
 
537
void CameraConfig::addStereoSystemCommand( int screen, std::string stereoCmd, std::string monoCmd )
 
538
{
 
539
    _stereoSystemCommands.push_back(StereoSystemCommand( screen, stereoCmd, monoCmd ));
 
540
}
 
541
 
 
542
const std::vector<CameraConfig::StereoSystemCommand> &CameraConfig::getStereoSystemCommands() 
 
543
 
544
    return _stereoSystemCommands; 
 
545
}
 
546
 
 
547
 
 
548
CameraConfig::~CameraConfig() 
 
549
{
 
550
}
 
551
 
 
552
//////////////////////
 
553
 
 
554
void CameraConfig::rotateCameraOffset( osg::Matrix::value_type deg, osg::Matrix::value_type x, osg::Matrix::value_type y, osg::Matrix::value_type z )
 
555
{
 
556
  osg::Matrix m;
 
557
  m.invert(osg::Matrix::rotate( osg::DegreesToRadians(deg), x,y,z)); 
 
558
  m = m * osg::Matrix(_offset_matrix);
 
559
    memcpy( _offset_matrix, m.ptr(), sizeof( osg::Matrix::value_type[16] ));
 
560
}
 
561
 
 
562
void CameraConfig::translateCameraOffset( osg::Matrix::value_type x, osg::Matrix::value_type y, osg::Matrix::value_type z )
 
563
{
 
564
  osg::Matrix m;
 
565
    m.invert(osg::Matrix::translate( x,y,z)); 
 
566
    m = m * osg::Matrix(_offset_matrix);
 
567
    memcpy( _offset_matrix, m.ptr(), sizeof( osg::Matrix::value_type[16] ));
 
568
}
 
569
 
 
570
void CameraConfig::scaleCameraOffset( osg::Matrix::value_type x, osg::Matrix::value_type y, osg::Matrix::value_type z )
 
571
{
 
572
  osg::Matrix m = osg::Matrix::scale( x,y,z) * osg::Matrix(_offset_matrix);
 
573
  memcpy( _offset_matrix, m.ptr(), sizeof( osg::Matrix::value_type[16] ));
 
574
}
 
575
 
 
576
bool CameraConfig::fileExists(const std::string& filename)
 
577
{
 
578
    return access( filename.c_str(), F_OK ) == 0;
 
579
}
 
580
 
 
581
// Order of precedence:
 
582
//
 
583
std::string CameraConfig::findFile( std::string filename )
 
584
{
 
585
    if (filename.empty()) return filename;
 
586
 
 
587
    std::string path;
 
588
    // Check env var
 
589
    char *ptr = getenv( "PRODUCER_CONFIG_FILE_PATH");
 
590
    if( ptr != NULL )
 
591
    {
 
592
         path = std::string(ptr) + '/' + filename;
 
593
        if( fileExists(path)) 
 
594
            return path;
 
595
    }
 
596
 
 
597
    // Check standard location(s)
 
598
    //path.clear();
 
599
    path = std::string( "/usr/local/share/Producer/Config/") + filename;
 
600
    if( fileExists(path) ) 
 
601
        return path;
 
602
 
 
603
    //path.clear();
 
604
    path = std::string( "/usr/share/Producer/Config/") + filename;
 
605
    if( fileExists(path) ) 
 
606
        return path;
 
607
 
 
608
    // Check local directory
 
609
    if(fileExists(filename)) 
 
610
        return filename;
 
611
 
 
612
    // Fail
 
613
    return std::string();
 
614
}
 
615
 
 
616
bool CameraConfig::defaultConfig()
 
617
{
 
618
    if( getNumberOfCameras() != 0 ) return false;
 
619
 
 
620
    char *env = getenv( "PRODUCER_CAMERA_CONFIG_FILE" );
 
621
 
 
622
    // Backwards compatibility
 
623
    if( env == NULL )
 
624
        env = getenv( "PRODUCER_CONFIG_FILE" );
 
625
 
 
626
    if( env != NULL )
 
627
    {
 
628
        std::string file = findFile(env);
 
629
        return parseFile( file.c_str() );
 
630
    }
 
631
 
 
632
    unsigned int numScreens =  getNumberOfScreens();
 
633
    if( numScreens == 0 )
 
634
        return false;
 
635
 
 
636
    float xshear = float(numScreens-1);
 
637
    float yshear = 0.0;
 
638
    float input_xMin = -1.0f;
 
639
    float input_yMin = -1.0f;
 
640
    float input_width = 2.0f/float(numScreens);
 
641
    float input_height = 2.0f;
 
642
 
 
643
    // use an InputArea if there is more than one screen.
 
644
    InputArea *ia = (numScreens>1) ? new InputArea : 0;
 
645
    setInputArea(ia);
 
646
 
 
647
    for( unsigned int i = 0; i < numScreens; i++ )
 
648
    {
 
649
      std::string name = "Screen" + i;
 
650
      std::pair<std::map<std::string, osg::ref_ptr<Camera> >::iterator,bool> res = 
 
651
      _camera_map.insert(std::pair<std::string, osg::ref_ptr<Camera> >(name, new Camera));
 
652
 
 
653
      ((res.first)->second)->getRenderSurface()->setScreenNum( i );
 
654
      ((res.first)->second)->setLensShear( xshear, yshear );
 
655
 
 
656
       RenderSurface *rs = ((res.first)->second)->getRenderSurface();
 
657
       rs->setWindowName( name );
 
658
       if (ia)
 
659
       {
 
660
           rs->setInputRectangle( RenderSurface::InputRectangle(input_xMin, input_xMin+input_width, input_yMin, input_yMin+input_height) );
 
661
           input_xMin += input_width;
 
662
           ia->addRenderSurface(rs);
 
663
       }
 
664
 
 
665
       _render_surface_map.insert(std::pair<std::string, 
 
666
            osg::ref_ptr<RenderSurface> >( rs->getWindowName(), rs ));
 
667
 
 
668
      xshear -= 2.0;
 
669
    }
 
670
 
 
671
    _threadModelDirective = CameraGroup::getDefaultThreadModel();
 
672
 
 
673
    return true;
 
674
}        
 
675