28.10.2011, 18:47
(
Последний раз редактировалось Stylock; 02.11.2011 в 14:56.
)
OK, it took me a while to calculate all this, but some people might find this function insanely useful.
pawn Код:
/*
GetAttachedObjectPos
objectid - the objectid to which the attached object is attached to. (not the attached objectid)
Float:offset_x - the distance between the main object and the attached object in the X direction.
Float:offset_y - the distance between the main object and the attached object in the Y direction.
Float:offset_z - the distance between the main object and the attached object in the Z direction.
Float:x - the variable to store the X coordinate, passed by reference.
Float:y - the variable to store the Y coordinate, passed by reference.
Float:z - the variable to store the Z coordinate, passed by reference.
*/
stock GetAttachedObjectPos(objectid, Float:offset_x, Float:offset_y, Float:offset_z, &Float:x, &Float:y, &Float:z)
{
new Float:object_px,
Float:object_py,
Float:object_pz,
Float:object_rx,
Float:object_ry,
Float:object_rz;
GetObjectPos(objectid, object_px, object_py, object_pz);
GetObjectRot(objectid, object_rx, object_ry, object_rz);
new Float:cos_x = floatcos(object_rx, degrees),
Float:cos_y = floatcos(object_ry, degrees),
Float:cos_z = floatcos(object_rz, degrees),
Float:sin_x = floatsin(object_rx, degrees),
Float:sin_y = floatsin(object_ry, degrees),
Float:sin_z = floatsin(object_rz, degrees);
x = object_px + offset_x * cos_y * cos_z - offset_x * sin_x * sin_y * sin_z - offset_y * cos_x * sin_z + offset_z * sin_y * cos_z + offset_z * sin_x * cos_y * sin_z;
y = object_py + offset_x * cos_y * sin_z + offset_x * sin_x * sin_y * cos_z + offset_y * cos_x * cos_z + offset_z * sin_y * sin_z - offset_z * sin_x * cos_y * cos_z;
z = object_pz - offset_x * cos_x * sin_y + offset_y * sin_x + offset_z * cos_x * cos_y;
}