Log in to reply



    I have this class where I don't want to use natives, so I'm trying to re-implement this. Brain says no though.

    I thought it should be possible with a few Vector3's:

    • base position in world coords
    • base rotation
    • offset position in world coords

    I can't figure it out though. Can anybody help?

    Edit - Never mind. I took ScriptHookVDotNet's Camera::GetOffsetInWorldCoords and adapted it for my own, and it seems to work:

        Vector3 GetOffsetInWorldCoords(Vector3 baseP, Vector3 rotation, Vector3 direction, Vector3 offset)
            Vector3 forward = direction;
            const double d2R = 0.01745329251994329576923690768489;
            double num1 = System.Math.Cos(rotation.Y * d2R);
            double x = num1 * System.Math.Cos(-rotation.Z * d2R);
            double y = num1 * System.Math.Sin(rotation.Z * d2R);
            double z = System.Math.Sin(-rotation.Y * d2R);
            Vector3 right = new Vector3((float)x, (float)y, (float)z);
            Vector3 up = Vector3.Cross(right, forward);
            return baseP + (right * offset.X) + (forward * offset.Y) + (up * offset.Z);

    Blah, cross products. I never quite understood algebra with vectors.

  • @ikt great job. I made my own implementation using dot product instead. I wish I had searched on google with parameter site: gta5-mods.com instead of just gtaforums.com . I thought there was no information about it, it took me some time to make own re-implementation. I was going to post my findings here as well, but yours is more efficient.


    Post it anyway, more choice is always better :)

  • @ikt Yeah you're right about that, more choice is better.

    public Vector3 GetOffsetGivenWorldCoords(Vector3 Origin, Vector3 Rotation, Vector3 Position)
        Vector3 RightVector = RelativeRightVector(Rotation);
        Vector3 ForwardVector = RotationToDirection(Rotation);
        return new Vector3(-1 * Vector3.Dot(RightVector, (Origin - Position)), -1 * Vector3.Dot(ForwardVector, (Origin - Position)), Position.Z - Origin.Z);
    public Vector3 RelativeRightVector(Vector3 Rotation)//source is from scripthookdotnet
       double num = Math.Cos(Rotation.Y * (Math.PI / 180.0));
       return new Vector3((float)(Math.Cos(-Rotation.Z * (Math.PI / 180.0)) * num), (float)(Math.Sin(Rotation.Z * (Math.PI / 180.0)) * num), (float)Math.Sin(-Rotation.Y * (Math.PI / 180.0)));
    public Vector3 RotationToDirection(Vector3 Rotation)//I forgot where I got this from, I had it for a long time
       float z = Rotation.Z;
       float num = z * 0.0174532924f;
       float x = Rotation.X;
       float num2 = x * 0.0174532924f;
       float num3 = Math.Abs((float)Math.Cos((double)num2));
       return new Vector3
         X = (-(float)Math.Sin(num)) * num3,
         Y = (float)Math.Cos(num) * num3,
         Z = (float)Math.Sin(num2)

  • @ikt I didn't realize your function said "GetOffsetInWorldCoords". My function does the other one and gets the offset.

Log in to reply

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.