25 #include "glm/gtc/type_ptr.hpp" 26 #include "glm/gtc/matrix_transform.hpp" 77 const std::vector<ModelNode *> &modelNodeMap) {
110 NodeMap::iterator n =
nodeMap.find(node);
114 return n->second->_nodedata;
118 NodeMap::const_iterator n =
nodeMap.find(node);
122 return n->second->_nodedata;
131 float x2,
float y2,
float z2,
float q2) {
133 return x1 * x2 + y1 * y2 + z1 * z2 + q1 * q2;
138 float &xOut,
float &yOut,
float &zOut,
float &qOut) {
140 const float magnitude = sqrt(
dotQuaternion(xIn, yIn, zIn, qIn, xIn, yIn, zIn, qIn));
142 xOut = xIn / magnitude;
143 yOut = yIn / magnitude;
144 zOut = zIn / magnitude;
145 qOut = qIn / magnitude;
149 bool relative)
const {
164 (dy + pos.
y) * scale,
165 (dz + pos.
z) * scale);
169 size_t lastFrame = 0;
172 if (pos.
time >= time)
181 (dy + last.
y) * scale,
182 (dz + last.
z) * scale);
188 const float f = (time - last.
time) / (next.
time - last.
time);
189 const float x = f * next.
x + (1.0f - f) * last.
x;
190 const float y = f * next.
y + (1.0f - f) * last.
y;
191 const float z = f * next.
z + (1.0f - f) * last.
z;
206 size_t lastFrame = 0;
209 if (ori.
time >= time)
223 const float f = (time - last.
time) / (next.
time - last.
time);
227 const float angle = acos(
dotQuaternion(last.
x, last.
y, last.
z, last.
q, next.
x, next.
y, next.
z, next.
q));
228 const float dir = (angle >= (
M_PI / 2)) ? -1.0f : 1.0f;
230 float x = f * dir * next.
x + (1.0f - f) * last.
x;
231 float y = f * dir * next.
y + (1.0f - f) * last.
y;
232 float z = f * dir * next.
z + (1.0f - f) * last.
z;
233 float q = f * dir * next.
q + (1.0f - f) * last.
q;
241 static void multiply(
const float *v,
const glm::mat4 &m,
float *rv) {
242 rv[0] = v[0] * m[0][0] + v[1] * m[1][0] + v[2] * m[2][0] + m[3][0];
243 rv[1] = v[0] * m[0][1] + v[1] * m[1][1] + v[2] * m[2][1] + m[3][1];
244 rv[2] = v[0] * m[0][2] + v[1] * m[1][2] + v[2] * m[2][2] + m[3][2];
245 float w = v[0] * m[0][3] + v[1] * m[1][3] + v[2] * m[2][3] + m[3][3];
252 const std::list<ModelNode *> &nodes = model->
getNodes();
253 for (std::list<ModelNode *>::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
273 int index =
static_cast<int>(skin->
boneMapping[i]);
275 skin->
boneNodeMap[index]->computeAbsoluteTransform();
285 vcb.resize(3 * vertexCount);
292 for (
uint32 i = 0; i < vertexCount; ++i) {
296 for (
uint8 j = 0; j < 4; ++j) {
297 int index =
static_cast<int>(boneMappingId[j]);
301 const glm::mat4 &invBindPose = skin->
boneNodeMap[index]->_invBindPose;
302 const glm::mat4 &boneTransform = skin->
boneNodeMap[index]->_absoluteTransform;
309 v[0] += tv[0] * boneWeights[j];
310 v[1] += tv[1] * boneWeights[j];
311 v[2] += tv[2] * boneWeights[j];
323 for (std::map<Common::UString, Model *>::iterator m = model->
_attachedModels.begin();
325 Model *attachedModel = m->second;
void setBufferedPosition(float x, float y, float z)
A node within an animation.
Common::UString _name
The model's name.
std::vector< float > boneMapping
const Common::UString & getName() const
Get the animation's name.
The global graphics manager.
void updateSkinnedModel(Model *model)
Transform vertices for each node of the specified model based on current animation.
A class holding an UTF-8 string.
void update(Model *model, float lastFrame, float nextFrame, const std::vector< ModelNode *> &modelNodeMap)
Update the model position and orientation.
void setLength(float length)
uint32 getCount() const
Get vertex count.
An animation to be applied to a model.
VertexBuffer * getVertexBuffer()
Utility functions for debug output.
std::vector< float > boneWeights
std::map< Common::UString, Model * > _attachedModels
void setBufferedOrientation(float x, float y, float z, float angle)
glm::mat4 _invBindPose
Inverse bind pose matrix used for animations.
float getAnimationScale(const Common::UString &anim)
Determine what animation scaling applies.
std::vector< ModelNode * > boneNodeMap
static void multiply(const float *v, const glm::mat4 &m, float *rv)
static void normQuaternion(float xIn, float yIn, float zIn, float qIn, float &xOut, float &yOut, float &zOut, float &qOut)
Normalize a quaternion.
std::vector< float > initialVertexCoords
Initial node vertex coordinates.
void setTransTime(float transtime)
bool _vertexCoordsBuffered
"GGraphics", global, non-engine graphics.
void interpolatePosition(ModelNode *animNode, ModelNode *target, float time, float scale, bool relative) const
const std::list< AnimNode * > & getNodes() const
Get all animation nodes.
A node within a 3D model.
ModelNode * getNode(const Common::UString &node)
Get the specified node.
const std::list< ModelNode * > & getNodes()
Get all nodes in the current state.
Buffer containing vertex data.
std::vector< QuaternionKeyFrame > _orientationFrames
Keyframes for orientation animation.
void interpolateOrientation(ModelNode *animNode, ModelNode *target, float time) const
Basic reading stream interfaces.
std::vector< float > boneMappingId
static float dotQuaternion(float x1, float y1, float z1, float q1, float x2, float y2, float z2, float q2)
Return the dot product of two quaternions.
Graphics::Mesh::Mesh * rawMesh
Node raw mesh data.
Common::UString _name
The node's name.
NodeMap nodeMap
The nodes within the state, indexed by name.
static glm::mat4 inverse(const glm::mat4 &m)
float getLength() const
Get the animations length.
void setName(Common::UString &name)
bool hasNode(const Common::UString &node) const
Does the specified node exist?
const Common::UString & getName() const
Get the node's name.
std::vector< float > _vertexCoordsBuffer
void addAnimNode(AnimNode *node)
static float rad2deg(float rad)
std::vector< PositionKeyFrame > _positionFrames
Keyframes for position animation.
ModelNode * _parent
The node's parent.
int stricmp(const UString &str) const
NodeList nodeList
The nodes within the state.