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


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
3 replies to this topic

#1 Movementcat   Members   -  Reputation: 106

Like
0Likes
Like

Posted 25 June 2013 - 09:14 AM

Dear Guys,

 

i have a understanding Question it work now for me but i dont know why maybe you can help or why even the Problem occur's.

 

I have a TileMap with 32, 32 Tiles and a normal Camera Class that follows my Player and for the Editor it follow the Mouse, but there i had a Probleme the Mouse Position was incorrect so i did Invert the Matrix for my Mouse Position.

 

It worked fine, exept in the Display Region under 0,0 so -32,0 etc etc or -32,-32, or every negativ value. Hope you understand me since my English arent the best.

 

It was not much difference but the Cursor was just a bit off. So i will show you some Code maybe you know why this happens.

 

 

Camera.cs

 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, -center.Y, 0)) *
                Matrix.CreateRotationZ(_rotation) *
                Matrix.CreateScale(_zoom) *
                Matrix.CreateTranslation(new Vector3(view.Width / 2, view.Height / 2, 0));
        }
    }
}


my Input Manager 

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

            if (mousePos.Y < 0)
            {
                mousePos.Y = mousePos.Y - 32;
            }

            if (mousePos.X < 0)
            {
                mousePos.X = mousePos.X - 32;
            }

            return mousePos;
        }

So here is a intresting Point, if i have this 2 If cases, everything ist fine but if i delete them my Cursor is off in negativ Display Values. But still fine in normal Display Regions.

 

And maybe its Interesting aswell here i "snap" the current Tile so that my Cursor is always Perfectly over a Tile its in my Editor.cs

 _cursorLocX = (int)(mousePos.X / _tileWidth) * _tileWidth;
 _cursorLocY = (int)(mousePos.Y / _tileHeight) * _tileHeight;

Thanks for reading, if you need any more Informations please let me know.

 

greetings Move


Edited by Movementcat, 25 June 2013 - 09:18 AM.


Sponsor:

#2 Movementcat   Members   -  Reputation: 106

Like
0Likes
Like

Posted 25 June 2013 - 08:25 PM

Nobody an advice?



#3 Andy474   Members   -  Reputation: 690

Like
0Likes
Like

Posted 26 June 2013 - 09:01 AM

perhaps try rewording the question. I need an enigma machine to decode this.

 

What is the actual problem (Screenshots)? 2D? 3D? Language? Framework? 



#4 Álvaro   Crossbones+   -  Reputation: 13652

Like
0Likes
Like

Posted 26 June 2013 - 09:26 AM


Dear Guys,



i have a understanding Question it work now for me but i dont know why maybe you can help or why even the Problem occur's.


 

I stopped reading about there. Your disregard for punctuation and grammar make it really hard to understand what you are saying, and if you are not willing to put the effort to write correctly, I am not willing to put the effort to help you.






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