MatrixTransform 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #ifndef OSG_MATRIXTRANSFORM
  14. #define OSG_MATRIXTRANSFORM 1
  15. #include <osg/Transform>
  16. namespace osg {
  17. /** MatrixTransform - is a subclass of Transform which has an osg::Matrix
  18. * which represents a 4x4 transformation of its children from local coordinates
  19. * into the Transform's parent coordinates.
  20. */
  21. class OSG_EXPORT MatrixTransform : public Transform
  22. {
  23. public :
  24. MatrixTransform();
  25. /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
  26. MatrixTransform(const MatrixTransform&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
  27. MatrixTransform(const Matrix& matix);
  28. META_Node(osg, MatrixTransform);
  29. virtual MatrixTransform* asMatrixTransform() { return this; }
  30. virtual const MatrixTransform* asMatrixTransform() const { return this; }
  31. /** Set the transform's matrix.*/
  32. void setMatrix(const Matrix& mat) { _matrix = mat; _inverseDirty=true; dirtyBound(); }
  33. /** Get the matrix. */
  34. inline const Matrix& getMatrix() const { return _matrix; }
  35. /** pre multiply the transform's matrix.*/
  36. void preMult(const Matrix& mat) { _matrix.preMult(mat); _inverseDirty=true; dirtyBound(); }
  37. /** post multiply the transform's matrix.*/
  38. void postMult(const Matrix& mat) { _matrix.postMult(mat); _inverseDirty=true; dirtyBound(); }
  39. /** Get the inverse matrix. */
  40. inline const Matrix& getInverseMatrix() const
  41. {
  42. if (_inverseDirty)
  43. {
  44. _inverse.invert(_matrix);
  45. _inverseDirty = false;
  46. }
  47. return _inverse;
  48. }
  49. virtual bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const;
  50. virtual bool computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor*) const;
  51. protected :
  52. virtual ~MatrixTransform();
  53. Matrix _matrix;
  54. mutable Matrix _inverse;
  55. mutable bool _inverseDirty;
  56. };
  57. }
  58. #endif