Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6372617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:15:41+00:00 2026-05-25T01:15:41+00:00

I have a image of a Map and a smaller PictureBox control. I’m getting

  • 0

I have a image of a Map and a smaller PictureBox control.

I’m getting input from my joysyick. My the Y takes the image up and left
Adn the X actually rotates the image..

My problem is when i rotate the Image, the Y axis rotates with it, so when i move up again it wont really go up.. it will go the the new direction the Y axis points too..

Here is my code if you could understand my problam..

    public void UpdateTurret()
    {
        while (js != null)
        {
            js.GetData();
            Thread.Sleep(80);
            MapY += js.State.Y;
            MapRotation += js.State.X;
            {
                Image map = Properties.Resources.Map;
                Bitmap bmp = (Bitmap)map.Clone();
                Graphics g = Graphics.FromImage((Image)bmp);
                g.TranslateTransform((float)bmp.Width / 2, (float)bmp.Height / 2 - (MapY / 2));
                g.RotateTransform(MapRotation);
                g.TranslateTransform(-(float)bmp.Width / 2, -(float)bmp.Height / 2 + (MapY / 2));
                g.DrawImage(bmp, 0, 0);

                Graphics gfx = Graphics.FromImage((Image)bmp);
                gfx.DrawPie(new Pen(Color.Blue, 5), bmp.Width/2 - 5, bmp.Height/2 - 5, 5, 5, 0, 360);
                gfx.DrawImage(bmp, 0, MapY);

                picBoxMap.Image = (Image)bmp;

                float rot = MapRotation;
                rot = (float)Math.Abs((rot - 360*Math.Ceiling(rot / 360)));
                DrawString = (rot).ToString() + "° Y:" + MapY.ToString();
            }
        }
    }

My problem now is that the rotation point is always centered, i want my rotation point to be the new position i reached.

So i figured out it should be like this:

g.TranslateTransform((float)bmp.Width / 2, (float)bmp.Height / 2 - MapY);
g.RotateTransform(MapRotation);
g.TranslateTransform(-(float)bmp.Width / 2, -(float)bmp.Height / 2 + MapY);

But this cause another bug. Now when i rotate the Image, the Y axis rotates with it, so when i move up again it wont really go up.. it will go the the new direction the Y axis points too..

Anyone has an idea on solving this issue?


EDIT:

Here is my new code:

    public void UpdateTurret()
    {
        while (js != null)
        {
            js.GetData();
            Thread.Sleep(80);
            MapY += js.State.Y;
            MapRotation += js.State.X;
            {
                Image map = Properties.Resources.Map;
                Size mapSize = map.Size;
                Bitmap bmp = (Bitmap)map.Clone();
                Graphics g = Graphics.FromImage((Image)bmp);

                Matrix transformMatrix = new Matrix();

                transformMatrix.Translate(-mapSize.Width / 2, -mapSize.Height / 2, MatrixOrder.Append);
                transformMatrix.Rotate(MapRotation, MatrixOrder.Append);
                transformMatrix.Translate(mapSize.Width / 2, mapSize.Height / 2, MatrixOrder.Append);

                transformMatrix.Translate(0, MapY, MatrixOrder.Append);

                g.Transform = transformMatrix;
                g.DrawImage(bmp, 0,0);

                picBoxMap.Image = (Image)bmp;

                float rot = MapRotation;
                rot = (float)Math.Abs((rot - 360*Math.Ceiling(rot / 360)));
                DrawString = (rot).ToString() + "° Y:" + MapY.ToString();
            }
        }
        //Draw Cross
        Graphics gfx = picBoxMap.CreateGraphics();
        Rectangle rc = picBoxMap.ClientRectangle;

        gfx.DrawLine(Pens.Red, rc.Width / 2, rc.Height / 2 + 10, rc.Width / 2, rc.Height / 2 - 10);
        gfx.DrawLine(Pens.Red, rc.Width / 2 + 10, rc.Height / 2, rc.Width / 2 - 10, rc.Height / 2);
    }

My problem now is that after i move the map on the Y axis, the rotation point stays on the center point.

enter image description here

And look after i only rotated the map:

enter image description here

You can see i didn’t move the Y axis but it did changed.. because the Rotation point is at the center of the image and not where to red cross is.

I need the rotation point to be at the same position of the red cross.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:15:41+00:00Added an answer on May 25, 2026 at 1:15 am

    Possibly a better approach is to use the Matrix.Rotate() and Matrix.Translate() methods to get a matrix to set the Graphics.Transform to.

    Then you can simply draw your map at the origin (ignoring moving and rotating it), and the graphics object will do the rest.

    See the examples in the Matrix method links for more info. In their example they draw a rectangle, but you could easily draw your image instead.


    In my unedited answer i was wrong. I’ve corrected my code below.

    The key things to note are:

    1. You want the point the map rotates at to vary according to where the player is, so you should translate the map first (since this will then effect where the rotation happens).
    2. I’ve changed the code to use the RotateAt so it’s easier to understand. This way we don’t need to worry about the extra translations to get the rotation point at the origin then back again.
    3. As you want the arrow keys to mean up with respect to the rotated image we can’t do it as simply as normal. I’ve added Cos and Sin terms in, deduced using basic trigonometry.
    4. I’ve now got 2 pictureboxes, the first shows only the translation, and the direction of the player, the second is a radar like view (which is what you’re after). So, this answer has the 2 main map display types, fixed north in picturebox1, rotating north in picturebox2.

    Arrow keys move the image, Q and E rotate it.

    using System;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            private PictureBox pictureBox1;
            private PictureBox pictureBox2;
    
            private Image imageToDraw = null;
    
            private float imageRotation = 0.0f;
            private PointF imageTranslation = new PointF();
    
            public Form1()
            {
                InitializeComponent();
    
                pictureBox1 = new PictureBox() { Top = 20, Left = 10, Width = 280, Height = 310, BorderStyle = BorderStyle.FixedSingle };
                pictureBox2 = new PictureBox() { Top = 20, Left = pictureBox1.Right + 10, Width = 280, Height = 310, BorderStyle = BorderStyle.FixedSingle };
    
                pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint);
                pictureBox2.Paint += new PaintEventHandler(pictureBox2_Paint);
    
                this.Controls.Add(pictureBox1);
                this.Controls.Add(pictureBox2);
    
                this.Controls.Add(new Label() { Text = "Left = translation only, Right = translation and rotation", Width = Width / 2 });
    
                this.ClientSize = new Size(pictureBox2.Right + 10, pictureBox2.Bottom + 10);
            }
    
            private void Form1_Paint(object sender, PaintEventArgs e)
            {
            }
    
            private void Form1_Activated(object sender, EventArgs e)
            {
                try
                {
                    imageToDraw = Image.FromFile("C:\\Map.jpg");
                }
                catch (Exception)
                {
                    MessageBox.Show("Ensure C:\\Map.jpg exists!");
                }
            }
    
            private void Form1_FormClosed(object sender, FormClosedEventArgs e)
            {
                if (imageToDraw != null)
                    imageToDraw.Dispose();
            }
    
            private void Form1_KeyDown(object sender, KeyEventArgs e)
            {
                const float MoveSpeed = 5.0f;
    
                switch (e.KeyCode)
                {
                    case Keys.Q:
                        imageRotation -= 1.0f;
                        break;
                    case Keys.E:
                        imageRotation += 1.0f;
                        break;
                    case Keys.Up:
                        imageTranslation = new PointF(imageTranslation.X - (float)Math.Sin(imageRotation / 180 * Math.PI) * MoveSpeed, imageTranslation.Y - (float)Math.Cos(imageRotation / 180 * Math.PI) * MoveSpeed);
                        break;
                    case Keys.Down:
                        imageTranslation = new PointF(imageTranslation.X + (float)Math.Sin(imageRotation / 180 * Math.PI) * MoveSpeed, imageTranslation.Y + (float)Math.Cos(imageRotation / 180 * Math.PI) * MoveSpeed);
                        break;
                    case Keys.Left:
                        imageTranslation = new PointF(imageTranslation.X - (float)Math.Cos(imageRotation / 180 * Math.PI) * MoveSpeed, imageTranslation.Y + (float)Math.Sin(imageRotation / 180 * Math.PI) * MoveSpeed);
                        break;
                    case Keys.Right:
                        imageTranslation = new PointF(imageTranslation.X + (float)Math.Cos(imageRotation / 180 * Math.PI) * MoveSpeed, imageTranslation.Y - (float)Math.Sin(imageRotation / 180 * Math.PI) * MoveSpeed);
                        break;
                }
    
                pictureBox1.Invalidate();
                pictureBox2.Invalidate();
            }
    
            private void pictureBox1_Paint(object sender, PaintEventArgs e)
            {
                if (imageToDraw != null)
                {
                    e.Graphics.ResetTransform();
    
                    Matrix transformMatrix = new Matrix();
    
                    transformMatrix.Translate(-imageTranslation.X, -imageTranslation.Y);
    
                    e.Graphics.Transform = transformMatrix;
    
                    e.Graphics.DrawImage(imageToDraw, Point.Empty);
    
                    transformMatrix = new Matrix();
    
                    transformMatrix.Translate(50, 50);
                    transformMatrix.RotateAt(-imageRotation, new PointF(20, 20));
    
                    e.Graphics.Transform = transformMatrix;
    
                    e.Graphics.DrawString("^", new Font(DefaultFont.FontFamily, 40), Brushes.Black, 0, 0);
                }
            }
    
            private void pictureBox2_Paint(object sender, PaintEventArgs e)
            {
                if (imageToDraw != null)
                {
                    e.Graphics.ResetTransform();
    
                    Matrix transformMatrix = new Matrix();
    
                    transformMatrix.Translate(-imageTranslation.X, -imageTranslation.Y);
                    transformMatrix.RotateAt(imageRotation, new PointF(pictureBox1.Width / 2 + imageTranslation.X, pictureBox1.Height / 2 + imageTranslation.Y));
    
                    e.Graphics.Transform = transformMatrix;
    
                    e.Graphics.DrawImage(imageToDraw, Point.Empty);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have taken thumbnail image from gallery which is smaller in size and resized
I have image map that can I move, but this map will be so
I have an image map in my page: <div id=books> <img src=images/books.png width=330 height=298
I have an image map with two different area shape attributes. I want to
I have custom map image with specific height and width. i need to map
I have an image and a map embedded as such: <img src=planets.gif width=145 height=126
I have this code to identify two different image map shape attributes. What I'm
I have a php class that generates a map image depending on my db
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I want to have a map (which is image-mapped) show green in areas where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.