[Math Help] Radar rotation. menu

User Tag List

Results 1 to 15 of 15
  1. #1
    cenron's Avatar Member
    Reputation
    12
    Join Date
    Mar 2008
    Posts
    93
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Math Help] Radar rotation.

    I am trying to get a in-game radar system going and its coming along great!

    I was able to get the distance of each point and scale is accordingly to get the location of everyone.

    Code:
    	wOutput.X = (wPlayer.X - wObj.X) * m_fZoom + m_iWidth / 2;
    	wOutput.Y = (wPlayer.Y - wObj.Y) * m_fZoom + m_iHeight / 2;


    BUT I can't seem to figure out the math for rotation. I want my character on the map to always face north and all other objects move around him, Halo Style. I am just stumped. I don't even know what the formula is called so I can google search it.

    Can anyone give me a bump in the right direction? I am real close to finishing it and my lack of math skills is keeping me from reaching the finish line.
    Last edited by cenron; 02-05-2009 at 02:24 PM.

    [Math Help] Radar rotation.
  2. #2
    alek900's Avatar Contributor
    Reputation
    103
    Join Date
    Nov 2007
    Posts
    101
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not sure i understand what your asking for but try...
    Code:
    	wOutput.X = (wPlayer.Y - wObj.Y) * m_fZoom + m_iWidth / 2; //notic the coord switch
    	wOutput.Y = (wPlayer.X - wObj.X) * m_fZoom + m_iHeight / 2; //notic the coord switch
    19+4 that means i score

  3. #3
    SKU's Avatar Contributor
    Reputation
    306
    Join Date
    May 2007
    Posts
    565
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rotation Matrix is what you're looking for.


    ((c) coords. background + formula picture wikipedia)

    You calculate the facing of your character, that gives you the angle (in radians) you need. Rotate every object around your player with that angle.

    In this example: f = pi/4

    x2 = sqrt(2)/2 * 3 - sqrt(2)/2 * (-3) = 3*sqrt(2)
    y2 = sqrt(2)/2 * 3 + sqrt(2)/2 * (-3) = 0

    -> (3*sqrt(2)/0)

    Kinda rushed, hope it helps.

    Edit: You'll obviously have to adjust it so it fits into the WoW environment.

    Also, I don't see the point in switching the X and Y coordinates. Depending on the coordinates, you get completely different rotation angles.

    Lets say you apply that on the point (3/0) --> new point = (0/3), that's a pi/2 rotation. Now take the object at the position (3/3) and apply it, you get a 'new' point (3/3). That means that this object didn't rotate with the other objects at all.

    Or am I missing something blatantly obvious?
    Last edited by SKU; 02-05-2009 at 03:30 PM.

  4. #4
    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)
    This is what you need to do, convert your Player rotation to degrees; The eq. is something like..

    ----

    (PI off the top of my head being roughly.. 3.1415926535897932384626433832795; soo..)

    Degrees = Player.Rotation * 180 / PI;

    ----

    Then you would create a matrix, and I'm assuming you use GDI to draw the map so something like..

    ----
    Code:
    PointF ptF (x = Form Width / 2, y = Form Height / 2)
    System.Drawing.Drawing2D.Matrix mat
    mat.RotateAt(Degrees, ptF, Drawing2D.MatrixOrder.Append)
    graphics.Transform = mat
    
    // Draw your entities
    
    mat.RotateAt(0, ptF, Drawing2D.MatrixOrder.Append)
    graphics.Transform = may
    
    // Draw your player
    Sure, it's a cheap way of doing it; But it works and there should be no fuss.

    But I recommend actually Rotating the player, making something like a triangle and rotating it; It's MUCH less confusing to the player.


  5. #5
    wraithZX's Avatar Active Member
    Reputation
    43
    Join Date
    May 2007
    Posts
    122
    Thanks G/R
    0/1
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Render everything to a surface as per normal, then rotate the surface when drawing.

  6. #6
    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)
    As I suggested above ^, Rotate the entire Graphics Object that you're drawing with then reset it and draw the player on top of all the other "Objects" you drew.


  7. #7
    cenron's Avatar Member
    Reputation
    12
    Join Date
    Mar 2008
    Posts
    93
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by SKU View Post
    Rotation Matrix is what you're looking for.


    ((c) coords. background + formula picture wikipedia)

    You calculate the facing of your character, that gives you the angle (in radians) you need. Rotate every object around your player with that angle.

    In this example: f = pi/4

    x2 = sqrt(2)/2 * 3 - sqrt(2)/2 * (-3) = 3*sqrt(2)
    y2 = sqrt(2)/2 * 3 + sqrt(2)/2 * (-3) = 0

    -> (3*sqrt(2)/0)

    Kinda rushed, hope it helps.

    Edit: You'll obviously have to adjust it so it fits into the WoW environment.

    Also, I don't see the point in switching the X and Y coordinates. Depending on the coordinates, you get completely different rotation angles.

    Lets say you apply that on the point (3/0) --> new point = (0/3), that's a pi/2 rotation. Now take the object at the position (3/3) and apply it, you get a 'new' point (3/3). That means that this object didn't rotate with the other objects at all.

    Or am I missing something blatantly obvious?
    Hmm this is what I am looking for. But having trouble implementing it.

    I get the players facing and run it through that formula.

    Code:
    	wOutput.X = (wPlayer.X - wObj.X) * m_fZoom + m_iWidth / 2;
    	wOutput.Y = (wPlayer.Y - wObj.Y) * m_fZoom + m_iHeight / 2;
    
    	float D = ( wPlayer.Facing );
    	wOutput.X = ( sqrt(D)/2 * wOutput.X - sqrt(D)/2 * wOutput.Y );
    	wOutput.Y = ( sqrt(D)/2 * wOutput.X + sqrt(D)/2 * wOutput.Y );
    It spits out numbers that aren't valid...I must be missing something. When you say get the angle of the player in radians you mean get the player facing? or get the angle between Point A and Point B using atan?

    I can't seem to get my brain around this concept.

    Originally Posted by suicidity View Post
    This is what you need to do, convert your Player rotation to degrees; The eq. is something like..

    ----

    (PI off the top of my head being roughly.. 3.1415926535897932384626433832795; soo..)

    Degrees = Player.Rotation * 180 / PI;

    ----

    Then you would create a matrix, and I'm assuming you use GDI to draw the map so something like..

    ----
    Code:
    PointF ptF (x = Form Width / 2, y = Form Height / 2)
    System.Drawing.Drawing2D.Matrix mat
    mat.RotateAt(Degrees, ptF, Drawing2D.MatrixOrder.Append)
    graphics.Transform = mat
    
    // Draw your entities
    
    mat.RotateAt(0, ptF, Drawing2D.MatrixOrder.Append)
    graphics.Transform = may
    
    // Draw your player
    Sure, it's a cheap way of doing it; But it works and there should be no fuss.

    But I recommend actually Rotating the player, making something like a triangle and rotating it; It's MUCH less confusing to the player.

    No GDI. I hooked D3D functions to draw. The matrix rotation is what I am looking at.

  8. #8
    jbrauman's Avatar Member
    Reputation
    65
    Join Date
    Dec 2007
    Posts
    72
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by wraithZX View Post
    Render everything to a surface as per normal, then rotate the surface when drawing.
    This is what I did in my radar. Instead of drawing things rotated, for each thing I was drawing I rotated the whole graphics object, then drew what I needed to draw, then rotated it back.

    Take a look at my radar source (search for it in the bots section)

  9. #9
    kynox's Avatar Member
    Reputation
    830
    Join Date
    Dec 2006
    Posts
    888
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    void calcRadarPos(idVec3 vecPos, idVec3 vecLocalPos, idVec2& vecScreen)
    {
        idVec3 vecDelta;
        // Added PI/2 to the facing
        float yaw = g_PlayerPtr->GetFacing() + 1.57079632f;
    
        vecDelta = (vecPos - vecLocalPos);
    
        vecScreen.x = -( vecDelta.x * cosf( -yaw ) - vecDelta.y * sinf( -yaw ) );
        vecScreen.y = ( vecDelta.y * cosf( -yaw ) + vecDelta.x * sinf( -yaw ) );
    
        // Add the vector to the radar position
        vecScreen.x += RadarPos.x;
        vecScreen.y += RadarPos.y;
    }
    Give that a whirl. It should rotate everything around when you move your camera.

  10. #10
    SKU's Avatar Contributor
    Reputation
    306
    Join Date
    May 2007
    Posts
    565
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    float D = ( wPlayer.Facing );
    wOutput.X = ( sqrt(D)/2 * wOutput.X - sqrt(D)/2 * wOutput.Y );
    wOutput.Y = ( sqrt(D)/2 * wOutput.X + sqrt(D)/2 * wOutput.Y );
    The sqrt(2)/2 was just an examle using pi/4 as the rotation angle. (Because sin(pi/4) = cos(pi/4) thus easy for me to show what I mean, sorry that it was a bit confusing)

    Basicly you would just need to change all your "sqrt(D)/2" pieces with either +-cps(D) or +-sin(D) (look at the matrix)

    You must however be aware that this is actually a rotation around the origin: (0/0). Using this method, you'd first need to make your players position (the middle of the radar) the origin (translation), then rotate and then translate everything back. (yah my math-english is bad, I know)

    This is just the very very basic math how to 'rotate' things using a matrix. It wold be much easier to draw everything normal and then properly rotate the whole 'picture' as suggested above. Thats what I get for not knowing that something like the graphic-rotation stuff exists .

    Gotta go to the univerity now, if you can't figure it out I might try it later when I get home.

  11. #11
    jbrauman's Avatar Member
    Reputation
    65
    Join Date
    Dec 2007
    Posts
    72
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice radar by the way, however you might think of making the 'blocks' transparent some.

  12. #12
    SKU's Avatar Contributor
    Reputation
    306
    Join Date
    May 2007
    Posts
    565
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was bored..



    the rotate-function (basically what kynox said, just trimmed to look short 'n ugly )

    Code:
            private void RotateObject(PointF obj, PointF center, float angle)
            {
                /*
                 * angle is in your case the facing (also in radians)
                 * center is the player. As you'll probably keep the player always in the middle, you
                 * can remove the PointF center agument and just hard code it into your function as it won't
                 * change anyway.
                 */
                PointF nPosition = new PointF();
                nPosition.X = (float)((Math.Cos(angle) * (obj.X - center.X) - Math.Sin(angle) * (obj.Y - center.Y)) + center.X);
                nPosition.Y = (float)((Math.Sin(angle) * (obj.X - center.X) + Math.Cos(angle) * (obj.Y - center.Y)) + center.Y);
                // now 'redraw' your point (and remove the old if it was actually painted)
                DrawPoint(nPosition, Color.Red); // Just some SetPixel stuff..
                // ..
            }
    It's just a 'linked' (spelling -_-) version of the three parts: Translation -> Rotation -> Translation



    Hope it helps.

    Edit: was even more bored and actually tested it ingame.. the objects you face are always north on the radar.
    http://img214.imageshack.us/img214/2...ngradarah8.jpg
    Last edited by SKU; 02-06-2009 at 02:24 PM.

  13. #13
    cenron's Avatar Member
    Reputation
    12
    Join Date
    Mar 2008
    Posts
    93
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by kynox View Post
    Code:
    void calcRadarPos(idVec3 vecPos, idVec3 vecLocalPos, idVec2& vecScreen)
    {
        idVec3 vecDelta;
        // Added PI/2 to the facing
        float yaw = g_PlayerPtr->GetFacing() + 1.57079632f;
    
        vecDelta = (vecPos - vecLocalPos);
    
        vecScreen.x = -( vecDelta.x * cosf( -yaw ) - vecDelta.y * sinf( -yaw ) );
        vecScreen.y = ( vecDelta.y * cosf( -yaw ) + vecDelta.x * sinf( -yaw ) );
    
        // Add the vector to the radar position
        vecScreen.x += RadarPos.x;
        vecScreen.y += RadarPos.y;
    }
    Give that a whirl. It should rotate everything around when you move your camera.
    Originally Posted by SKU View Post
    The sqrt(2)/2 was just an examle using pi/4 as the rotation angle. (Because sin(pi/4) = cos(pi/4) thus easy for me to show what I mean, sorry that it was a bit confusing)

    Basicly you would just need to change all your "sqrt(D)/2" pieces with either +-cps(D) or +-sin(D) (look at the matrix)

    You must however be aware that this is actually a rotation around the origin: (0/0). Using this method, you'd first need to make your players position (the middle of the radar) the origin (translation), then rotate and then translate everything back. (yah my math-english is bad, I know)

    This is just the very very basic math how to 'rotate' things using a matrix. It wold be much easier to draw everything normal and then properly rotate the whole 'picture' as suggested above. Thats what I get for not knowing that something like the graphic-rotation stuff exists .

    Gotta go to the univerity now, if you can't figure it out I might try it later when I get home.
    Originally Posted by SKU View Post
    I was bored..



    the rotate-function (basically what kynox said, just trimmed to look short 'n ugly )

    Code:
            private void RotateObject(PointF obj, PointF center, float angle)
            {
                /*
                 * angle is in your case the facing (also in radians)
                 * center is the player. As you'll probably keep the player always in the middle, you
                 * can remove the PointF center agument and just hard code it into your function as it won't
                 * change anyway.
                 */
                PointF nPosition = new PointF();
                nPosition.X = (float)((Math.Cos(angle) * (obj.X - center.X) - Math.Sin(angle) * (obj.Y - center.Y)) + center.X);
                nPosition.Y = (float)((Math.Sin(angle) * (obj.X - center.X) + Math.Cos(angle) * (obj.Y - center.Y)) + center.Y);
                // now 'redraw' your point (and remove the old if it was actually painted)
                DrawPoint(nPosition, Color.Red); // Just some SetPixel stuff..
                // ..
            }
    It's just a 'linked' (spelling -_-) version of the three parts: Translation -> Rotation -> Translation



    Hope it helps.

    Edit: was even more bored and actually tested it ingame.. the objects you face are always north on the radar.
    http://img214.imageshack.us/img214/2...ngradarah8.jpg
    Thx for all the info guys. I got it to work. You two seriously made my night when I got home from work and the info that I needed was here. Totally put a smile on my face


    Let me clean up my code and Ill post a screen shot and and the code that handles the calculations.

  14. #14
    SKU's Avatar Contributor
    Reputation
    306
    Join Date
    May 2007
    Posts
    565
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice to hear that.

  15. #15
    cenron's Avatar Member
    Reputation
    12
    Join Date
    Mar 2008
    Posts
    93
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So here is a cool screen shot of the radar and it turns as I turn. I can zoom in and out.


    So far it gives you the obj name and its distance from you.





    // Code that handles it. Pass two wow positions and it will convert it to fit the screen.
    Code:
    WOWPOS CRadar::CalcObjPos( WOWPOS wPlayer, WOWPOS wObj )
    {
    	WOWPOS wOutput;
    	WOWPOS vecScreen;
    
    	wOutput.X = (wObj.X - wPlayer.X);
    	wOutput.Y = (wObj.Y - wPlayer.Y);
    
    	 
    	// Added PI/2 to the facing...Thx kynox and SKU for this info.
    	 float yaw = gpXTC->GetCurMgr()->GetPlayer()->GetFacing() + 1.57079632f;
    
    	vecScreen.X = -( wOutput.X * cosf( -yaw ) - wOutput.Y * sinf( -yaw ) );
    	vecScreen.Y = ( wOutput.Y * cosf( -yaw ) + wOutput.X * sinf( -yaw ) );
    	
    	wOutput.X += vecScreen.X * m_fZoom + m_iWidth / 2;
    	wOutput.Y += vecScreen.Y * m_fZoom + m_iHeight / 2;
    
    	return wOutput;
    }

Similar Threads

  1. Need some quick math help >.<
    By xcureanddisease in forum Community Chat
    Replies: 1
    Last Post: 11-24-2014, 11:12 AM
  2. coding help. resto rotation. pe
    By Mackdaddy2887 in forum WoW Bots Questions & Requests
    Replies: 2
    Last Post: 03-25-2014, 03:46 PM
  3. [HELP] PQR Rotation Bot Profile Making
    By Missu in forum Programming
    Replies: 0
    Last Post: 10-22-2012, 06:27 AM
  4. [Help] Object Coords to own "Radar"
    By unbekannt1 in forum WoW Memory Editing
    Replies: 12
    Last Post: 05-01-2009, 12:53 PM
  5. math help plox :<
    By cripling in forum Community Chat
    Replies: 5
    Last Post: 11-26-2007, 01:50 PM
All times are GMT -5. The time now is 04:26 AM. 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