当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - How do I move the camera 1 pixel unit of my window instead of 1 unit in world space in directx11?

问题描述:

I am trying to offset my camera by 1 pixel each frame. So I was wondering how can I make it so my camera translates only 1 pixel length on the X and Y axis instead of an X amount in world space?

网友答案:

In general, you can not offset a camera by "one pixel" in 3D space.

Any motion your camera makes - up, down, right, or left - will make what is currently seen move by a factor relative to how far away each object is, and how many pixels compose the current view window.

Put another way - pixels, as a unit of measurement, don't exist in 3D space.

网友答案:

One way to do this, is in your vertex shader(s), after calculating the homogenous coordinate of the vertex (the 4d point you get by multiplying the vertex by the matrices), you add the offset in pixels, divided by screen width and height, multiplied by the w of your homogenous coordinate.

In other words:

Offset2d = (offsetX / screenWidth, offsetY / screenHeight, 0, 0)

Out = homogenous + offset2d * homogenous.w

Where offsetX and offsetY are in pixels.

I'm sure there's a way to adjust your projection matrix to get the same result, so you don't have to put this in every vertex shader, but haven't worked that out yet.

分享给朋友:
您可能感兴趣的文章:
随机阅读: