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 8074941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:49:46+00:00 2026-06-05T14:49:46+00:00

I have a pretty annoying problem. I would like to create a drawing program,

  • 0

I have a pretty annoying problem. I would like to create a drawing program, using winform + XNA combo.

The most important part would be to transform the mouse position into the XNA drawn grid – I was able to make it for the translations, but it only work if I don’t zoom in – when I do, the coordinates simply went horrible wrong.

And I have no idea what I doing wrong. I tried to transform with scaling matrix, transform with inverse scaling matrix, multiplying with zoom, but none seems to work.

In the beginning (with zoom value = 1) the grid starts from (0,0,0) going to (Width, Height, 0). I was able to get coordinates based on this grid as long as the zoom value didn’t changed at all. I using a custom shader, with orthographic projection matrix, identity view matrix, and the transformed world matrix.

Here are the two main methods:

internal void Update(RenderData data)
{
    KeyboardState keyS = Keyboard.GetState();
    MouseState mouS = Mouse.GetState();

    if (ButtonState.Pressed == mouS.RightButton)
    {
        camTarget.X -= (float)(mouS.X - oldMstate.X) / 2;
        camTarget.Y += (float)(mouS.Y - oldMstate.Y) / 2;
    }

    if (ButtonState.Pressed == mouS.MiddleButton || keyS.IsKeyDown(Keys.Space))
    {
        zVal += (float)(mouS.Y - oldMstate.Y) / 10;
        zoom = (float)Math.Pow(2, zVal);
    }

    oldKState = keyS;
    oldMstate = mouS;

    world = Matrix.CreateTranslation(new Vector3(-camTarget.X, -camTarget.Y, 0)) * Matrix.CreateScale(zoom / 2);
}

internal PointF MousePos
{
    get
    {
        Vector2 mousePos = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);

        Matrix trans = Matrix.CreateTranslation(new Vector3(camTarget.X - (Width / 2), -camTarget.Y + (Height / 2), 0));

        mousePos = Vector2.Transform(mousePos, trans);
        return new PointF(mousePos.X, mousePos.Y);
    }
}

The second method should return the coordinates of the mouse cursor based on the grid (where the (0,0) point of the grid is the top-left corner.).

But is just don’t work. I deleted the zoom transformation from the matrix trans, as I wasn’t able to get any useful results (most of the time, the coordinates were horribly wrong, mostly many thousands when the grid’s size is 500×500).

Any ideas, or suggestions? I’ve been trying to solve this simple problem for two days now :\

  • 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-06-05T14:49:48+00:00Added an answer on June 5, 2026 at 2:49 pm

    Take a look at the GraphicsDevice.Viewport.Unproject method for converting screen space locations in to world space, it basically goes through your world, view, projection transformations in reverse order.

    as for your zooming issue, instead of scaling the world transform why not move the camera closer to the object that you’re viewing?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pretty annoying problem here, as Im still trying to internalize each
I have a pretty annoying problem with the IntelliSense in Visual Studio 2010: Every
I have a pretty annoying compiling problem. I am trying to do a System.loadlibrary
I have this annoying problem, that Im pretty sure happens to all of you
I have pretty standard Qmail toaster installation. I'm using the dot files to set
I have a problem with hibernate where it is doing N+1 SELECTS when using
And this is pretty annoying since we have it set up to continuously check
I'm running across a very annoying problem regarding transitive const in D. I have
I've just come across a pretty strange problem with VS2010 and Script#, which most
i have my listview activity that works pretty fine but i have an annoying

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.