在direct3d中使用鼠标点击选择对象(托管directx)

时间:2014-07-01 04:33:25

标签: directx direct3d

基本上我想在direct3d(托管directx)C#中使用鼠标点击选择一个对象。 我需要将2D点转换为3D点。谷歌搜索后,我发现,我可以使用采摘 或射线。这是一个使用光线的例子 http://msdn.microsoft.com/en-us/library/bb203905.aspx

我的问题,如果我实现光线是我在direct3d找不到GraphicsDevice.Viewport.Unproject。 如果还有其他解决方案,请告诉我。

更新

这就是我所做的:

protected override void OnMouseClick(MouseEventArgs e)
    {
        base.OnMouseClick(e);
        int x = e.X;
        int y = e.Y;
        Vector3 nearsource = new Vector3((float)x, (float)y, 0f);
        Vector3 farsource = new Vector3((float)x, (float)y, 1f);

        nearsource.Unproject(device.Viewport, device.Transform.Projection, device.Transform.View,device.Transform.World);
        farsource.Unproject(device.Viewport, device.Transform.Projection, device.Transform.View, device.Transform.World);
        Vector3 direction=nearsource-farsource;
        direction.Normalize();
        }

问题是farsouce矩阵具有NaN值

1 个答案:

答案 0 :(得分:0)

Managed DirectX已被弃用了很长时间。我建议使用更好的支持API,如SlimDX。

一个小小的谷歌搜索显示this thread,这似乎是你想要的SlimDX。

相关问题