Bubba-3D  0.9.0
Awesome game engine!
BoneTransformer.h
1 /*
2  * This file is part of Bubba-3D.
3  *
4  * Bubba-3D is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Bubba-3D is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with Bubba-3D. If not, see http://www.gnu.org/licenses/.
16  */
17 #pragma once
18 
19 
20 #include <string>
21 #include <vector>
22 #include <assimp/scene.h>
23 #include <map>
24 #include <BoneMatrices.h>
25 #include <assimp/Importer.hpp>
26 #include "linmath/float3.h"
27 #include "AABB2.h"
28 #include "assimp/material.h"
29 
47 
48 public:
49  BoneTransformer() = default;
50  BoneTransformer(aiScene *aiScene);
51 
59  std::vector<chag::float4x4> calculateBoneTransforms(float totalElapsedTimeInSeconds);
60 
67  int createBoneIndexIfAbsent(const aiBone *bone);
68 
69 
70 private:
74  double getCurrentAnimationTick(float totalElapsedTimeInSeconds) const;
75 
80  void readNodeHierarchyAndUpdateBoneTransformations(float currentAnimationTick, aiNode *currentAssimpNode,
81  chag::float4x4 parentMatrix);
82 
86  void updateBoneTransformation(const std::string &nodeName, const chag::float4x4 &globalTransformation);
87 
91  bool nodeIsABone(const std::string &nodeName) const;
92 
93  chag::float4x4 getCurrentNodeTransformation(float currentAnimationTick, const aiNode *currentAssimpNode,
94  const std::string nodeName);
95 
96 
104  chag::float4x4 getInterpolatedAnimationMatrix(float currentAnimationTick, const aiNodeAnim *nodeAnimation);
105 
107 
114  chag::float4x4 getInterpolatedTranslationMatrix(float currentAnimationTick, const aiNodeAnim *nodeAnimation);
115  chag::float4x4 getInterpolatedRotationMatrix(float currentAnimationTick, const aiNodeAnim *nodeAnimation);
116  chag::float4x4 getInterpolatedScalingMatrix(float currentAnimationTick, const aiNodeAnim *nodeAnimation);
118 
122  const aiNodeAnim *getAnimationNode(const std::string &nodeName);
123 
127  const aiNodeAnim* findNodeAnim(const aiAnimation* animation, const std::string nodeName);
128 
130 
137  aiVector3D calculateScalingInterpolation(float currentAnimationTick, const aiNodeAnim *nodeAnimation);
138  aiQuaternion calculateRotationInterpolation(float currentAnimationTick, const aiNodeAnim *nodeAnimation);
139  aiVector3D calculateTranslationInterpolation(float currentAnimationTick, const aiNodeAnim *nodeAnimation);
141 
143 
150  unsigned int findScalingIndexRightBeforeTick(float currentAnimationTick, const aiNodeAnim *nodeAnimation);
151  unsigned int findRotationIndexRightBeforeTick(float currentAnimationTick, const aiNodeAnim *nodeAnimation);
152  unsigned int findTranslationIndexRightBeforeTick(float currentAnimationTick, const aiNodeAnim *nodeAnimation);
154 
155  //Matrix for transforming FROM bone space TO world space
156  chag::float4x4 globalInverseTransform;
157  std::map<std::string, int> boneNameToIndexMapping;
158  std::vector<BoneMatrices*> boneInfos;
159  const aiScene *assimpScene;
160  int numberOfBones;
161 };
162 
163 
std::vector< chag::float4x4 > calculateBoneTransforms(float totalElapsedTimeInSeconds)
int createBoneIndexIfAbsent(const aiBone *bone)