new Float:North[3], Float:South[3], Float:East[3], Float:West[3], Float:RXAngle, Float:RYAngle, Float:opposite, Float:hypotenuse; // Set slope positions North[0] = objects[ox]; North[1] = objects[oy] + 1; South[0] = objects[ox]; South[1] = objects[oy] - 1; East[0] = objects[ox] + 1; East[1] = objects[oy]; West[0] = objects[ox] - 1; West[1] = objects[oy]; // Use map andreas to get Z Values MapAndreas_FindZ_For2DCoord(North[0], North[1], North[2]); MapAndreas_FindZ_For2DCoord(South[0], South[1], South[2]); MapAndreas_FindZ_For2DCoord(East[0], East[1], East[2]); MapAndreas_FindZ_For2DCoord(West[0], West[1], West[2]); // Calculate Slope angles // North South RX hypotenuse = getdist3d(North[0], North[1], North[2], South[0], South[1], South[2]); opposite = getdist3d(North[0], North[1], North[2], North[0], North[1], South[2]); RXAngle = asin(floatdiv(opposite, hypotenuse)); if(South[2] > North[2]) RXAngle *= -1; // West East RY hypotenuse = getdist3d(West[0], West[1], West[2], East[0], East[1], East[2]); opposite = getdist3d(West[0], West[1], West[2], West[0], West[1], East[2]); RYAngle = asin(floatdiv(opposite, hypotenuse)); if(East[2] > West[2]) RYAngle *= -1; // Set object rotation objects[rx] = RXAngle; objects[ry] = RYAngle; SetObjectRot(objects[object_id], objects[rx], objects[ry], objects[rz]);
Quaternions (and I can't help you more than that as I don't know them).
|
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;
}
stock ObjectRotateZ(Float:RX, Float:RY, Float:RZ, Float:rot_z, &Float:NewRX, &Float:NewRY, &Float:NewRZ) { new Float:sinx, Float:siny, Float:sinz, Float:cosx, Float:cosy, Float:cosz; FloatConvertValue(RX, RY, RZ, sinx, siny, sinz, cosx, cosy, cosz); // Convert from one euler angle sequence (ZXY) to another and add the rotation FloatConvertValue(asin(cosx * cosy), atan2(sinx, cosx * siny) + rot_z, atan2(cosy * cosz * sinx - siny * sinz, cosz * siny - cosy * sinx * -sinz), sinx, siny, sinz, cosx, cosy, cosz); // Convert back to the original euler angle sequence and apply the new rotation to the object NewRX = asin(cosx * siny), NewRY = atan2(cosx * cosy, sinx), NewRZ = atan2(cosz * sinx * siny - cosy * sinz, cosy * cosz + sinx * siny * sinz); return 1; } stock FloatConvertValue(Float:rot_x, Float:rot_y, Float:rot_z, &Float:sinx, &Float:siny, &Float:sinz, &Float:cosx, &Float:cosy, &Float:cosz) { sinx = floatsin(rot_x, degrees); siny = floatsin(rot_y, degrees); sinz = floatsin(rot_z, degrees); cosx = floatcos(rot_x, degrees); cosy = floatcos(rot_y, degrees); cosz = floatcos(rot_z, degrees); return 1; }