openmw/components/nif/niftypes.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

111 lines
3 KiB
C++
Raw Normal View History

2010-01-06 15:00:08 +01:00
/*
OpenMW - The completely unofficial reimplementation of Morrowind
Copyright (C) 2008-2010 Nicolay Korslund
Email: < korslund@gmail.com >
WWW: https://openmw.org/
2010-01-06 15:00:08 +01:00
This file (nif_types.h) is part of the OpenMW package.
OpenMW is distributed as free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License
version 3, as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
version 3 along with this program. If not, see
https://www.gnu.org/licenses/ .
2010-01-06 15:00:08 +01:00
*/
#ifndef OPENMW_COMPONENTS_NIF_NIFTYPES_HPP
#define OPENMW_COMPONENTS_NIF_NIFTYPES_HPP
2010-01-06 15:00:08 +01:00
2015-05-07 21:17:15 +02:00
#include <osg/Matrixf>
#include <osg/Quat>
2015-02-17 17:08:55 +01:00
#include <osg/Vec3f>
2010-01-06 15:00:08 +01:00
// Common types used in NIF files
namespace Nif
{
struct Matrix3
2015-05-07 21:17:15 +02:00
{
float mValues[3][3];
2022-09-22 21:26:05 +03:00
2015-05-07 21:17:15 +02:00
Matrix3()
2022-09-22 21:26:05 +03:00
{
2015-05-07 21:17:15 +02:00
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
mValues[i][j] = (i == j) ? 1.f : 0.f;
}
2022-09-22 21:26:05 +03:00
bool isIdentity() const
{
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
if ((i == j) != (mValues[i][j] == 1))
return false;
return true;
}
2022-09-22 21:26:05 +03:00
};
struct NiTransform
2012-03-23 22:15:45 +02:00
{
Matrix3 mRotation; // this can contain scale components too, including negative and nonuniform scales
osg::Vec3f mTranslation;
float mScale;
2022-09-22 21:26:05 +03:00
2015-05-07 21:17:15 +02:00
osg::Matrixf toMatrix() const
2022-09-22 21:26:05 +03:00
{
2015-05-07 21:17:15 +02:00
osg::Matrixf transform;
transform.setTrans(mTranslation);
2022-09-22 21:26:05 +03:00
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
transform(j, i) = mRotation.mValues[i][j] * mScale; // NB column/row major difference
2022-09-22 21:26:05 +03:00
2015-05-07 21:17:15 +02:00
return transform;
2022-09-22 21:26:05 +03:00
}
bool isIdentity() const { return mRotation.isIdentity() && mTranslation == osg::Vec3f() && mScale == 1.f; }
2022-09-22 21:26:05 +03:00
static const NiTransform& getIdentity()
2022-09-22 21:26:05 +03:00
{
static const NiTransform identity = { Matrix3(), osg::Vec3f(), 1.0f };
2012-07-09 21:35:36 -07:00
return identity;
2012-03-23 22:15:45 +02:00
}
2010-01-06 15:00:08 +01:00
};
struct NiQuatTransform
{
osg::Vec3f mTranslation;
osg::Quat mRotation;
float mScale;
osg::Matrixf toMatrix() const
{
osg::Matrixf transform(mRotation);
transform.setTrans(mTranslation);
for (int i = 0; i < 3; i++)
transform(i, i) *= mScale;
return transform;
}
bool isIdentity() const { return mTranslation == osg::Vec3f() && mRotation == osg::Quat() && mScale == 1.f; }
static const NiQuatTransform& getIdentity()
{
static const NiQuatTransform identity = { osg::Vec3f(), osg::Quat(), 1.f };
return identity;
}
};
2010-01-06 15:00:08 +01:00
} // Namespace
#endif