1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 15:49:56 +00:00
openmw-tes3mp/components/nifosg/matrixtransform.cpp
Capostrophic 46825e8a4d Move NIF record index back to a separate user object
This makes sure it's never erroneously optimized out. NodeIndexHolders don't need to be cloned as their record index is never supposed to be changed.
2020-07-26 09:57:43 +03:00

56 lines
1.5 KiB
C++

#include "matrixtransform.hpp"
namespace NifOsg
{
MatrixTransform::MatrixTransform()
: osg::MatrixTransform()
{
}
MatrixTransform::MatrixTransform(const Nif::Transformation &trafo)
: osg::MatrixTransform(trafo.toMatrix())
, mScale(trafo.scale)
, mRotationScale(trafo.rotation)
{
}
MatrixTransform::MatrixTransform(const MatrixTransform &copy, const osg::CopyOp &copyop)
: osg::MatrixTransform(copy, copyop)
, mScale(copy.mScale)
, mRotationScale(copy.mRotationScale)
{
}
void MatrixTransform::applyCurrentRotation()
{
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
_matrix(j,i) = mRotationScale.mValues[i][j]; // NB column/row major difference
}
void MatrixTransform::applyCurrentScale()
{
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
_matrix(i,j) *= mScale;
}
void MatrixTransform::updateRotation(const osg::Quat& rotation)
{
_matrix.setRotate(rotation);
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
mRotationScale.mValues[i][j] = _matrix(j,i); // NB column/row major difference
}
void MatrixTransform::updateScale(const float scale)
{
mScale = scale;
applyCurrentScale();
}
void MatrixTransform::setTranslation(const osg::Vec3f& translation)
{
_matrix.setTrans(translation);
}
}