13.03.2013, 16:25
You could convert from one euler angle sequence to another, rotate the object, convert back to the original sequence and apply the new rotation values to the object. That's how it's done in my object editor - no quaternions used at all. See the following function for example:
pawn Код:
EDIT_ObjectRotateZ(object, Float:rot_z)
{
new
Float:x,
Float:y,
Float:z,
Float:sin[3],
Float:cos[3];
GetObjectRot(object, x, y, z);
EDIT_FloatConvertValue(x, y, z, sin, cos);
// Convert from one euler angle sequence (ZXY) to another and add the rotation
EDIT_FloatConvertValue(asin(cos[0] * cos[1]), atan2(sin[0], cos[0] * sin[1]) + rot_z, atan2(cos[1] * cos[2] * sin[0] - sin[1] * sin[2], cos[2] * sin[1] - cos[1] * sin[0] * -sin[2]), sin, cos);
// Convert back to the original euler angle sequence and apply the new rotation to the object
SetObjectRot(object, asin(cos[0] * sin[1]), atan2(cos[0] * cos[1], sin[0]), atan2(cos[2] * sin[0] * sin[1] - cos[1] * sin[2], cos[1] * cos[2] + sin[0] * sin[1] * sin[2]));
return 1;
}
EDIT_FloatConvertValue(Float:rot_x, Float:rot_y, Float:rot_z, Float:sin[3], Float:cos[3])
{
sin[0] = floatsin(rot_x, degrees);
sin[1] = floatsin(rot_y, degrees);
sin[2] = floatsin(rot_z, degrees);
cos[0] = floatcos(rot_x, degrees);
cos[1] = floatcos(rot_y, degrees);
cos[2] = floatcos(rot_z, degrees);
return 1;
}