|
|
(from megasrc07.zip)
I have just had a little peek into that c-file
and found that it might be possible to do some
simplifications of the code within it.
So here's my suggestion:
Replace this:
(27 multiplications and 18 additions/subtractions)
#ifdef AxisRotFixPatch
void Compute_Axis_Rotation_Transform (TRANSFORM *transform, VECTOR
AxisVect, DBL angle)
{
DBL cosx, sinx;
VECTOR V1;
VNormalize(V1, AxisVect);
#else
void Compute_Axis_Rotation_Transform (TRANSFORM *transform, VECTOR V1,
DBL angle)
{
DBL l, cosx, sinx;
VLength(l, V1);
VInverseScaleEq(V1, l);
#endif
MIdentity(transform->matrix);
cosx = cos(angle);
sinx = sin(angle);
transform->matrix[0][0] = V1[X] * V1[X] + cosx * (1.0 - V1[X] *
V1[X]);
transform->matrix[0][1] = V1[X] * V1[Y] * (1.0 - cosx) + V1[Z] * sinx;
transform->matrix[0][2] = V1[X] * V1[Z] * (1.0 - cosx) - V1[Y] * sinx;
transform->matrix[1][0] = V1[X] * V1[Y] * (1.0 - cosx) - V1[Z] * sinx;
transform->matrix[1][1] = V1[Y] * V1[Y] + cosx * (1.0 - V1[Y] *
V1[Y]);
transform->matrix[1][2] = V1[Y] * V1[Z] * (1.0 - cosx) + V1[X] * sinx;
transform->matrix[2][0] = V1[X] * V1[Z] * (1.0 - cosx) + V1[Y] * sinx;
transform->matrix[2][1] = V1[Y] * V1[Z] * (1.0 - cosx) - V1[X] * sinx;
transform->matrix[2][2] = V1[Z] * V1[Z] + cosx * (1.0 - V1[Z] *
V1[Z]);
MTranspose(transform->inverse, transform->matrix);
}
With this:
(24 multiplications and 10 additions/subtractions)
#ifdef AxisRotFixPatch
void Compute_Axis_Rotation_Transform (TRANSFORM *transform, VECTOR
AxisVect, DBL angle)
{
DBL cosx, sinx, omc;
VECTOR V1;
VNormalize(V1, AxisVect);
#else
void Compute_Axis_Rotation_Transform (TRANSFORM *transform, VECTOR V1,
DBL angle)
{
DBL l, cosx, sinx, omc;
VLength(l, V1);
VInverseScaleEq(V1, l);
#endif
MIdentity(transform->matrix);
cosx = cos(angle);
sinx = sin(angle);
omc = 1.0 - cosx;
transform->matrix[0][0] = V1[X] * V1[X] * omc + cosx;
transform->matrix[0][1] = V1[X] * V1[Y] * omc + V1[Z] * sinx;
transform->matrix[0][2] = V1[X] * V1[Z] * omc - V1[Y] * sinx;
transform->matrix[1][0] = V1[X] * V1[Y] * omc - V1[Z] * sinx;
transform->matrix[1][1] = V1[Y] * V1[Y] * omc + cosx;
transform->matrix[1][2] = V1[Y] * V1[Z] * omc + V1[X] * sinx;
transform->matrix[2][0] = V1[X] * V1[Z] * omc + V1[Y] * sinx;
transform->matrix[2][1] = V1[Y] * V1[Z] * omc - V1[X] * sinx;
transform->matrix[2][2] = V1[Z] * V1[Z] * omc + cosx;
MTranspose(transform->inverse, transform->matrix);
}
This introduces one extra local variable; omc,
but I hope there will be a little speed gain anyway.
Tor Olav
Post a reply to this message
|
|