Skip to content
This repository has been archived by the owner on Sep 8, 2024. 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
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ void Head::Joint::orientTowards(bool entering, const Math::Vector3d &point, floa
float pitchStep = step / 3.0f; float pitchStep = step / 3.0f;
float rollStep = 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; ModelNode *p = _node;
while (p->_parent) { while (p->_parent) {
p = p->_parent; p = p->_parent;
p->_needsUpdate = true;
} }
p->setMatrix(matrix); p->setMatrix(matrix);
p->update(); p->update();
Expand Down
2 changes: 2 additions & 0 deletions engines/grim/costume/head.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class Head {
float _maxPitch; float _maxPitch;
float _maxYaw; float _maxYaw;


ModelNode *_rootNode;

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


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


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


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

_needsUpdate = false;
} }


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


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

0 comments on commit 4fb4e0c

Please sign in to comment.