Skip to content

Commit

Permalink
GRAPHICS: Apply animation scaling to node positions
Browse files Browse the repository at this point in the history
  • Loading branch information
jbowtie authored and DrMcCoy committed Apr 27, 2012
1 parent 70c5db4 commit 2dc6ef8
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/graphics/aurora/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ void Animation::update(Model *model, float lastFrame, float nextFrame) {
//TODO: also need to fire off associated events
//for event in _events event->fire()


float scale = model->getAnimationScale(_name);
if(scale != 1.0f)
status("Anim %s has scale %f in model %s", _name.c_str(), scale, model->getName().c_str());
for (NodeList::iterator n = nodeList.begin();
n != nodeList.end(); ++n) {
(*n)->update(model, lastFrame, nextFrame);
(*n)->update(model, lastFrame, nextFrame, scale);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/graphics/aurora/animnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const Common::UString &AnimNode::getName() const {
return _name;
}

void AnimNode::update(Model *model, float lastFrame, float nextFrame) {
void AnimNode::update(Model *model, float lastFrame, float nextFrame, float scale) {
if(!_nodedata)
return;
//determine the corresponding keyframes
Expand All @@ -77,7 +77,7 @@ void AnimNode::update(Model *model, float lastFrame, float nextFrame) {
_nodedata->interpolateOrientation(nextFrame, oX, oY, oZ, oA);
ModelNode *target = model->getNode(_name);
if(target) {
target->setPosition(curX, curY, curZ);
target->setPosition(curX * scale, curY * scale, curZ * scale);
target->setOrientation(oX, oY, oZ, oA);
}
//update the position/orientation of corresponding modelnode
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/aurora/animnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class AnimNode {
const Common::UString &getName() const;

/** Update the model properties interpolating between frames */
void update(Model *model, float lastFrame, float nextFrame);
void update(Model *model, float lastFrame, float nextFrame, float scale);
protected:
// Animation *_animation; ///< The animation this node belongs to.

Expand Down
17 changes: 17 additions & 0 deletions src/graphics/aurora/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Model::Model(ModelType type) : Renderable((RenderableType) type),
_rotation[0] = 0.0; _rotation[1] = 0.0; _rotation[2] = 0.0;

_modelScale[0] = 1.0; _modelScale[1] = 1.0; _modelScale[2] = 1.0;
//TODO: is this the same as modelScale for non-UI?
_animationScale = 1.0;
}

Model::~Model() {
Expand Down Expand Up @@ -368,6 +370,21 @@ Animation *Model::getAnimation(const Common::UString &anim) {
return n->second;
}

float Model::getAnimationScale(const Common::UString &anim) {
//TODO: we can cache this for performance
AnimationMap::iterator n = _animationMap.find(anim);
if (n == _animationMap.end()) {
//animation scaling only applies to inherited animations
if(_supermodel)
return _animationScale * _supermodel->getAnimationScale(anim);
//can't find it, return sensible default
return 1.0f;
}

//we found it, don't scale further
return 1.0f;
}

void Model::calculateDistance() {
if (_type == kModelTypeGUIFront) {
_distance = _position[2];
Expand Down
3 changes: 3 additions & 0 deletions src/graphics/aurora/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class Model : public GLContainer, public Renderable {
void populateDefaultAnimations();
/** select the default idle animation */
void selectDefaultAnimation();
/** determine what animation scaling applies */
float getAnimationScale(const Common::UString &anim);

// Renderable
void calculateDistance();
Expand Down Expand Up @@ -180,6 +182,7 @@ class Model : public GLContainer, public Renderable {
AnimationList _defaultAnimations;
Animation *_currentAnimation;
Animation *_nextAnimation;
float _animationScale;

float _modelScale[3]; ///< The model's scale.

Expand Down
2 changes: 1 addition & 1 deletion src/graphics/aurora/model_nwn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void Model_NWN::loadBinary(ParserContext &ctx) {

float radius = ctx.mdl->readIEEEFloatLE();

float scale = ctx.mdl->readIEEEFloatLE();
_animationScale = ctx.mdl->readIEEEFloatLE();

_superModelName.readFixedASCII(*ctx.mdl, 64);

Expand Down
6 changes: 2 additions & 4 deletions src/graphics/aurora/modelnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ void ModelNode::interpolatePosition(float time, float &x, float &y, float &z) co
return;
}

int lastFrame = 0;
uint32 lastFrame = 0;
for(uint32 i = 0; i < _positionFrames.size(); i++) {
PositionKeyFrame pos = _positionFrames[i];
if(pos.time < time)
Expand All @@ -531,8 +531,6 @@ void ModelNode::interpolatePosition(float time, float &x, float &y, float &z) co
x = f * next.x + (1.0f - f) * last.x;
y = f * next.y + (1.0f - f) * last.y;
z = f * next.z + (1.0f - f) * last.z;
// f = (t - last.t)/(next.t - last.t)
// v = f * next + (1-f) * last
}

void ModelNode::interpolateOrientation(float time, float &x, float &y, float &z, float& a) const {
Expand All @@ -543,7 +541,7 @@ void ModelNode::interpolateOrientation(float time, float &x, float &y, float &z,
return;
}

int lastFrame = 0;
uint32 lastFrame = 0;
for(uint32 i = 0; i < _orientationFrames.size(); i++) {
QuaternionKeyFrame pos = _orientationFrames[i];
if(pos.time < time)
Expand Down

0 comments on commit 2dc6ef8

Please sign in to comment.