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 >
|
2018-03-08 21:23:24 +01:00
|
|
|
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
|
2018-03-08 21:23:24 +01:00
|
|
|
https://www.gnu.org/licenses/ .
|
2010-01-06 15:00:08 +01:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2013-02-24 13:51:56 -08: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>
|
2023-09-13 23:15:14 +03:00
|
|
|
#include <osg/Quat>
|
2015-02-17 17:08:55 +01:00
|
|
|
#include <osg/Vec3f>
|
2012-07-10 02:38:35 -07:00
|
|
|
|
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
|
|
|
|
2015-06-15 02:06:04 +02: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;
|
|
|
|
}
|
2024-04-04 01:30:27 +01:00
|
|
|
|
|
|
|
osg::Matrixf toOsgMatrix() const
|
|
|
|
{
|
|
|
|
osg::Matrixf osgMat;
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; ++i)
|
|
|
|
for (int j = 0; j < 3; ++j)
|
|
|
|
osgMat(i, j) = mValues[j][i]; // NB: column/row major difference
|
|
|
|
|
|
|
|
return osgMat;
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
};
|
|
|
|
|
2023-09-10 01:38:17 +03:00
|
|
|
struct NiTransform
|
2012-03-23 22:15:45 +02:00
|
|
|
{
|
2023-09-10 01:38:17 +03: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;
|
2023-09-10 01:38:17 +03:00
|
|
|
transform.setTrans(mTranslation);
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2015-06-15 02:06:04 +02:00
|
|
|
for (int i = 0; i < 3; ++i)
|
|
|
|
for (int j = 0; j < 3; ++j)
|
2023-09-10 01:38:17 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-09-10 01:38:17 +03:00
|
|
|
bool isIdentity() const { return mRotation.isIdentity() && mTranslation == osg::Vec3f() && mScale == 1.f; }
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2023-09-10 01:38:17 +03:00
|
|
|
static const NiTransform& getIdentity()
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2023-09-10 01:38:17 +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
|
|
|
};
|
|
|
|
|
2023-09-13 23:15:14 +03: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
|