<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.xna.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>XNA Framework</title><link>http://forums.xna.com/forums/56.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 0.0)</generator><item><title>Re: Unproject() Insanity</title><link>http://forums.xna.com/forums/thread/159483.aspx</link><pubDate>Sun, 05 Apr 2009 22:42:07 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:159483</guid><dc:creator>ajmiles</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/159483.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=56&amp;PostID=159483</wfw:commentRss><description>I believe it was fixed in 3.0. I have vague recollections of a thread involving Shawn and Zman looking at the code and one of the two highlighting a very subtle bug in the code that meant it failed under some conditions, that was definitely pre-3.0.</description></item><item><title>Re: Unproject() Insanity</title><link>http://forums.xna.com/forums/thread/159423.aspx</link><pubDate>Sun, 05 Apr 2009 19:59:36 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:159423</guid><dc:creator>jwatte</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/159423.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=56&amp;PostID=159423</wfw:commentRss><description>Sorry to necro this thread, but AFAICT, Viewport.Unproject() works fine. It certainly does in 3.0.&lt;br /&gt;
Something that tripped me up once was the order of parameters -- projection, view, world is the reverse of what you&amp;#39;d expect from just looking at the transform pipeline.&lt;br /&gt;
I have posted a tutorial on how to do world-space mouse picking correctly, using Viewport.Unproject(), together with a sample program that shows that it works, at &lt;a href="http://www.enchantedage.com/xna-picking"&gt;http://www.enchantedage.com/xna-picking&lt;/a&gt;. Have fun!&lt;br /&gt;
&lt;br /&gt;</description></item><item><title>Re: Unproject() Insanity</title><link>http://forums.xna.com/forums/thread/70238.aspx</link><pubDate>Sat, 21 Jun 2008 01:42:12 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:70238</guid><dc:creator>x3d</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/70238.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=56&amp;PostID=70238</wfw:commentRss><description>Thanks a lot for making this topic, I&amp;#39;ve spent ages figuring out what was wrong with my unproject code.&lt;br /&gt;</description></item><item><title>Re: Unproject() Insanity</title><link>http://forums.xna.com/forums/thread/70055.aspx</link><pubDate>Fri, 20 Jun 2008 09:22:12 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:70055</guid><dc:creator>testi</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/70055.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=56&amp;PostID=70055</wfw:commentRss><description>Thank you very much dexy - you really saved me some trouble.
&lt;p&gt;
&lt;p&gt;I changed the code a little, so the method is an extension of viewport with the same parameters as Viewport.Unproject(). Now you have to simply change your call from m_viewport.Unproject(...) to m_viewport.UnprojectEx(...). (...and copy the following class in your namespace of course)&lt;/p&gt;
&lt;div style="overflow:auto;background-color:white;width:100%;height:259px;font-family:Courier New;font-size:11px;"&gt;
&lt;table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;" cellpadding="0" cellspacing="0"&gt;
    
    
        &lt;tr&gt;
            &lt;td&gt;&lt;font style="font-size:11px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font style="color:blue;"&gt;public&lt;/font&gt;&lt;font style="font-size:11px;"&gt;&amp;nbsp;&lt;/font&gt;&lt;font style="color:blue;"&gt;static&lt;/font&gt;&lt;font style="font-size:11px;"&gt;&amp;nbsp;&lt;/font&gt;&lt;font style="color:blue;"&gt;class&lt;/font&gt;&lt;font style="font-size:11px;"&gt;&amp;nbsp;ViewportExtension&amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font style="color:blue;"&gt;public&lt;/font&gt;&lt;font style="font-size:11px;"&gt;&amp;nbsp;&lt;/font&gt;&lt;font style="color:blue;"&gt;static&lt;/font&gt;&lt;font style="font-size:11px;"&gt;&amp;nbsp;Vector3&amp;nbsp;UnprojectEx(&lt;/font&gt;&lt;font style="color:blue;"&gt;this&lt;/font&gt;&lt;font style="font-size:11px;"&gt;&amp;nbsp;Viewport&amp;nbsp;viewport,&amp;nbsp;Vector3&amp;nbsp;screenSpace,&amp;nbsp;Matrix&amp;nbsp;projection,&amp;nbsp;Matrix&amp;nbsp;view,&amp;nbsp;Matrix&amp;nbsp;world)&amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font style="color:green;"&gt;//First,&amp;nbsp;convert&amp;nbsp;raw&amp;nbsp;screen&amp;nbsp;coords&amp;nbsp;to&amp;nbsp;unprojectable&amp;nbsp;ones&lt;/font&gt;&lt;font style="font-size:11px;"&gt;&amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vector3&amp;nbsp;position&amp;nbsp;=&amp;nbsp;&lt;font style="color:blue;"&gt;new&lt;/font&gt;&lt;font style="font-size:11px;"&gt;&amp;nbsp;Vector3();&amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;position.X&amp;nbsp;=&amp;nbsp;(((screenSpace.X&amp;nbsp;-&amp;nbsp;(&lt;font style="color:blue;"&gt;float&lt;/font&gt;&lt;font style="font-size:11px;"&gt;)viewport.X)&amp;nbsp;/&amp;nbsp;((&lt;/font&gt;&lt;font style="color:blue;"&gt;float&lt;/font&gt;&lt;font style="font-size:11px;"&gt;)viewport.Width))&amp;nbsp;*&amp;nbsp;2f)&amp;nbsp;-&amp;nbsp;1f;&amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;position.Y&amp;nbsp;=&amp;nbsp;-((((screenSpace.Y&amp;nbsp;-&amp;nbsp;(&lt;font style="color:blue;"&gt;float&lt;/font&gt;&lt;font style="font-size:11px;"&gt;)viewport.Y)&amp;nbsp;/&amp;nbsp;((&lt;/font&gt;&lt;font style="color:blue;"&gt;float&lt;/font&gt;&lt;font style="font-size:11px;"&gt;)viewport.Height))&amp;nbsp;*&amp;nbsp;2f)&amp;nbsp;-&amp;nbsp;1f);&amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;position.Z&amp;nbsp;=&amp;nbsp;(screenSpace.Z&amp;nbsp;-&amp;nbsp;viewport.MinDepth)&amp;nbsp;/&amp;nbsp;(viewport.MaxDepth&amp;nbsp;-&amp;nbsp;viewport.MinDepth);&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font style="color:green;"&gt;//Unproject&amp;nbsp;by&amp;nbsp;transforming&amp;nbsp;the&amp;nbsp;4d&amp;nbsp;vector&amp;nbsp;by&amp;nbsp;the&amp;nbsp;inverse&amp;nbsp;of&amp;nbsp;the&amp;nbsp;projecttion&amp;nbsp;matrix,&amp;nbsp;followed&amp;nbsp;by&amp;nbsp;the&amp;nbsp;inverse&amp;nbsp;of&amp;nbsp;the&amp;nbsp;view&amp;nbsp;matrix.&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font style="font-size:11px;"&gt;&amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vector4&amp;nbsp;us4&amp;nbsp;=&amp;nbsp;&lt;font style="color:blue;"&gt;new&lt;/font&gt;&lt;font style="font-size:11px;"&gt;&amp;nbsp;Vector4(position,&amp;nbsp;1f);&amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vector4&amp;nbsp;up4&amp;nbsp;=&amp;nbsp;Vector4.Transform(us4,&amp;nbsp;&amp;nbsp;Matrix.Invert(Matrix.Multiply(Matrix.Multiply(world,&amp;nbsp;view),&amp;nbsp;projection)));&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vector3&amp;nbsp;up3&amp;nbsp;=&amp;nbsp;&lt;font style="color:blue;"&gt;new&lt;/font&gt;&lt;font style="font-size:11px;"&gt;&amp;nbsp;Vector3(up4.X,&amp;nbsp;up4.Y,&amp;nbsp;up4.Z);&amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font style="color:blue;"&gt;return&lt;/font&gt;&lt;font style="font-size:11px;"&gt;&amp;nbsp;up3&amp;nbsp;/&amp;nbsp;up4.W;&amp;nbsp;&lt;/font&gt;&lt;font style="color:green;"&gt;//better&amp;nbsp;to&amp;nbsp;do&amp;nbsp;this&amp;nbsp;here&amp;nbsp;to&amp;nbsp;reduce&amp;nbsp;precision&amp;nbsp;loss..&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font style="font-size:11px;"&gt;&amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
    
&lt;/table&gt;
&lt;/div&gt;
&lt;/p&gt;</description></item><item><title>Re: Unproject() Insanity</title><link>http://forums.xna.com/forums/thread/67353.aspx</link><pubDate>Sun, 08 Jun 2008 11:42:56 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:67353</guid><dc:creator>Ronzan</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/67353.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=56&amp;PostID=67353</wfw:commentRss><description>&lt;p&gt;Thanks dexy!&lt;/p&gt;
&lt;p&gt;I had this problem and raised&amp;nbsp;the question&amp;nbsp;long time ago but gave up on it when I found the same issue with the Picking Sample.&lt;br /&gt;
&lt;br /&gt;
However,&amp;nbsp;your code&amp;nbsp;didn&amp;#39;t work (for me!) with the Z screen coordinate thing (farClip * 10) - but changing it to 1f made it work just fine.&lt;/p&gt;
&lt;div style="BORDER-RIGHT:#7f9db9 1px solid;BORDER-TOP:#7f9db9 1px solid;FONT-SIZE:11px;OVERFLOW:auto;BORDER-LEFT:#7f9db9 1px solid;WIDTH:100%;BORDER-BOTTOM:#7f9db9 1px solid;FONT-FAMILY:Courier New;HEIGHT:34px;BACKGROUND-COLOR:white;"&gt;
&lt;table style="BORDER-TOP-WIDTH:0px;BORDER-LEFT-WIDTH:0px;MARGIN:2px 0px;WIDTH:99%;BORDER-BOTTOM:#eee 0px solid;BORDER-COLLAPSE:collapse;BACKGROUND-COLOR:#fff;BORDER-RIGHT-WIDTH:0px;" cellspacing="0" cellpadding="0"&gt;
    
    
    
        &lt;tr&gt;
            &lt;td&gt;&lt;font style="FONT-SIZE:11px;"&gt;&lt;font color="#0000ff"&gt;Vector3&lt;/font&gt;&amp;nbsp;screenFar&amp;nbsp;=&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;new&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;Vector3((&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;float&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;)x,&amp;nbsp;(&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;float&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;)y,&amp;nbsp;&lt;strong&gt;1f&lt;/strong&gt;);&amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
    
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;So far I have only tested it quickly, but when using the built in UnProject I could reproduce the bug easily - with your code I have been trying for 10-15mins without seeing the bug.&lt;br /&gt;
&lt;br /&gt;
Thanks a bunch!&lt;br /&gt;
Now I can finally get some picking done in my test engine :)&lt;/p&gt;
&lt;p&gt;/Ronzan&lt;/p&gt;</description></item><item><title>Re: Unproject() Insanity</title><link>http://forums.xna.com/forums/thread/66552.aspx</link><pubDate>Wed, 04 Jun 2008 12:30:56 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:66552</guid><dc:creator>dexy</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/66552.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=56&amp;PostID=66552</wfw:commentRss><description>&lt;p&gt;Thankyou everyone for replying.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve been a bit busy, bit i got back on to 3d stuff last week. I&amp;#39;ve been playing around with a&amp;nbsp;generic octree, go figure.&lt;/p&gt;
&lt;p&gt;So I implemented a method to get a list of octree nodes currently under the mouse cursor (hello Unproject()!). I just plugged in my unproject method and it seems to be working well, at least for areas close to the origin.&lt;/p&gt;
&lt;p&gt;In reply to the posts:&lt;/p&gt;
&lt;p&gt;Pike - The method I posted above (and the one I&amp;#39;m going to include below) both have the input in pixel coordinates (x and y are&amp;nbsp;0 - screen res), so the method scales this to -1 to +1. The Z input coord however is between 0 and 1 (0=near, 1=far).&lt;/p&gt;
&lt;p&gt;Ligren - Perhaps you are running into the inaccuracy issue I found, which I think I may have a solution for - dividing by W after the projection inverse&amp;nbsp;transform and before the inverse view one. This way it gets rid of the&amp;nbsp;&amp;#39;d approaching epsilon&amp;#39; problem that can happen with different view transforms... (I think...)&lt;/p&gt;
&lt;p&gt;Shawn -&amp;nbsp;Cool, thanks!&lt;/p&gt;
&lt;p&gt;MissileControl - I did find pushing&amp;nbsp;the near clip plane out can help with precision issues, I think I have it at 0.5 at present. 1 might be sensible, but I like getting close to objects. I might consider a secondary transform for close objects.&lt;/p&gt;
&lt;p&gt;And finally here&amp;#39;s a copy of my current method:&lt;/p&gt;
&lt;div style="BORDER-RIGHT:#7f9db9 1px solid;BORDER-TOP:#7f9db9 1px solid;FONT-SIZE:11px;OVERFLOW:auto;BORDER-LEFT:#7f9db9 1px solid;WIDTH:100%;BORDER-BOTTOM:#7f9db9 1px solid;FONT-FAMILY:Courier New;HEIGHT:258px;BACKGROUND-COLOR:white;"&gt;
&lt;table style="BORDER-TOP-WIDTH:0px;BORDER-LEFT-WIDTH:0px;MARGIN:2px 0px;WIDTH:99%;BORDER-BOTTOM:#eee 0px solid;BORDER-COLLAPSE:collapse;BACKGROUND-COLOR:#fff;BORDER-RIGHT-WIDTH:0px;" cellspacing="0" cellpadding="0"&gt;
    
    
    
        &lt;tr&gt;
            &lt;td&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;public&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;static&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;Vector3&amp;nbsp;Unproject(Camera&amp;nbsp;camera,&amp;nbsp;Vector3&amp;nbsp;screenSpace) &amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="BACKGROUND-COLOR:#f7f7f7;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{ &amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:green;"&gt;//First,&amp;nbsp;convert&amp;nbsp;raw&amp;nbsp;screen&amp;nbsp;coords&amp;nbsp;to&amp;nbsp;unprojectable&amp;nbsp;ones &lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="BACKGROUND-COLOR:#f7f7f7;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Viewport&amp;nbsp;port&amp;nbsp;=&amp;nbsp;camera.Viewport; &amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vector3&amp;nbsp;position&amp;nbsp;=&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;new&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;Vector3(); &amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="BACKGROUND-COLOR:#f7f7f7;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;position.X&amp;nbsp;=&amp;nbsp;(((screenSpace.X&amp;nbsp;-&amp;nbsp;(&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;float&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;)port.X)&amp;nbsp;/&amp;nbsp;((&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;float&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;)port.Width))&amp;nbsp;*&amp;nbsp;2f)&amp;nbsp;-&amp;nbsp;1f; &amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;position.Y&amp;nbsp;=&amp;nbsp;-((((screenSpace.Y&amp;nbsp;-&amp;nbsp;(&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;float&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;)port.Y)&amp;nbsp;/&amp;nbsp;((&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;float&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;)port.Height))&amp;nbsp;*&amp;nbsp;2f)&amp;nbsp;-&amp;nbsp;1f); &amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="BACKGROUND-COLOR:#f7f7f7;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;position.Z&amp;nbsp;=&amp;nbsp;(screenSpace.Z&amp;nbsp;-&amp;nbsp;port.MinDepth)&amp;nbsp;/&amp;nbsp;(port.MaxDepth&amp;nbsp;-&amp;nbsp;port.MinDepth); &amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="BACKGROUND-COLOR:#f7f7f7;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:green;"&gt;//Unproject&amp;nbsp;by&amp;nbsp;transforming&amp;nbsp;the&amp;nbsp;4d&amp;nbsp;vector&amp;nbsp;by&amp;nbsp;the&amp;nbsp;inverse&amp;nbsp;of&amp;nbsp;the&amp;nbsp;projecttion&amp;nbsp;matrix,&amp;nbsp;followed&amp;nbsp;by&amp;nbsp;the&amp;nbsp;inverse&amp;nbsp;of&amp;nbsp;the&amp;nbsp;view&amp;nbsp;matrix. &lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vector4&amp;nbsp;us4&amp;nbsp;=&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;new&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;Vector4(position,&amp;nbsp;1f); &amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="BACKGROUND-COLOR:#f7f7f7;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vector4&amp;nbsp;up4&amp;nbsp;=&amp;nbsp;Vector4.Transform(us4,&amp;nbsp;camera.ProjectionMatrixInverse); &amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vector3&amp;nbsp;up3&amp;nbsp;=&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;new&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;Vector3(up4.X,&amp;nbsp;up4.Y,&amp;nbsp;up4.Z); &amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="BACKGROUND-COLOR:#f7f7f7;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;up3&amp;nbsp;=&amp;nbsp;up3&amp;nbsp;/&amp;nbsp;up4.W;&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:green;"&gt;//better&amp;nbsp;to&amp;nbsp;do&amp;nbsp;this&amp;nbsp;here&amp;nbsp;to&amp;nbsp;reduce&amp;nbsp;precision&amp;nbsp;loss.. &lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vector3&amp;nbsp;uv3&amp;nbsp;=&amp;nbsp;Vector3.Transform(up3,&amp;nbsp;camera.ViewMatrixInverse); &amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="BACKGROUND-COLOR:#f7f7f7;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;return&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;(uv3); &amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;}&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
    
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;And this method is very useful! It may be the source of some people&amp;#39;s problems:&lt;/p&gt;
&lt;div style="BORDER-RIGHT:#7f9db9 1px solid;BORDER-TOP:#7f9db9 1px solid;FONT-SIZE:11px;OVERFLOW:auto;BORDER-LEFT:#7f9db9 1px solid;WIDTH:100%;BORDER-BOTTOM:#7f9db9 1px solid;FONT-FAMILY:Courier New;HEIGHT:300px;BACKGROUND-COLOR:white;"&gt;
&lt;table style="BORDER-TOP-WIDTH:0px;BORDER-LEFT-WIDTH:0px;MARGIN:2px 0px;WIDTH:99%;BORDER-BOTTOM:#eee 0px solid;BORDER-COLLAPSE:collapse;BACKGROUND-COLOR:#fff;BORDER-RIGHT-WIDTH:0px;" cellspacing="0" cellpadding="0"&gt;
    
    
    
        &lt;tr&gt;
            &lt;td&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;public&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;static&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;Ray&amp;nbsp;UnprojectPoint(Camera&amp;nbsp;camera,&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;int&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;x,&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;int&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;y) &amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="BACKGROUND-COLOR:#f7f7f7;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{ &amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="BACKGROUND-COLOR:#f7f7f7;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vector3&amp;nbsp;screenNear&amp;nbsp;=&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;new&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;Vector3((&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;float&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;)x,&amp;nbsp;(&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;float&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;)y,&amp;nbsp;0f); &amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vector3&amp;nbsp;screenFar&amp;nbsp;=&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;new&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;Vector3((&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;float&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;)x,&amp;nbsp;(&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;float&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;)y,&amp;nbsp;camera.FarClippingPlane&amp;nbsp;*&amp;nbsp;10f);&amp;nbsp; &amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="BACKGROUND-COLOR:#f7f7f7;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:green;"&gt;//multiplying&amp;nbsp;by&amp;nbsp;10&amp;nbsp;makes&amp;nbsp;sure&amp;nbsp;the&amp;nbsp;line&amp;#39;s&amp;nbsp;direction&amp;nbsp;is&amp;nbsp;accurate&amp;nbsp;-&amp;nbsp;by&amp;nbsp;casting&amp;nbsp;out&amp;nbsp; &lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:green;"&gt;//a&amp;nbsp;very&amp;nbsp;far&amp;nbsp;distance.&amp;nbsp;The&amp;nbsp;direction&amp;nbsp;is&amp;nbsp;all&amp;nbsp;we&amp;nbsp;really&amp;nbsp;care&amp;nbsp;about,&amp;nbsp;so&amp;nbsp;the&amp;nbsp;further &lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="BACKGROUND-COLOR:#f7f7f7;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:green;"&gt;//away&amp;nbsp;the&amp;nbsp;point,&amp;nbsp;the&amp;nbsp;more&amp;nbsp;accurate&amp;nbsp;it&amp;nbsp;will&amp;nbsp;be.... &lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vector3&amp;nbsp;worldNear&amp;nbsp;=&amp;nbsp;Unproject(camera,&amp;nbsp;screenNear); &amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="BACKGROUND-COLOR:#f7f7f7;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vector3&amp;nbsp;worldFar&amp;nbsp;=&amp;nbsp;Unproject(camera,&amp;nbsp;screenFar); &amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Vector3&amp;nbsp;direction&amp;nbsp;=&amp;nbsp;worldFar&amp;nbsp;-&amp;nbsp;worldNear; &amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="BACKGROUND-COLOR:#f7f7f7;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;float&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;len&amp;nbsp;=&amp;nbsp;1f&amp;nbsp;/&amp;nbsp;direction.Length(); &amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;direction&amp;nbsp;=&amp;nbsp;direction&amp;nbsp;*&amp;nbsp;len;&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:green;"&gt;//manual&amp;nbsp;normalisation &lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="BACKGROUND-COLOR:#f7f7f7;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Ray&amp;nbsp;r&amp;nbsp;=&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;new&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;Ray(worldNear,&amp;nbsp;direction); &amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="BACKGROUND-COLOR:#f7f7f7;"&gt;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font style="COLOR:blue;"&gt;return&lt;/font&gt;&lt;font style="FONT-SIZE:11px;"&gt;&amp;nbsp;(r); &amp;nbsp;&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="BACKGROUND-COLOR:#f7f7f7;"&gt;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="BACKGROUND-COLOR:#f7f7f7;"&gt;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
    
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;Then you can just feed in the x and y coords and there&amp;#39;s your mouse ray! In reality, the screen&amp;nbsp;Z coord for the far point unproject&amp;nbsp;doesn&amp;#39;t really matter as long as it&amp;#39;s big.&amp;nbsp;It could do with further testing, so if anyone uses this, I&amp;#39;d love to know!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;dexy&lt;/p&gt;</description></item><item><title>Re: Unproject() Insanity</title><link>http://forums.xna.com/forums/thread/63736.aspx</link><pubDate>Fri, 23 May 2008 14:42:00 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:63736</guid><dc:creator>MissileControl</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/63736.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=56&amp;PostID=63736</wfw:commentRss><description>When you set up your projection matrix, where is your near plane?
&lt;p&gt;I&amp;#39;m wondering if your failure to obtain a correct value from the Viewport.Unproject may be related to a too small near plane value.&amp;nbsp; Take a look at this link... http://www.sjbaker.org/steve/omniv/love_your_z_buffer.html&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;In my case, I was originally using a model scaled down to 1/100th the original size... so my near plane was set to 0.1...&amp;nbsp; With this setup my collision code was perfect, but due to some other changes I had to stop scaling my models.&amp;nbsp; After I stopped scaling my models, I noticed that my collision code wasn&amp;#39;t working...&amp;nbsp; Larger models should be easyier to collide against right? wrong...&amp;nbsp; because my models where larger I had increased my rate of movement and moved my far plane out so that my models wouldn&amp;#39;t get clipped at the back end, which meant that I would be farther away from the models when I perform a triangle intersection test.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;A simple test that I did was to first test my triangle picking code w/ a near plane of 0.01...&amp;nbsp; which was really bad... couldn&amp;#39;t collide a against anything.&amp;nbsp; I then tried 0.1...&amp;nbsp; things worked better, but it would be off at times...&amp;nbsp; I increased it to 1 and was able to collide accurately 100% of the time.&lt;/p&gt;
&lt;/p&gt;
&lt;/p&gt;
&amp;nbsp;My advise... move your near plane out farther and see if that fixes things.&lt;br /&gt;</description></item><item><title>Re: Unproject() Insanity</title><link>http://forums.xna.com/forums/thread/61816.aspx</link><pubDate>Wed, 14 May 2008 11:54:20 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:61816</guid><dc:creator>Shawn Hargreaves</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/61816.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=56&amp;PostID=61816</wfw:commentRss><description>Don't worry, we have this bug in our internal database (I just checked).&lt;br&gt;</description></item><item><title>Re: Unproject() Insanity</title><link>http://forums.xna.com/forums/thread/61792.aspx</link><pubDate>Wed, 14 May 2008 09:00:36 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:61792</guid><dc:creator>lidgren</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/61792.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=56&amp;PostID=61792</wfw:commentRss><description>Sorry dexy, but i'm getting the exact same result from your method as I do from Xna (... since they're almost the same). We still use the old MDX Unproject() to get correct behaviour, but it's an ugly dependency I'd like to get rid of.</description></item><item><title>Re: Unproject() Insanity</title><link>http://forums.xna.com/forums/thread/61788.aspx</link><pubDate>Wed, 14 May 2008 06:22:01 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:61788</guid><dc:creator>PikeTheHuman</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/61788.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=56&amp;PostID=61788</wfw:commentRss><description>All these methods seem to assume (unless I'm missing something) pixel based screen coordinates with positive right and down, upper-left being 0,0 and lower-right being something like 1024,768.&amp;nbsp; Shouldn't they be using screen space, with positive right and up and bounds -1 to +1?&lt;br&gt;&lt;br&gt;&lt;br&gt;</description></item><item><title>Re: Unproject() Insanity</title><link>http://forums.xna.com/forums/thread/57608.aspx</link><pubDate>Thu, 17 Apr 2008 06:39:49 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:57608</guid><dc:creator>dexy</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/57608.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=56&amp;PostID=57608</wfw:commentRss><description>&lt;P&gt;Well, it only took a week of my spare time, but I fixed it. All by myself!&lt;/P&gt;
&lt;P&gt;After implementing my old matrix class because I thought maybe the XNA matrix inversion wasnt working properly, I sighed, because it returned the same result as with the XNA invert.&lt;/P&gt;
&lt;P&gt;So back to the drawing board.. I tried what Kris suggested, but it returned results&amp;nbsp;almost identical&amp;nbsp;to the Viewport.Unproject() [not much surprise because really it is very similar to Viewport.Unproject]. I fiddled more with the way the matrices were concatenated... trying with all multiplied together first and inverting, and trying with all inverses multiplied in reverse order... both returning different, incorrect, results. Really I would have expected them all to return the same thing (they look correct to me! Somehow this was not the case).&lt;/P&gt;
&lt;P&gt;And thats when it all flashed back to me. I read my earlier post in here where I said I had to do something with the W values. OF COURSE!! I remembered reading, while I was learning about how to perform a matrix inversion (a while ago), that when unprojecting you have to use 4-component vectors...!!!!! And then after you have transformed your 4d vector, to convert it into the 3d one you simply divide by W. And that's what the "float a=..." is&amp;nbsp;in the Viewport.Unproject.&lt;/P&gt;
&lt;P&gt;AND IT WORKS PERFECTLY.&lt;/P&gt;
&lt;P&gt;So here is my very own Unproject method!! Working much much much better than Viewport.Unproject().&lt;/P&gt;
&lt;DIV style="BACKGROUND-COLOR:white;"&gt;
&lt;DIV style="PADDING-RIGHT:2px;OVERFLOW-Y:hidden;PADDING-LEFT:8px;PADDING-BOTTOM:2px;MARGIN:0px;OVERFLOW:scroll;WIDTH:505px;PADDING-TOP:2px;BACKGROUND-COLOR:white;"&gt;&lt;PRE&gt;&lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:black;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;        &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:blue;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;public&lt;/SPAN&gt; &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:blue;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;static&lt;/SPAN&gt; Vector3 UnprojectD(Camera camera, Vector3 screenSpace)&lt;BR&gt;        {&lt;BR&gt;&lt;BR&gt;            Viewport port &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;=&lt;/SPAN&gt; camera.Viewport;&lt;BR&gt;&lt;BR&gt;            Vector3 position &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;=&lt;/SPAN&gt; &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:blue;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;new&lt;/SPAN&gt; Vector3();&lt;BR&gt;            position.X &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;=&lt;/SPAN&gt; (((screenSpace.X &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;-&lt;/SPAN&gt; port.X) &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;/&lt;/SPAN&gt; ((&lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:blue;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;float&lt;/SPAN&gt;)port.Width)) &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;*&lt;/SPAN&gt; 2f) &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;-&lt;/SPAN&gt; 1f;&lt;BR&gt;            position.Y &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;=&lt;/SPAN&gt; &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;-&lt;/SPAN&gt;((((screenSpace.Y &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;-&lt;/SPAN&gt; port.Y) &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;/&lt;/SPAN&gt; ((&lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:blue;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;float&lt;/SPAN&gt;)port.Height)) &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;*&lt;/SPAN&gt; 2f) &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;-&lt;/SPAN&gt; 1f);&lt;BR&gt;            position.Z &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;=&lt;/SPAN&gt; (screenSpace.Z &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;-&lt;/SPAN&gt; port.MinDepth) &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;/&lt;/SPAN&gt; (port.MaxDepth &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;-&lt;/SPAN&gt; port.MinDepth);&lt;BR&gt;&lt;BR&gt;            Vector4 us4 &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;=&lt;/SPAN&gt; &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:blue;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;new&lt;/SPAN&gt; Vector4(position, 1f);&lt;BR&gt;            Vector4 up4 &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;=&lt;/SPAN&gt; Vector4.Transform(us4, camera.ProjectionMatrixInverse);&lt;BR&gt;            Vector4 uv4 &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;=&lt;/SPAN&gt; Vector4.Transform(up4, camera.ViewMatrixInverse);&lt;BR&gt;&lt;BR&gt;            Vector3 uv3 &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;=&lt;/SPAN&gt; &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:blue;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;new&lt;/SPAN&gt; Vector3(uv4.X, uv4.Y, uv4.Z);&lt;BR&gt;            uv3 &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;=&lt;/SPAN&gt; uv3 &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;/&lt;/SPAN&gt; uv4.W;&lt;BR&gt;&lt;BR&gt;            &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:blue;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;return&lt;/SPAN&gt; (uv3);&lt;BR&gt;}&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;So there it is. The method itself doesn't do any matrix inversions so it should be much faster than the original. It does however require the view and projection matrices to be already available in inverted form. My camera class is doing this whenever the view or projection matrices are updated (respectively). I think this ends up&amp;nbsp;with the minimum of processor wasteage. Note the input vector is scaled without a scaling matrix, this is probably faster than using a matrix for this particular calculation. port.MinDepth and MaxDepth are usually 0 and 1, so really the Z part of the scaling does nothing and could probably be removed.&lt;/P&gt;
&lt;P&gt;GO ME!!! (also thanks to anyone else who put any time into this! :)&lt;/P&gt;
&lt;P&gt;-dexy&lt;/P&gt;</description></item><item><title>Re: Unproject() Insanity</title><link>http://forums.xna.com/forums/thread/57587.aspx</link><pubDate>Wed, 16 Apr 2008 23:35:23 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:57587</guid><dc:creator>dexy</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/57587.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=56&amp;PostID=57587</wfw:commentRss><description>&lt;P&gt;David,&lt;/P&gt;
&lt;P&gt;That's what I initially thought "Closed (By Design)" meant. So I posted a comment in the connect area about how I couldn't possibly understand how this behaviour is "By Design" because I can't get it to return any sort of useable result at all. If someone can show me how to get a correct mouse ray in world coords with this method I will retract my comments. Until then I won't believe the method is working properly.&lt;/P&gt;
&lt;P&gt;Also thanks ZMan, I probably should have gone researching about that before hand. But I still don't understand how the issue got it's current status, I guess because no-one voted for it (because how many people would be using unproject in XNA!? Not many! Most would be using XNA to make little games for their XBOX, which would have no use for Unproject.)&lt;/P&gt;
&lt;P&gt;And if this behaviour really is "By Design", then I want to know how to use the method properly!! The examples seem to be using Unproject in the same way as in XNA GSE. And given these functions return different results between 1.0 and 2.0 of XNA, I can't see how the examples are valid. Anyway the samples don't work properly, they suffer the same problem as when I use Viewport.Unproject.&lt;/P&gt;</description></item><item><title>Re: Unproject() Insanity</title><link>http://forums.xna.com/forums/thread/57575.aspx</link><pubDate>Wed, 16 Apr 2008 21:51:58 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:57575</guid><dc:creator>The ZMan</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/57575.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=56&amp;PostID=57575</wfw:commentRss><description>See this thread for bug status mesages &lt;A href="http://forums.xna.com/thread/27521.aspx"&gt;http://forums.xna.com/thread/27521.aspx&lt;/A&gt;&amp;nbsp;(find reply by mitch walker)</description></item><item><title>Re: Unproject() Insanity</title><link>http://forums.xna.com/forums/thread/57573.aspx</link><pubDate>Wed, 16 Apr 2008 21:49:00 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:57573</guid><dc:creator>David Hunt</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/57573.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=56&amp;PostID=57573</wfw:commentRss><description>&lt;P&gt;"Closed (By Design)" is a different thing entirely. That means that it's working the way they intended it to and don't plan to change it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description></item><item><title>Re: Unproject() Insanity</title><link>http://forums.xna.com/forums/thread/57571.aspx</link><pubDate>Wed, 16 Apr 2008 21:41:53 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:57571</guid><dc:creator>dexy</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/57571.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=56&amp;PostID=57571</wfw:commentRss><description>&lt;P&gt;Thanks for the replies...&lt;/P&gt;
&lt;P&gt;I was a little confused about the status "Closed (By Design)" on the connect issue. I guess it's just wording that I'm not used to.&lt;/P&gt;
&lt;P&gt;Obviously I can't wait for someone to change the XNA framework Viewport.Unproject, so I will have to persist with my own method.&lt;/P&gt;
&lt;P&gt;Kris, I'll try your suggestions tonight, but somehow I don't think the results will be any different from my current implementation...&lt;/P&gt;
&lt;P&gt;Example: My camera can be rotated and translated using keyboard and mouse. I am unprojecting a point at the bottom right of the screen, and using screenSpace.Z=0. I then draw an object at that point in the world (my world matrix is just identity). The object is drawn in the correct position, far more accurately than if using Viewport.Unproject(). The problem is, that when I specify screenSpace.Z=1, it returns the same point, as if Z=0 (the point on the near plane).&lt;/P&gt;
&lt;P&gt;I'll try concatenating the matrices first, then inverting. But somehow I don't think it will make any difference. I seem to remember when learning about matrices that you need to use a W value when using the projection inverse matrix..? I'm really not sure.&lt;/P&gt;
&lt;P&gt;-dexy&lt;/P&gt;</description></item></channel></rss>