How to get the character's orientation from MumbleLink? — Guild Wars 2 Forums
Home API Development

How to get the character's orientation from MumbleLink?

I'm playing with the MumbleLink API at the moment and I'm trying to get the character's orientation relative to the game map's orientation.
There's a struct fAvatarFront in LinkedMem. This struct changes when the character rotates around itself.
And there's another struct compassRotation in MumbleContext but it's always 0 no matter which way the character turns afaik even though the wiki said that it's radians (I have a high hope for it but turned out it didn't worked or I missed something big time :p ).
Does anyone figure out how to get this information? My best observation is the clue relates to the struct fAvatarFront.
It would be nice if someone already created some sort of formula to convert these numbers into the angle number relative to the map's orientation.

Thanks in advance

Best Answer

Answers

  • Thanks for tips about the minimap and the link. It has been a long time since I touched the triangles, lines, points and stuffs. I think it's time for me to refresh them.

  • Leo.3428Leo.3428 Member ✭✭✭

    Assuming that in GW2 the character model cannot stare at the zenith or the nadir, I think that you can simplify the math and use only the projection of the front vector onto the horizontal plane: yaw = atan2(frontvector.z, frontvector.x). See the Mumble coordinate system if you're wondering why we take z and x. This yields the anticlockwise angle from the positive x axis. Ref: https://en.wikipedia.org/wiki/Atan2 . Give it a try and let us know, I'm interested in the result :)

    If you're interested in how to handle unit vectors with a complete freedom of rotation, have a look at https://en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions

  • Here is what I came up with:
    I use fAvatarFront from struct LinkedMem and like you said we take only X and Z values so they are fAvatarFront[0] and fAvatarFront[2] respectively.

    This is the code written in C#:

    public static int Get_Orientation(float fAvatarFront)
    {
    float radian = (float)Math.Atan2(fAvatarFront[0], fAvatarFront[2]);
    float angle = radian * 180.0f / (float)Math.PI;
    return (int)((angle + 360.0f) % 360.0f);
    }

    This will return an integer value from 0 to 359. It starts at true North equals to 0 and goes clockwise.
    Thanks again for the infos.

  • Leo.3428Leo.3428 Member ✭✭✭

    Glad it worked! Nice trick to do atan2(x,z) instead of atan2(z,x) to get the origin axis rotated and the angle flipped as you describe (north clockwise instead of east anticlockwise).
    Are you planning to develop a game tool?

  • Are you planning to develop a game tool?

    Maybe in the near future but for now, I'm just trying to test my capability and get familiar with the APIs.