Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Commit

Permalink
GRIM: Only compute the world transform matrices for the joint node an…
Browse files Browse the repository at this point in the history
…d its parents, not for every node of the character.
  • Loading branch information
Akz- committed Apr 8, 2012
1 parent 8530edd commit 4fb4e0c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion engines/grim/costume/head.cpp
Expand Up @@ -41,10 +41,12 @@ void Head::Joint::orientTowards(bool entering, const Math::Vector3d &point, floa
float pitchStep = step / 3.0f;
float rollStep = step / 3.0f;

// Make sure we have up-to-date world transform matrices computed for every bone node of this character.
// Make sure we have up-to-date world transform matrices computed for the joint nodes of this character.
_node->_needsUpdate = true;
ModelNode *p = _node;
while (p->_parent) {
p = p->_parent;
p->_needsUpdate = true;
}
p->setMatrix(matrix);
p->update();
Expand Down
2 changes: 2 additions & 0 deletions engines/grim/costume/head.h
Expand Up @@ -71,6 +71,8 @@ class Head {
float _maxPitch;
float _maxYaw;

ModelNode *_rootNode;

// Specifies the three head joint bones of this character.
// These joint bones are animated by the moveHead function to make
// the characters face different directions.
Expand Down
2 changes: 2 additions & 0 deletions engines/grim/lua_v1_actor.cpp
Expand Up @@ -646,9 +646,11 @@ void Lua_V1::GetActorNodeLocation() {
ModelNode *allNodes = actor->getCurrentCostume()->getModelNodes();
ModelNode *node = allNodes + nodeId;

node->_needsUpdate = true;
ModelNode *root = node;
while (root->_parent) {
root = root->_parent;
root->_needsUpdate = true;
}

Math::Matrix4 matrix;
Expand Down
4 changes: 3 additions & 1 deletion engines/grim/model.cpp
Expand Up @@ -709,7 +709,7 @@ void ModelNode::update() {
if (!_initialized)
return;

if (_hierVisible) {
if (_hierVisible && _needsUpdate) {
Math::Vector3d animPos = _pos + _animPos;
Math::Angle animPitch = _pitch + _animPitch;
Math::Angle animYaw = _yaw + _animYaw;
Expand All @@ -731,6 +731,8 @@ void ModelNode::update() {
_child->setMatrix(_matrix);
_child->update();
}

_needsUpdate = false;
}

if (_sibling) {
Expand Down
3 changes: 2 additions & 1 deletion engines/grim/model.h
Expand Up @@ -143,7 +143,7 @@ class Mesh {

class ModelNode {
public:
ModelNode() : _initialized(false) { }
ModelNode() : _initialized(false), _needsUpdate(true) { }
~ModelNode();
void loadBinary(Common::SeekableReadStream *data, ModelNode *hierNodes, const Model::Geoset *g);
void draw() const;
Expand Down Expand Up @@ -181,6 +181,7 @@ class ModelNode {
Math::Angle _animPitch, _animYaw, _animRoll;
bool _meshVisible, _hierVisible;
bool _initialized;
bool _needsUpdate;
Math::Matrix4 _matrix;
Math::Matrix4 _localMatrix;
Math::Matrix4 _pivotMatrix;
Expand Down

0 comments on commit 4fb4e0c

Please sign in to comment.