Have made osg::Transform more extensible via additions of new getLocalToWorldMatrix()
and getWorldToLocalMatrix(), computeLocalToWorld() and computeWorldToLocal() methods. Have updated the CullVisitor, IntersectVisitor and Optimizer to use the new osg::Transform::getLocalToWorldMatrix() which has the same functionality as the old getMatrix() but is now supports subclasses of osg::Transform transparently. Have added osg::PositionAttitudeTransform as subclass of osg::Transform which manages the transform as position and attitude via a Vec3 and Quat respectively.
This commit is contained in:
43
src/osg/PositionAttitudeTransform.cpp
Normal file
43
src/osg/PositionAttitudeTransform.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <osg/PositionAttitudeTransform>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
PositionAttitudeTransform::PositionAttitudeTransform()
|
||||
{
|
||||
}
|
||||
|
||||
void PositionAttitudeTransform::computeLocalToWorld() const
|
||||
{
|
||||
if (_localToWorldDirty)
|
||||
{
|
||||
if (_mode==MODEL)
|
||||
{
|
||||
_localToWorld->makeRotate(_attitude);
|
||||
_localToWorld->setTrans(_position);
|
||||
}
|
||||
else
|
||||
{
|
||||
_localToWorld->makeTranslate(-_position);
|
||||
_localToWorld->postMult(osg::Matrix::rotate(_attitude.inverse()));
|
||||
}
|
||||
_localToWorldDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
void PositionAttitudeTransform::computeWorldToLocal() const
|
||||
{
|
||||
if (_worldToLocalDirty)
|
||||
{
|
||||
if (_mode==MODEL)
|
||||
{
|
||||
_worldToLocal->makeTranslate(-_position);
|
||||
_worldToLocal->postMult(osg::Matrix::rotate(_attitude.inverse()));
|
||||
}
|
||||
else
|
||||
{
|
||||
_worldToLocal->makeRotate(_attitude);
|
||||
_worldToLocal->setTrans(_position);
|
||||
}
|
||||
_worldToLocalDirty = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user