Having finished the main engine of my game, I thought it was best to write a level editor rather than manually creating the xml level files as I have done so far.
The game is what I call 2.5D. Its basically a 2D game (Think asteroids) but using 3D models for improved lighting effects etc. (All objects are on the Z=0 plane).
Anyway, for the level editor I used the WinForms tutorials as my basis and created a GameWorldControl to show my game level info. The next step was to allow the user to select objects (e.g. asteroids) and place them int he game world using the mouse.
I'm using the Unproject method to convert the mouse co-ords into world co-ords, but it appears to be pretty inaccurate.
At the centre of the screen the unproject seems to be perfectly accurate, but the further you move from the centre the bigger the error becomes (Linearly). At the screen edges the error is about 50 pixels, which equates to several thousand units in the game world.
The snippet of code that tries to convert from client area co-ords to world co-ords is here:
| Vector3 clickpos = new Vector3(((MouseEventArgs)e).X, ((MouseEventArgs)e).Y, 0); |
| |
| // And project them back into world co-ords |
| Vector3 worldpos = GraphicsDevice.Viewport.Unproject(clickpos, m_ProjectionMatrix, m_ViewMatrix, Matrix.Identity); |
| |
And I'm using the exact same matrixies int he drawing code!
I've seen the thread Unproject() Insanity and whilst there were some good theories in there, and Shawn confirmed that it is in the XNA bug database, it didn't really give a solution.
Has anyone managed to their own accurate version (That ideally takes the same params as the original version)?
Thanks for your help
Ben