Camera 相机(LootkAt+;正交投影)不';我不想工作[SlimDX/D3D9]

Camera 相机(LootkAt+;正交投影)不';我不想工作[SlimDX/D3D9],camera,directx,direct3d,slimdx,Camera,Directx,Direct3d,Slimdx,我真的不明白“摄像机”是如何与D3D9配合工作的 首先,我如何设置我的相机: public Camera() { this.eye = new Vector3(0.0f, 0.0f, 0.0f); this.lookAt = new Vector3(0.0f, 0.0f, 1.0f); this.up = new Vector3(0.0f, 1.0f, 0.0f); viewMatrix = Matrix.Look

我真的不明白“摄像机”是如何与D3D9配合工作的

首先,我如何设置我的相机:

     public Camera()
    {
        this.eye = new Vector3(0.0f, 0.0f, 0.0f);
        this.lookAt = new Vector3(0.0f, 0.0f, 1.0f);
        this.up = new Vector3(0.0f, 1.0f, 0.0f);
        viewMatrix = Matrix.LookAtLH(eye, lookAt, up);
        projectionMatrix = Matrix.OrthoLH(1 * zoomLevel, 1 * zoomLevel, 0.0f, 1.0f);
    }
和我的顶点:

        vertices = new VertexTexture[]
        {
            new VertexTexture()
            {
                Position =  new Vector4(0.0f, 0.0f, 0.0f, 1.0f),
                TextureCoord = new Vector2(0.0f, 1.0f)
            },
            new VertexTexture()
            {
                Position =  new Vector4(0.0f, model.Height, 0.0f, 1.0f),
                TextureCoord = new Vector2(0.0f, 0.0f)
            },
            new VertexTexture()
            {
                Position =  new Vector4(model.Width, model.Height, 0.0f, 1.0f),
                TextureCoord = new Vector2(1.0f, 0.0f)
            },
            new VertexTexture()
            {
                Position =  new Vector4(model.Width, 0.0f, 0.0f, 1.0f),
                TextureCoord = new Vector2(1.0f, 1.0f)
            }
        };
它起作用了。我可以移动相机、变焦等

但是相机的属性在我看来很奇怪!我以为会是这样的:

    public Camera()
    {
        this.eye = new Vector3(0.0f, 0.0f, 1.0f);
        this.lookAt = new Vector3(0.0f, 0.0f, 0.0f);
        this.up = new Vector3(0.0f, 1.0f, 0.0f);
        viewMatrix = Matrix.LookAtLH(eye, lookAt, up);
        projectionMatrix = Matrix.OrthoLH(1 * zoomLevel, 1 * zoomLevel, 0.1f, 100.0f);
    }
但有了这些参数,它就不起作用了。如果更改计划的Z坐标(需要设置为0才能工作),则相同

现在,我尝试渲染其他对象。我为一个球体生成顶点(它在D3D10上运行良好,一个围绕(0;0;0)生成的1半径球体),但屏幕上没有显示任何内容


我玩过eye和lookat参数,但我能想出如何使其工作,所以,我做错了什么?

首先,一些背景。在正交投影中,我们技术上不需要Z坐标变换,但事实上D3D系统并不关心您使用哪种投影-对于设备来说,它只是一个变换矩阵,仅此而已。因此,Z坐标始终变换为,而与投影类型无关。另一方面,摄像机坐标不是通过投影矩阵变换的(否则定位将是一场噩梦)。现在让我们回到你的处境,看看发生了什么

OrthoLH
中指定zn=0.1f,表示这是最小深度。因此,每个顶点将在深度上移动-0.1f。变换顶点布局后,Z将为0.9f,但您记得摄影机不受影响吗?所以,它仍然在1.0f的深度,这就是为什么你什么也看不到:相机后面没有顶点


在这里添加浮点计算错误,您将理解为什么将相机设置为0.9f有时有用,有时无效。不过,将位置设置为0.8f将适用于任何情况。

首先,感谢您的回答。 我通过设置相机的以下属性来避免问题:

        this.eye = new Vector3(0.0f, 0.0f, 0.0f);
        this.lookAt = new Vector3(0.0f, 0.0f, 1.0f);
        this.up = new Vector3(0.0f, 1.0f, 0.0f);

        viewMatrix = Matrix.LookAtLH(eye, lookAt, up);
        projectionMatrix = Matrix.OrthoLH(1 * zoomLevel, 1 * zoomLevel, 0.0f, 10000000.0f);    :D
我会再读一遍你说的话,然后想一个最好的办法:)

我认为我的问题与我的顶点有关。。。例如,我生成一个半径为20的球体,然后根据屏幕坐标缩放,将这些顶点变换为对应于一个20px宽的球体

        worldMatrix = SlimDX.Matrix.Identity;
        worldMatrix = SlimDX.Matrix.Scaling(new Vector3(2.0f / ControlWidth, 2.0f / ControlHeight, 1.0f));
        worldMatrix = SlimDX.Matrix.Multiply(worldMatrix, SlimDX.Matrix.Translation(new Vector3(-1.0f, -1.0f, 0.0f)));
我的X/Y缩放正常。但是如何缩放Z坐标呢?2.0/((控制高度+控制宽度)/2)


我将再次阅读您的Anzer,以了解所有内容:)

在缩放中,使用与X/Y相同的方法是无害的。所描述的问题仅涉及偏移(特别是顶点的Z坐标)。将“eye”放置在Z=0.0、zn=0.0和顶点的非负Z坐标处,可以进行任何变换。