1
0
Fork 0

Added rotation animations, and a factor parameter for scaling.

This commit is contained in:
david 2002-02-26 14:30:04 +00:00
parent fe7fbdf532
commit 8f1d2f7bc9
2 changed files with 30 additions and 2 deletions

View file

@ -182,6 +182,13 @@ FGAircraftModel::read_animation (const SGPropertyNode * node)
if (type_name == "spin") { if (type_name == "spin") {
SG_LOG(SG_INPUT, SG_INFO, "Reading spin animation"); SG_LOG(SG_INPUT, SG_INFO, "Reading spin animation");
animation.type = Animation::Spin; animation.type = Animation::Spin;
} else if (type_name == "rotate") {
SG_LOG(SG_INPUT, SG_INFO, "Reading rotate animation");
animation.type = Animation::Rotate;
} else if (type_name == "none") {
SG_LOG(SG_INPUT, SG_INFO, "Reading disabled animation");
animation.type = Animation::None;
return animation;
} else { } else {
animation.type = Animation::None; animation.type = Animation::None;
SG_LOG(SG_INPUT, SG_ALERT, "Unknown animation type " << type_name); SG_LOG(SG_INPUT, SG_ALERT, "Unknown animation type " << type_name);
@ -213,6 +220,9 @@ FGAircraftModel::read_animation (const SGPropertyNode * node)
animation.prop = animation.prop =
fgGetNode(node->getStringValue("property", "/null"), true); fgGetNode(node->getStringValue("property", "/null"), true);
animation.position = node->getFloatValue("initial-position", 0);
animation.factor = node->getFloatValue("factor", 1);
// Get the center and axis // Get the center and axis
animation.center_x = node->getFloatValue("center/x-m", 0); animation.center_x = node->getFloatValue("center/x-m", 0);
animation.center_y = node->getFloatValue("center/y-m", 0); animation.center_y = node->getFloatValue("center/y-m", 0);
@ -231,7 +241,8 @@ FGAircraftModel::do_animation (Animation &animation, long elapsed_ms)
case Animation::None: case Animation::None:
return; return;
case Animation::Spin: { case Animation::Spin: {
float velocity_rpms = animation.prop->getDoubleValue() / 60000.0; float velocity_rpms = animation.prop->getDoubleValue()
* animation.factor / 60000.0;
animation.position += (elapsed_ms * velocity_rpms * 360); animation.position += (elapsed_ms * velocity_rpms * 360);
while (animation.position >= 360) while (animation.position >= 360)
animation.position -= 360; animation.position -= 360;
@ -248,6 +259,21 @@ FGAircraftModel::do_animation (Animation &animation, long elapsed_ms)
animation.transform->setTransform(animation.matrix); animation.transform->setTransform(animation.matrix);
return; return;
} }
case Animation::Rotate: {
animation.position = animation.prop->getFloatValue() * animation.factor;
sgMakeTransMat4(animation.matrix, -animation.center_x,
-animation.center_y, -animation.center_z);
sgVec3 axis;
sgSetVec3(axis, animation.axis_x, animation.axis_y, animation.axis_z);
sgMat4 tmp;
sgMakeRotMat4(tmp, animation.position, axis);
sgPostMultMat4(animation.matrix, tmp);
sgMakeTransMat4(tmp, animation.center_x,
animation.center_y, animation.center_z);
sgPostMultMat4(animation.matrix, tmp);
animation.transform->setTransform(animation.matrix);
return;
}
default: default:
return; return;
} }

View file

@ -38,13 +38,15 @@ private:
{ {
enum Type { enum Type {
None, None,
Spin Spin,
Rotate
}; };
string name; string name;
Type type; Type type;
ssgTransform * transform; ssgTransform * transform;
sgMat4 matrix; sgMat4 matrix;
SGPropertyNode * prop; SGPropertyNode * prop;
float factor;
float position; float position;
float center_x; float center_x;
float center_y; float center_y;