Followers 0

Problem with Camera and Mousepos

3 posts in this topic

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)
{

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;


greetings Move

Edited by Movementcat
0

0

Share on other sites

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

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

0

Share on other sites

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.

0

Create an account

Register a new account