OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
niftypes.hpp
Go to the documentation of this file.
1 /*
2  OpenMW - The completely unofficial reimplementation of Morrowind
3  Copyright (C) 2008-2010 Nicolay Korslund
4  Email: < korslund@gmail.com >
5  WWW: http://openmw.sourceforge.net/
6 
7  This file (nif_types.h) is part of the OpenMW package.
8 
9  OpenMW is distributed as free software: you can redistribute it
10  and/or modify it under the terms of the GNU General Public License
11  version 3, as published by the Free Software Foundation.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  version 3 along with this program. If not, see
20  http://www.gnu.org/licenses/ .
21 
22  */
23 
24 #ifndef OPENMW_COMPONENTS_NIF_NIFTYPES_HPP
25 #define OPENMW_COMPONENTS_NIF_NIFTYPES_HPP
26 
27 #include <osg/Vec3f>
28 #include <osg/Matrixf>
29 
30 // Common types used in NIF files
31 
32 namespace Nif
33 {
34 
35 struct Matrix3
36 {
37  float mValues[3][3];
38 
40  {
41  for (int i=0;i<3;++i)
42  for (int j=0;j<3;++j)
43  mValues[i][j] = (i==j) ? 1.f : 0.f;
44  }
45 
46  bool isIdentity() const
47  {
48  for (int i=0;i<3;++i)
49  for (int j=0;j<3;++j)
50  if ((i==j) != (mValues[i][j] == 1))
51  return false;
52  return true;
53  }
54 };
55 
57 {
58  osg::Vec3f pos;
59  Matrix3 rotation; // this can contain scale components too, including negative and nonuniform scales
60  float scale;
61 
62  osg::Matrixf toMatrix() const
63  {
64  osg::Matrixf transform;
65  transform.setTrans(pos);
66 
67  for (int i=0;i<3;++i)
68  for (int j=0;j<3;++j)
69  transform(j,i) = rotation.mValues[i][j] * scale; // NB column/row major difference
70 
71  return transform;
72  }
73 
74  bool isIdentity() const
75  {
76  return pos == osg::Vec3f(0,0,0)
77  && rotation.isIdentity() && scale == 1.f;
78  }
79 
80  static const Transformation& getIdentity()
81  {
82  static const Transformation identity = {
83  osg::Vec3f(), Matrix3(), 1.0f
84  };
85  return identity;
86  }
87 };
88 
89 } // Namespace
90 #endif
float mValues[3][3]
Definition: niftypes.hpp:37
Matrix3()
Definition: niftypes.hpp:39
bool isIdentity() const
Definition: niftypes.hpp:74
float scale
Definition: niftypes.hpp:60
Definition: niftypes.hpp:56
bool isIdentity() const
Definition: niftypes.hpp:46
osg::Vec3f pos
Definition: niftypes.hpp:58
Matrix3 rotation
Definition: niftypes.hpp:59
static const Transformation & getIdentity()
Definition: niftypes.hpp:80
Definition: niftypes.hpp:35
osg::Matrixf toMatrix() const
Definition: niftypes.hpp:62