River.8964 Posted April 23, 2020 Share Posted April 23, 2020 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 Link to comment Share on other sites More sharing options...
Leo.3428 Posted April 24, 2020 Share Posted April 24, 2020 fAvatarFront and fAvatarUp are unit vectors out of which you can calculate the character's yaw and pitch with a bit of trigonometry - see https://wiki.mumble.info/wiki/Link I think compassRotation would change only if you enable your minimap to rotate automatically depending on your character's orientation. Does this help? Link to comment Share on other sites More sharing options...
River.8964 Posted April 24, 2020 Author Share Posted April 24, 2020 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. Link to comment Share on other sites More sharing options...
Leo.3428 Posted April 24, 2020 Share Posted April 24, 2020 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 Link to comment Share on other sites More sharing options...
River.8964 Posted April 28, 2020 Author Share Posted April 28, 2020 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. Link to comment Share on other sites More sharing options...
Leo.3428 Posted April 28, 2020 Share Posted April 28, 2020 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? Link to comment Share on other sites More sharing options...
River.8964 Posted April 28, 2020 Author Share Posted April 28, 2020 > 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now