[Plugin] S-ART [place any picture on the map like an object!]
#45

Here is how you can do it.

1.) Find the group center of all objects
2.) Rotate each object with the following function

pawn Код:
// Credits: Stylock
stock AttachPoint(Float:offx, Float:offy, Float:offz, Float:offrx, Float:offry, Float:offrz, Float:px, Float:py, Float:pz, Float:prx, Float:pry, Float:prz, &Float:RetX, &Float:RetY, &Float:RetZ, &Float:RetRX, &Float:RetRY, &Float:RetRZ, sync_rotation = 1)
{
    new
        Float:g_sin[3],
        Float:g_cos[3],
        Float:off_x,
        Float:off_y,
        Float:off_z;

    EDIT_FloatEulerFix(prx, pry, prz);

    off_x = offx - px; // static offset
    off_y = offy - py; // static offset
    off_z = offz - pz; // static offset

    // Calculate the new position
    EDIT_FloatConvertValue(prx, pry, prz, g_sin, g_cos);
    RetX = px + off_x * g_cos[1] * g_cos[2] - off_x * g_sin[0] * g_sin[1] * g_sin[2] - off_y * g_cos[0] * g_sin[2] + off_z * g_sin[1] * g_cos[2] + off_z * g_sin[0] * g_cos[1] * g_sin[2];
    RetY = py + off_x * g_cos[1] * g_sin[2] + off_x * g_sin[0] * g_sin[1] * g_cos[2] + off_y * g_cos[0] * g_cos[2] + off_z * g_sin[1] * g_sin[2] - off_z * g_sin[0] * g_cos[1] * g_cos[2];
    RetZ = pz - off_x * g_cos[0] * g_sin[1] + off_y * g_sin[0] + off_z * g_cos[0] * g_cos[1];

    if (sync_rotation)
    {
        // Calculate the new rotation
        EDIT_FloatConvertValue(asin(g_cos[0] * g_cos[1]), atan2(g_sin[0], g_cos[0] * g_sin[1]) + offrz, atan2(g_cos[1] * g_cos[2] * g_sin[0] - g_sin[1] * g_sin[2], g_cos[2] * g_sin[1] - g_cos[1] * g_sin[0] * -g_sin[2]), g_sin, g_cos);
        EDIT_FloatConvertValue(asin(g_cos[0] * g_sin[1]), atan2(g_cos[0] * g_cos[1], g_sin[0]), atan2(g_cos[2] * g_sin[0] * g_sin[1] - g_cos[1] * g_sin[2], g_cos[1] * g_cos[2] + g_sin[0] * g_sin[1] * g_sin[2]), g_sin, g_cos);
        EDIT_FloatConvertValue(atan2(g_sin[0], g_cos[0] * g_cos[1]) + offrx, asin(g_cos[0] * g_sin[1]), atan2(g_cos[2] * g_sin[0] * g_sin[1] + g_cos[1] * g_sin[2], g_cos[1] * g_cos[2] - g_sin[0] * g_sin[1] * g_sin[2]), g_sin, g_cos);

        RetRX = asin(g_cos[1] * g_sin[0]);
        RetRY = atan2(g_sin[1], g_cos[0] * g_cos[1]) + offry;
        RetRZ = atan2(g_cos[0] * g_sin[2] - g_cos[2] * g_sin[0] * g_sin[1], g_cos[0] * g_cos[2] + g_sin[0] * g_sin[1] * g_sin[2]);
    }
}





stock 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;
}

/*
 * Fixes a bug that causes objects to not rotate
 * correctly when rotating on the Z axis only.
 */

stock EDIT_FloatEulerFix(&Float:rot_x, &Float:rot_y, &Float:rot_z)
{
    EDIT_FloatGetRemainder(rot_x, rot_y, rot_z);
    if((!floatcmp(rot_x, 0.0) || !floatcmp(rot_x, 360.0))
    && (!floatcmp(rot_y, 0.0) || !floatcmp(rot_y, 360.0)))
    {
        rot_y = 0.00000002;
    }
    return 1;
}

stock EDIT_FloatGetRemainder(&Float:rot_x, &Float:rot_y, &Float:rot_z)
{
    EDIT_FloatRemainder(rot_x, 360.0);
    EDIT_FloatRemainder(rot_y, 360.0);
    EDIT_FloatRemainder(rot_z, 360.0);
    return 1;
}

stock EDIT_FloatRemainder(&Float:remainder, Float:value)
{
    if(remainder >= value)
    {
        while(remainder >= value)
        {
            remainder = remainder - value;
        }
    }
    else if(remainder < 0.0)
    {
        while(remainder < 0.0)
        {
            remainder = remainder + value;
        }
    }
    return 1;
}
You should be able to convert that code to work in c++ for your plugin fairly easily.
Reply


Messages In This Thread
S-ART [place any picture on the map like an object!] - by DialUp - 01.01.2015, 23:24
Re: S-ART [place any picture on the map like an object!] - by Abagail - 01.01.2015, 23:31
Re: S-ART [place any picture on the map like an object!] - by Madzior_ - 01.01.2015, 23:32
Respuesta: S-ART [place any picture on the map like an object!] - by The_Scope - 02.01.2015, 00:18
Re: S-ART [place any picture on the map like an object!] - by Diabloa - 02.01.2015, 01:01
Re: S-ART [place any picture on the map like an object!] - by $$inSane - 02.01.2015, 05:25
Re: S-ART [place any picture on the map like an object!] - by DialUp - 02.01.2015, 05:32
Re: S-ART [place any picture on the map like an object!] - by $$inSane - 02.01.2015, 05:42
Re: S-ART [place any picture on the map like an object!] - by DialUp - 02.01.2015, 05:54
Re: S-ART [place any picture on the map like an object!] - by Tamer - 02.01.2015, 09:25
Re: S-ART [place any picture on the map like an object!] - by muzammilfreeman - 02.01.2015, 09:31
Re: S-ART [place any picture on the map like an object!] - by Lordzy - 02.01.2015, 09:52
Re: S-ART [place any picture on the map like an object!] - by Daewoo - 02.01.2015, 09:55
Re: S-ART [place any picture on the map like an object!] - by N.K.Stallone - 02.01.2015, 10:22
Re: S-ART [place any picture on the map like an object!] - by RaeF - 02.01.2015, 10:36
Respuesta: S-ART [place any picture on the map like an object!] - by Zume - 02.01.2015, 11:16
Re: S-ART [place any picture on the map like an object!] - by iWhite - 02.01.2015, 12:36
Re: S-ART [place any picture on the map like an object!] - by n0minal - 02.01.2015, 12:52
Re: S-ART [place any picture on the map like an object!] - by iWhite - 02.01.2015, 13:59
Re: S-ART [place any picture on the map like an object!] - by n0minal - 02.01.2015, 14:06
Re: S-ART [place any picture on the map like an object!] - by DialUp - 02.01.2015, 14:07
Re: S-ART [place any picture on the map like an object!] - by n0minal - 02.01.2015, 14:15
Re: S-ART [place any picture on the map like an object!] - by DialUp - 02.01.2015, 14:17
Re: S-ART [place any picture on the map like an object!] - by DialUp - 02.01.2015, 15:31
Re: S-ART [place any picture on the map like an object!] - by n0minal - 02.01.2015, 16:35
Re: S-ART [place any picture on the map like an object!] - by DialUp - 02.01.2015, 16:44
Re: S-ART [place any picture on the map like an object!] - by Dampyr - 02.01.2015, 17:06
Re: S-ART [place any picture on the map like an object!] - by DialUp - 02.01.2015, 17:09
Re: S-ART [place any picture on the map like an object!] - by iWhite - 03.01.2015, 09:50
Re: S-ART [place any picture on the map like an object!] - by DialUp - 03.01.2015, 14:40
Re: S-ART [place any picture on the map like an object!] - by Pottus - 04.01.2015, 18:12
Re: S-ART [place any picture on the map like an object!] - by DialUp - 04.01.2015, 18:25
Re: S-ART [place any picture on the map like an object!] - by Pottus - 04.01.2015, 18:32
Re: S-ART [place any picture on the map like an object!] - by DialUp - 04.01.2015, 18:40
Re: S-ART [place any picture on the map like an object!] - by Pottus - 04.01.2015, 18:50
Re: S-ART [place any picture on the map like an object!] - by DialUp - 04.01.2015, 18:59
Respuesta: S-ART [place any picture on the map like an object!] - by JustBored - 04.01.2015, 19:04
Re: S-ART [place any picture on the map like an object!] - by Pottus - 04.01.2015, 19:06
Re: Respuesta: S-ART [place any picture on the map like an object!] - by DialUp - 04.01.2015, 19:22
Respuesta: S-ART [place any picture on the map like an object!] - by JustBored - 04.01.2015, 19:33
Re: S-ART [place any picture on the map like an object!] - by Crayder - 04.01.2015, 19:47
Re: Respuesta: S-ART [place any picture on the map like an object!] - by DialUp - 04.01.2015, 19:57
Re: S-ART [place any picture on the map like an object!] - by Pottus - 04.01.2015, 20:08
Re: S-ART [place any picture on the map like an object!] - by DialUp - 04.01.2015, 20:20
Re: S-ART [place any picture on the map like an object!] - by Pottus - 04.01.2015, 23:25
Re: S-ART [place any picture on the map like an object!] - by DialUp - 04.01.2015, 23:36
Re: S-ART [place any picture on the map like an object!] - by Pottus - 04.01.2015, 23:45
Respuesta: S-ART [place any picture on the map like an object!] - by JustBored - 05.01.2015, 00:22
Re: Respuesta: S-ART [place any picture on the map like an object!] - by DialUp - 05.01.2015, 00:25
Respuesta: S-ART [place any picture on the map like an object!] - by JustBored - 05.01.2015, 03:03
Re: S-ART [place any picture on the map like an object!] - by Maximun - 10.01.2015, 12:25
Re: S-ART [place any picture on the map like an object!] - by SDraw - 10.01.2015, 18:20
Re: S-ART [place any picture on the map like an object!] - by DialUp - 11.01.2015, 18:25
Re: S-ART [place any picture on the map like an object!] - by Redirect Left - 11.01.2015, 18:31
Re: S-ART [place any picture on the map like an object!] - by TiW - 12.01.2015, 13:11
Re: S-ART [place any picture on the map like an object!] - by SDraw - 12.01.2015, 15:44
Re: S-ART [place any picture on the map like an object!] - by bigboy81 - 13.01.2015, 00:50
Re: S-ART [place any picture on the map like an object!] - by Vinnyy - 13.01.2015, 04:29
Re: S-ART [place any picture on the map like an object!] - by DialUp - 13.01.2015, 19:48
Respuesta: S-ART [place any picture on the map like an object!] - by kgbayala528 - 17.01.2015, 00:47
Re: S-ART [place any picture on the map like an object!] - by MP_Spec - 23.01.2015, 22:00
Re: S-ART [place any picture on the map like an object!] - by hideintherain - 05.02.2015, 11:19
Re: S-ART [place any picture on the map like an object!] - by Crayder - 05.02.2015, 11:49
Re: S-ART [place any picture on the map like an object!] - by hideintherain - 05.02.2015, 17:27
Re: S-ART [place any picture on the map like an object!] - by hideintherain - 06.02.2015, 15:20
Re: S-ART [place any picture on the map like an object!] - by Greaper - 09.05.2015, 12:05
Re: S-ART [place any picture on the map like an object!] - by KrYpToDeN - 10.07.2015, 05:48
Re: S-ART [place any picture on the map like an object!] - by dusk - 10.07.2015, 09:30
Re: S-ART [place any picture on the map like an object!] - by McOwens - 13.07.2015, 21:03
Re: S-ART [place any picture on the map like an object!] - by Stanford - 19.07.2015, 13:58
Re: S-ART [place any picture on the map like an object!] - by mirzakovacic - 23.03.2016, 21:53
Re: S-ART [place any picture on the map like an object!] - by Mowgli - 27.02.2017, 09:48
Re: S-ART [place any picture on the map like an object!] - by iLearner - 27.02.2017, 10:03

Forum Jump:


Users browsing this thread: 2 Guest(s)