root/OpenSceneGraph/trunk/src/osg/PositionAttitudeTransform.cpp @ 13041

Revision 13041, 2.0 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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#include <osg/PositionAttitudeTransform>
14
15using namespace osg;
16
17PositionAttitudeTransform::PositionAttitudeTransform():
18    _scale(1.0,1.0,1.0)
19{
20}
21
22bool PositionAttitudeTransform::computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const
23{
24    if (_referenceFrame==RELATIVE_RF)
25    {
26        matrix.preMultTranslate(_position);
27        matrix.preMultRotate(_attitude);
28        matrix.preMultScale(_scale);
29        matrix.preMultTranslate(-_pivotPoint);
30    }
31    else // absolute
32    {
33        matrix.makeRotate(_attitude);
34        matrix.postMultTranslate(_position);
35        matrix.preMultScale(_scale);
36        matrix.preMultTranslate(-_pivotPoint);
37    }
38    return true;
39}
40
41
42bool PositionAttitudeTransform::computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor*) const
43{
44    if (_scale.x() == 0.0 || _scale.y() == 0.0 || _scale.z() == 0.0)
45        return false;
46
47    if (_referenceFrame==RELATIVE_RF)
48    {
49        matrix.postMultTranslate(-_position);
50        matrix.postMultRotate(_attitude.inverse());
51        matrix.postMultScale(Vec3d(1.0/_scale.x(), 1.0/_scale.y(), 1.0/_scale.z()));
52        matrix.postMultTranslate(_pivotPoint);
53    }
54    else // absolute
55    {
56        matrix.makeRotate(_attitude.inverse());
57        matrix.preMultTranslate(-_position);
58        matrix.postMultScale(Vec3d(1.0/_scale.x(), 1.0/_scale.y(), 1.0/_scale.z()));
59        matrix.postMultTranslate(_pivotPoint);
60    }
61    return true;
62}
Note: See TracBrowser for help on using the browser.