Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Problem with Camera and Mousepos XNA


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Movementcat   Members   -  Reputation: 106

Like
0Likes
Like

Posted 06 July 2013 - 04:55 PM

Dear Guys,

 

I use a Camera in my 2D XNA Game, and have really Problems to get the right Position of my Mouse Cursor you have maybe a Solution?

        //Klassen Variablen

        public Matrix transform;
        Viewport view;
        public Vector2 center;

        //Eigenschaften

        float _width { get; set; }
        float _height { get; set; }
        float _rotation { get; set; }
        float _zoom { get; set; }
        float _camSpeed { get; set; }
        bool _follow { get; set; }

        //Konstruktor
        
        public Camera(Viewport newView)
        {
            view = newView;
            _zoom = 1f;
            _rotation = 0f;
            center = new Vector2(0, 0);
            _camSpeed = 5f;
            _follow = true;
        }

        #region Kamera Kontrolle


        //Camera Position Updaten

        public void Update(IFocus focus)
        {
 
            if(_follow == true)
            center = focus.getFocus();
            _width = focus.getWidth() / 2;
            _height = focus.getHeight() / 2;

            transform = Matrix.CreateTranslation(new Vector3(-center.X - _width, -center.Y - _height, 0)) *
                Matrix.CreateRotationZ(_rotation) *
                Matrix.CreateScale(_zoom) *
                Matrix.CreateTranslation(new Vector3(view.Width / 2, view.Height / 2, 0));
        }
    }
}

If i try to transform the MousePosition aswell, the Mouse is still a bit off the Center if im in negativ Values of the Screen.

 

mousePos = Vector2.Transform(mousePos, Matrix.Invert(cam.transform));

 

I cant do any precise shooting or anything else.

 

maybe you know a answer.

 

Greetings Move

 

 

 



Sponsor:

#2 DpakoH   Members   -  Reputation: 1008

Like
0Likes
Like

Posted 08 July 2013 - 07:18 AM

hi there,

there is something strange with your camera class, maybe you should provide code for IFocus. why don't you look here, I am using this camera, it is similar to yours. the way you are taking world coordinates for the mouse is right, I am doing it the same way and it is working.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS