[Math] Camera Yaw - How to Calculate? menu

User Tag List

Results 1 to 8 of 8
  1. #1
    Xelper's Avatar ★ Elder ★
    Reputation
    1024
    Join Date
    Mar 2007
    Posts
    860
    Thanks G/R
    0/8
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Math] Camera Yaw - How to Calculate?

    I was hoping someone might be able to help me out with what is probably some basic trig here.. I've been trying to figure this out for a few hours, probably should have payed more attention in school.

    I'm trying to calculate the yaw in degrees (hopefully that is the proper way to say it) (0-359.9~) at which the camera is facing the target (normally the player.)

    So if the camera is behind the player, 0 would be returned. If it was in front of the player looking at the player's face, 180 would be returned.

    (X = Object, normally player. Circle = Camera)


    I already have the X Y ( and Z, though irrelevant imo) of both the camera and the player.

    I have been looking at functions to accomplish this from posts such as:
    http://www.mmowned.com/forums/world-...-function.html

    and

    Calculate yaw and pitch from origin and target? - App Hub Forums

    However I can't seem to get the value I am looking for, it would obviously help if I better understood trig, but I really just don't have the time to teach myself it for what will be a really small portion of my bot. The last time I needed this was sometime during Wrath, and at the time I was able to just grab the WoW CVar "cameraYawE" however it has since been removed from the game because an addon was using it in a way Blizzard didn't like.

    Thanks!
    Last edited by Xelper; 06-05-2011 at 05:15 PM.

    [Math] Camera Yaw - How to Calculate?
  2. #2
    streppel's Avatar Active Member
    Reputation
    78
    Join Date
    Mar 2007
    Posts
    196
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    atan2(y2-y1,x2-x1)?
    returns a value from -pi to pi which can be turned from radian into degree easily

  3. #3
    Xelper's Avatar ★ Elder ★
    Reputation
    1024
    Join Date
    Mar 2007
    Posts
    860
    Thanks G/R
    0/8
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Doesn't seem to be returning the number I am looking for, I swapped the origin and target (player/camera) and got the same type of result each time. I probably should have been a bit more specific.

    Origin X, Y, Z:
    {-9176.93, 336.066, 91.83826}

    Target X, Y, Z:
    {-9195.183, 317.5946, 87.67601}

    Code:
            private float ComputeYaw(MyWoW.Position origin, MyWoW.Position target)
            {
                return (float)Math.Atan2(target.Y - origin.Y, target.X - origin.X);
            }
    //convert to deg.
    yaw = (float)(180 / Math.PI) * ComputeYaw(cameraPos, myPos);

    returns -134.65921
    The result of this is correct only if the player is facing north, rotating the camera shows the yaw as a value between -pi and pi. When converted to degrees: 90 to the right, 180 on the opposite side and -90 (270) to the left.

    This works as if the player was always facing north, so I guess I also need a way to take the player's facing into account? So that if the player was flying directly west and the camera was following in its default location (directly behind the player) 0 would be returned. I'm thinking that it should be pretty simple. I'll experiment some more.

    Thank you so much for your help. +rep


    EDIT:

    Got it, while there might be a more elegant way to accomplish this:

    rotation = (float)(ObjectManager.Me.R * (180 / Math.PI));
    yaw = yaw - rotation
    if (yaw < 0)
    {
    yaw = yaw + 360
    }
    Last edited by Xelper; 06-05-2011 at 06:59 PM.

  4. #4
    MaiN's Avatar Elite User
    Reputation
    335
    Join Date
    Sep 2006
    Posts
    1,047
    Thanks G/R
    0/10
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Btw, the image you posted is wrong. In WoW, 0 degrees is north and 90 degrees is West.
    [16:15:41] Cypher: caus the CPU is a dick
    [16:16:07] kynox: CPU is mad
    [16:16:15] Cypher: CPU is all like
    [16:16:16] Cypher: whatever, i do what i want

  5. #5
    suicidity's Avatar Contributor
    Reputation
    207
    Join Date
    Oct 2006
    Posts
    1,439
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by MaiN View Post
    Btw, the image you posted is wrong. In WoW, 0 degrees is north and 90 degrees is West.
    The image is rotated as if the bottom of the image is behind the character, top is in front of the character; Ergo rotating everything 180deg.


  6. #6
    streppel's Avatar Active Member
    Reputation
    78
    Join Date
    Mar 2007
    Posts
    196
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    now i'm totally confused

  7. #7
    Xelper's Avatar ★ Elder ★
    Reputation
    1024
    Join Date
    Mar 2007
    Posts
    860
    Thanks G/R
    0/8
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by streppel View Post
    now i'm totally confused
    Haha, it is working now. I was just looking to replicate the cameraYawE CVar WoW had prior to patch 3.3.5. This CVar would return 0 if the camera was directly behind the player, 90 if to the right of the player (looking at the player), 180 if in front of the player and 270 if to the left of the player (and everything in between 0-359.9~). The atan2 function you gave me worked fine, but it didn't take into consideration the player's rotation... so I just had to subtract the player's rotation from that.

  8. #8
    streppel's Avatar Active Member
    Reputation
    78
    Join Date
    Mar 2007
    Posts
    196
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah,good to know you got it working

Similar Threads

  1. [Tool] ### How to Calculate IV precisely? ###
    By Brick3 in forum Pokemon GO Hacks|Cheats
    Replies: 4
    Last Post: 08-10-2016, 02:56 PM
  2. [Mangos] How to calculate AreaMap from GameObject Coordinates ?
    By Alberto Pittaluga in forum WoW EMU Questions & Requests
    Replies: 3
    Last Post: 05-19-2015, 12:48 PM
  3. How +Spell Damage Is Calculated For Mages
    By impulse102 in forum World of Warcraft Guides
    Replies: 7
    Last Post: 08-06-2006, 06:08 AM
All times are GMT -5. The time now is 03:45 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search