2014-10-28 07:12:36 +00:00
|
|
|
#include "nifstream.hpp"
|
|
|
|
// For error reporting
|
|
|
|
#include "niffile.hpp"
|
|
|
|
|
|
|
|
namespace Nif
|
|
|
|
{
|
2018-07-10 09:32:52 +00:00
|
|
|
osg::Quat NIFStream::getQuaternion()
|
|
|
|
{
|
|
|
|
float f[4];
|
2021-05-04 20:58:01 +00:00
|
|
|
readLittleEndianBufferOfType<4, float>(inp, f);
|
2018-07-10 09:32:52 +00:00
|
|
|
osg::Quat quat;
|
|
|
|
quat.w() = f[0];
|
|
|
|
quat.x() = f[1];
|
|
|
|
quat.y() = f[2];
|
|
|
|
quat.z() = f[3];
|
|
|
|
return quat;
|
|
|
|
}
|
2014-10-28 07:12:36 +00:00
|
|
|
|
2018-07-10 09:32:52 +00:00
|
|
|
Transformation NIFStream::getTrafo()
|
|
|
|
{
|
|
|
|
Transformation t;
|
|
|
|
t.pos = getVector3();
|
|
|
|
t.rotation = getMatrix3();
|
|
|
|
t.scale = getFloat();
|
|
|
|
return t;
|
|
|
|
}
|
2019-12-29 12:53:44 +00:00
|
|
|
|
2020-10-03 22:27:49 +00:00
|
|
|
/// Booleans in 4.0.0.2 (Morrowind format) and earlier are 4 byte, while in 4.1.0.0+ they're 1 byte.
|
2019-12-29 12:53:44 +00:00
|
|
|
bool NIFStream::getBoolean()
|
|
|
|
{
|
2020-10-03 22:27:49 +00:00
|
|
|
return getVersion() < generateVersion(4, 1, 0, 0) ? getInt() != 0 : getChar() != 0;
|
2019-12-29 12:53:44 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 22:27:49 +00:00
|
|
|
/// Read in a string, either from the string table using the index or from the stream using the specified length
|
2019-12-29 12:53:44 +00:00
|
|
|
std::string NIFStream::getString()
|
|
|
|
{
|
2022-09-17 17:24:42 +00:00
|
|
|
return getVersion() < generateVersion(20, 1, 0, 1) ? getSizedString() : file.getString(getUInt());
|
2019-12-29 12:53:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convenience utility functions: get the versions of the currently read file
|
2020-02-02 15:40:11 +00:00
|
|
|
unsigned int NIFStream::getVersion() const
|
|
|
|
{
|
2022-09-17 17:24:42 +00:00
|
|
|
return file.getVersion();
|
2020-02-02 15:40:11 +00:00
|
|
|
}
|
|
|
|
unsigned int NIFStream::getUserVersion() const
|
|
|
|
{
|
2022-09-17 17:24:42 +00:00
|
|
|
return file.getBethVersion();
|
2020-02-02 15:40:11 +00:00
|
|
|
}
|
|
|
|
unsigned int NIFStream::getBethVersion() const
|
|
|
|
{
|
2022-09-17 17:24:42 +00:00
|
|
|
return file.getBethVersion();
|
2020-02-02 15:40:11 +00:00
|
|
|
}
|
2014-10-28 07:12:36 +00:00
|
|
|
}
|