如何将 3D 平面中的点映射到屏幕平面

发布于 2024-12-08 23:05:34 字数 367 浏览 0 评论 0原文

我已经分配了使用 C 语言中的简单图形将 3D 空间中的对象投影到 2D 平面中的任务。问题是,将一个立方体放置在固定的 3D 空间中,并且将相机放置在坐标为x,y,z 并且相机正在查看原点,即 0,0,0。现在我们必须将立方体顶点投影到相机平面上。

我继续执行以下步骤

步骤 1:我找到平面 aX+bY+cZ+d=0 的方程,该方程垂直于从相机位置到原点绘制的线。

步骤2:找到在上述步骤中获得的立方体的每个顶点到平面的投影。

现在我想将步骤 2 中在平面 aX+bY+cZ+d=0 中投影得到的顶点位置映射到我的屏幕平面中。

谢谢,

我不认为让 z 坐标等于 0 会引导我进行实际的映射。所以有任何帮助可以解决这个问题。

I have given an assignment of to project a object in 3D space into a 2D plane using simple graphics in C. The question is that a cube is placed in fixed 3D space and there is camera which is placed in a position whose co-ordinates are x,y,z and the camera is looking at the origin i.e. 0,0,0. Now we have to project the cube vertex into the camera plane.

I am proceeding with the following steps

Step 1: I find the equation of the plane aX+bY+cZ+d=0 which is perpendicular to the line drawn from the camera position to the origin.

Step 2: I find the projection of each vertex of the cube to the plane which is obtained in the above step.

Now I want to map those vertex position which i got by projection in step 2 in the plane aX+bY+cZ+d=0 into my screen plane.

thanks,

I don't think that by letting the z co-ordinate equals zero will lead me to the actual mapping. So any help to figure out this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枕梦 2024-12-15 23:05:34

您可以通过两个简单的步骤来完成此操作:

  1. 将立方体的坐标转换为相机的系统(使用
    旋转),使得相机在该系统中的坐标为 x=y=z=0 并且立方体的平移 z 为 > 0.
  2. 通过将其 x 和 y 除以各自的 z,将平移立方体的坐标投影到二维平面上(您可能需要在此处应用恒定的缩放因子,以使坐标对于屏幕而言合理,例如不要太小且在 +/ 范围内) - 屏幕高度的一半(以像素为单位)。这将产生透视效果。现在,您可以使用这些划分的 x 和 y 在屏幕上绘制像素,假设 x=y=0 是屏幕的中心。

这几乎就是 3D 游戏中的做法。如果使用立方体顶点坐标,则会将其侧面投影到屏幕上。然后,您可以实体填充生成的二维形状或对其进行纹理映射。但为此,您必须首先弄清楚哪些面没有被其他面遮挡(当然,除非您使用一种称为 z 缓冲的技术)。不过,对于简单的线框演示,您不需要它,只需在投影顶点之间绘制直线即可。

You can do that in two simple steps:

  1. Translate the cube's coordinates to the camera's system (using
    rotation), such that the camera's own coordinates in that system are x=y=z=0 and the cube's translated z's are > 0.
  2. Project the translated cube's coordinates onto a 2d plain by dividing its x's and y's by their respective z's (you may need to apply a constant scaling factor here for the coordinates to be reasonable for the screen, e.g. not too small and within +/-half the screen's height in pixels). This will create the perspective effect. You can now draw pixels using these divided x's and y's on the screen assuming x=y=0 is the center of it.

This is pretty much how it is done in 3d games. If you use cube vertex coordinates, then you get projections of its sides onto the screen. You may then solid-fill the resultant 2d shapes or texture-map them. But for that you'll have to first figure out which sides are not obscured by others (unless, of course, you use a technique called z-buffering). You don't need that for a simple wire-frame demo, though, just draw straight lines between the projected vertices.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文