Nice addition
No need for an 'expensive' derivation
of the rotation matrix though as you can
straight forwardly write it out all at once
========
model.hxx
========
class FGAircraftModel : public FGSubsystem
{
.....
struct Animation
{
enum Type {
None,
Spin,
Rotate
};
string name;
Type type;
ssgTransform * transform;
SGPropertyNode * prop;
float factor;
float position;
sgVec3 center;
sgVec3 axis;
void setRotation();
};
....
};
========
model.cxx
========
FGAircraftModel::read_animation (const SGPropertyNode * node)
{
...........
// Get the center and axis
animation.center[0] = node->getFloatValue("center/x-m", 0);
animation.center[1] = node->getFloatValue("center/y-m", 0);
animation.center[2] = node->getFloatValue("center/z-m", 0);
animation.axis[0] = node->getFloatValue("axis/x", 0);
animation.axis[1] = node->getFloatValue("axis/y", 1);
animation.axis[2] = node->getFloatValue("axis/z", 0);
sgNormalizeVec3( animation.axis );
return animation;
}
void
FGAircraftModel::do_animation (Animation &animation, long elapsed_ms)
{
switch (animation.type)
{
case Animation::None:
return;
case Animation::Spin:
{
float velocity_rpms =
animation.prop->getDoubleValue() * animation.factor / 60000.0;
animation.position += (elapsed_ms * velocity_rpms * 360);
animation.setRotation();
return;
}
case Animation::Rotate:
{
animation.position =
animation.prop->getFloatValue() * animation.factor;
animation.setRotation();
return;
}
default:
return;
}
}
/* Transform to rotate an object around its local axis
* from a relative frame of reference at center -- NHV
*/
void
FGAircraftModel::Animation::setRotation()
{
float temp_angle = -position * SG_DEGREES_TO_RADIANS ;
float s = (float) sin ( temp_angle ) ;
float c = (float) cos ( temp_angle ) ;
float t = SG_ONE - c ;
// axis was normalized at load time
// hint to the compiler to put these into FP registers
float x = axis[0];
float y = axis[1];
float z = axis[2];
sgMat4 matrix;
matrix[0][0] = t * x * x + c ;
matrix[0][1] = t * y * x - s * z ;
matrix[0][2] = t * z * x + s * y ;
matrix[0][3] = SG_ZERO;
matrix[1][0] = t * x * y + s * z ;
matrix[1][1] = t * y * y + c ;
matrix[1][2] = t * z * y - s * x ;
matrix[1][3] = SG_ZERO;
matrix[2][0] = t * x * z - s * y ;
matrix[2][1] = t * y * z + s * x ;
matrix[2][2] = t * z * z + c ;
matrix[2][3] = SG_ZERO;
// hint to the compiler to put these into FP registers
x = center[0];
y = center[1];
z = center[2];
matrix[3][0] = x - x*matrix[0][0] - y*matrix[1][0] - z*matrix[2][0];
matrix[3][1] = y - x*matrix[0][1] - y*matrix[1][1] - z*matrix[2][1];
matrix[3][2] = z - x*matrix[0][2] - y*matrix[1][2] - z*matrix[2][2];
matrix[3][3] = SG_ONE;
transform->setTransform(matrix);
}
// end of model.cxx
_______________________________________________
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel