XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

Unproject problem

Last post 5/22/2008 8:50 PM by SMJ. 2 replies.
  • 5/22/2008 6:57 PM

    Unproject problem

    I'm using Managed Directx 9, and I have been able to use the project method successfully, however, I seem to be unable to use unproject correctly.  Every time I look at another site I see a different set of matricies that are being used.  If I have a world with a view, projection, transform, what is the correct sequence? 

    Shouldn't it be

    Vector3 ray = new Vector3(MouseX, MouseY, 0) - this is 2D

     ray.unproject(device.Viewport, device.Transform.Projection, device.Transform.View, device.Transform.World)  ?  Then ray.x/ray.y should be my world coordinates right?

    It seems to generally be correct, however, the decimal is always slightly off and I can't figure out why when the project method is right on.  After two days of pounding my head, I could use a second opinion.  Thanks!

  • 5/22/2008 7:20 PM In reply to

    Re: Unproject problem

    What is it returning versus what you are expecting? Try passing Matrix.Identity as the World parameter and the x,y,0 point should be transformed to world space near the view matrix position.
    Ziggy

    Microsoft XNA MVP

    Ziggyware XNA News and Tutorials
  • 5/22/2008 8:50 PM In reply to

    Re: Unproject problem

    I have tried with the Identity Matrix as well.  It is returning coordinates within .05 of where I expect.  The problem is I have objects very close together because I have basically mapped my world locations to be latitudes/longitudes, and .01 in lat/lon is still a significant distance.  I suppose errors that small are due to floating point rounding error?  The results seem too close to be anything else.
Page 1 of 1 (3 items) Previous Next