开发者

How to Unproject in SlimDX

开发者 https://www.devze.com 2023-02-22 23:47 出处:网络
I am new to game programming as well as new to DirectX & SlimDX. Currenty I am converting a MDX code to SlimDX code and I got stuck into an issue which I am unable to find out in the SlimDX docume

I am new to game programming as well as new to DirectX & SlimDX. Currenty I am converting a MDX code to SlimDX code and I got stuck into an issue which I am unable to find out in the SlimDX documentation. I am trying to "Unproject" a vector code for which is as follows:

MDX code:

Vector3 p1 = ne开发者_如何转开发w Vector3(x, y, device.Viewport.MinZ);
p1.Unproject(device.Viewport, device.Transform.Projection, device.Transform.View, device.Transform.World);

SlimDX code which I converted is as follows:

Vector3 p1 = new Vector3(x, y, device.Viewport.MinZ);
p1 = Vector3.Unproject(p1, device.Viewport.X, device.Viewport.Y, device.Viewport.Width,
device.Viewport.Height, device.Viewport.MinZ, device.Viewport.MaxZ, 
device.GetTransform(TransformState.World));

Using the above SlimDX code I am unable to get the correct results, please advice me on this i.e. how can I Unproject the vector in SlimDX.


I'm not familiar with SlimDX, but in the MDX case you're passing the world, view, and projection matrices to the Unproject function (as you should) and in your second example you're only passing the world matrix. Assuming that Vector3.Unproject function only takes one matrix as an argument, try passing the product of World * View * Projection instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号