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

« back to all changes in this revision

Viewing changes to OpenSceneGraph/src/osgGA/UFOManipulator.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
1
#include <osgGA/UFOManipulator>
2
2
#include <osgUtil/IntersectVisitor>
3
3
 
 
4
#include <osg/io_utils>
 
5
 
4
6
#ifndef M_PI
5
7
# define M_PI       3.14159265358979323846  /* pi */
6
8
#endif
74
76
    _position.set( _inverseMatrix(3,0), _inverseMatrix(3,1), _inverseMatrix(3,2 ));
75
77
    osg::Matrix R(_inverseMatrix);
76
78
    R(3,0) = R(3,1) = R(3,2) = 0.0;
77
 
    _direction = osg::Vec3(0,0,-1) * R; // yep.
 
79
    _direction = osg::Vec3(0,0,-1) * R; // camera up is +Z, regardless of CoordinateFrame
78
80
 
79
81
    _stop();
80
82
}
87
89
    _position.set( _inverseMatrix(3,0), _inverseMatrix(3,1), _inverseMatrix(3,2 ));
88
90
    osg::Matrix R(_inverseMatrix);
89
91
    R(3,0) = R(3,1) = R(3,2) = 0.0;
90
 
    _direction = osg::Vec3(0,0,-1) * R; // yep.
 
92
    _direction = osg::Vec3(0,0,-1) * R; // camera up is +Z, regardless of CoordinateFrame
91
93
 
92
94
    _stop();
93
95
}
116
118
    osgUtil::IntersectVisitor iv;
117
119
    iv.setTraversalMask(_intersectTraversalMask);
118
120
 
 
121
    osg::CoordinateFrame cf( getCoordinateFrame(bs.center()) ); // not sure what position to use here
 
122
    osg::Vec3d upVec( getUpVector(cf) );
119
123
    osg::ref_ptr<osg::LineSegment> seg = new osg::LineSegment;
120
 
    osg::Vec3 A = bs.center() + (osg::Vec3(0,0,1)*(bs.radius()*2));
121
 
    osg::Vec3 B = bs.center() + (osg::Vec3(0,0,-1)*(bs.radius()*2));
 
124
    osg::Vec3 A = bs.center() + (upVec*(bs.radius()*2));
 
125
    osg::Vec3 B = bs.center() + (-upVec*(bs.radius()*2));
122
126
 
123
127
    if( (B-A).length() == 0.0)
124
128
    {
126
130
    }
127
131
 
128
132
    /*
129
 
    seg->set( bs.center() + (osg::Vec3(0,0,1)*(bs.radius()*2)), 
130
 
              bs.center() + (osg::Vec3(0,0,-1)*(bs.radius()*2)) );
 
133
    seg->set( bs.center() + (upVec*(bs.radius()*2)), 
 
134
              bs.center() + (-upVec*(bs.radius()*2)) );
131
135
              */
132
136
    seg->set( A, B );
133
137
 
141
145
    {
142
146
        osgUtil::IntersectVisitor::HitList& hitList = iv.getHitList(seg.get());
143
147
        osg::Vec3d ip = hitList.front().getWorldIntersectPoint();
144
 
        if( fabs(ip[2]) < ground )
145
 
            ground = ip[2];
 
148
        double d = ip.length();
 
149
        if( d < ground )
 
150
            ground = d;
146
151
    }
147
152
    else
148
153
    {
151
156
    }
152
157
 
153
158
 
154
 
    osg::Vec3 p(bs.center()[0], bs.center()[1], ground + (_minHeightAboveGround*1.25) );
155
 
    setHomePosition( p, p + osg::Vec3(0,1,0), osg::Vec3(0,0,1) );
 
159
    osg::Vec3 p(bs.center() + upVec*( ground + _minHeightAboveGround*1.25 ) );
 
160
    setHomePosition( p, p + getFrontVector(cf), upVec );
156
161
}
157
162
 
158
163
void UFOManipulator::init(const GUIEventAdapter&, GUIActionAdapter&)
410
415
            home(ea.getTime());
411
416
            break;
412
417
    }
 
418
 
413
419
}
414
420
 
415
421
void UFOManipulator::_frame( const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter & )
426
432
        _t0 = t1;
427
433
    }
428
434
 
 
435
    osg::CoordinateFrame cf( getCoordinateFrame(_position) );
 
436
    osg::Vec3d upVec( getUpVector(cf) );
429
437
    if( fabs( _directionRotationRate ) > _directionRotationEpsilon )
430
438
    {
431
 
        _direction = _direction * osg::Matrix::rotate( _directionRotationRate, osg::Vec3(0,0,1));
 
439
      _direction = _direction * osg::Matrix::rotate( _directionRotationRate, upVec);
432
440
    }
433
441
 
434
442
    {
435
 
        osg::Vec3 _sideVec = _direction * osg::Matrix::rotate( -M_PI*0.5, osg::Vec3(0,0,1));
 
443
      osg::Vec3 _sideVec = _direction * osg::Matrix::rotate( -M_PI*0.5, upVec);
436
444
 
437
445
        _position += ((_direction       * _forwardSpeed) + 
438
446
                      (_sideVec         * _sideSpeed) +
439
 
                      (osg::Vec3(0,0,1) * _upSpeed))
 
447
                      (upVec * _upSpeed))
440
448
                       * _dt;
 
449
 
441
450
    }
442
451
 
443
452
    _pitchOffset += _pitchOffsetRate * _dt;
448
457
    if( _yawOffset >= M_PI || _yawOffset < -M_PI ) 
449
458
        _yawOffset *= -1;
450
459
 
451
 
    _offset       = osg::Matrix::rotate( _yawOffset, osg::Vec3(0,1,0),
452
 
                                         _pitchOffset, osg::Vec3(1,0,0),
453
 
                                         0.0, osg::Vec3(0,0,1));
 
460
    _offset       = osg::Matrix::rotate( _yawOffset, getSideVector(cf),
 
461
                                         _pitchOffset, getFrontVector(cf),
 
462
                                         0.0, upVec);
454
463
 
455
464
    _adjustPosition();
456
465
 
457
 
    _inverseMatrix.makeLookAt( _position, _position + _direction, osg::Vec3(0,0,1)); 
 
466
    _inverseMatrix.makeLookAt( _position, _position + _direction, upVec); 
458
467
    _matrix.invert(_inverseMatrix);
459
468
 
460
469
    if( _decelerateUpSideRate )
511
520
 
512
521
 
513
522
    // Down line segment at 3 times our intersect distance
 
523
    osg::CoordinateFrame cf( getCoordinateFrame(_position) );
 
524
    osg::Vec3d upVec( getUpVector(cf) );
514
525
    osg::ref_ptr<osg::LineSegment> segDown = new osg::LineSegment;
515
526
    segDown->set(   _position, 
516
 
                    _position - (osg::Vec3(0,0, _minHeightAboveGround*3)));
 
527
                    _position - upVec*_minHeightAboveGround*3);
517
528
    iv.addLineSegment( segDown.get() );
518
529
 
519
530
    _node->accept(iv);
543
554
            if (!hitList.empty())
544
555
            {
545
556
                osg::Vec3d ip = hitList.front().getWorldIntersectPoint();
546
 
                if( _position[2] - ip[2] < _minHeightAboveGround )
547
 
                    _position[2] = ip[2] + _minHeightAboveGround;
 
557
                double d = (ip - _position).length();
 
558
            
 
559
                if( d < _minHeightAboveGround )
 
560
                  _position = ip + (upVec * _minHeightAboveGround);
548
561
            }
549
562
        }
550
563
 
564
577
{
565
578
    eye = _position;
566
579
    center = _position + _direction;
567
 
    up.set( 0, 0, 1 );
 
580
    up.set(getUpVector(getCoordinateFrame(_position)));
568
581
}
569
582