物体在 3D 平面上的透视投影

发布于 2024-11-19 09:11:55 字数 277 浏览 5 评论 0原文

想象一下虚拟人和物体之间有一个平面。该对象是一个具有一定 xyz 缩放和旋转的盒子。飞机就像一扇玻璃窗。人通过平面观察物体。摄像机从不同的角度观察整个场景。

我想按照人们看到的方式将物体的轮廓绘制到平面上,就好像他在窗户上绘制另一侧物体的轮廓一样。

如何变换对象,使其顶点正确地位于平面上?

我知道如何进行点到平面的正交投影,但在这种情况下我想我需要透视投影。当物体移得更远时,其投影也需要根据观看者的视角调整大小和位置。

我想只要有人解释我需要采取的步骤,我就能弄清楚代码。

Imagine there is plane in between a virtual person and an object. The object is a box with a certain xyz scaling and rotation. The plane is like a glass window. The person is looking at the object through the plane. The camera is looking at the whole scene from a different angle.

I would like to draw the outline of the object onto the plane the way the person would see it, as if he were drawing on the window the outline of the object on the other side.

How can I transform the object so that its vertices end up on the plane correctly?

I know how to do a orthogonal projection of a point to a plane, but in this case I need perspective projection I guess. When the object moves further away its projection also needs to be adjusted in size and position according to the viewers perspective.

I think I can figure out the code if only someone would explain the steps I need to take.

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

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

发布评论

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

评论(2

雨巷深深 2024-11-26 09:11:55
  1. 创建以人眼为中心的 3D 坐标系。编写函数将点从一个系统转换到另一个系统。您可能还有另一个系统与该对象绑定。请记住,创建系统只不过是在其他默认坐标系中写入系统原点和轴的坐标。例如:
    System_ human_eye = {Point3f Origin(10, 0, 3), Xaxis(1, 0, 0), Yaxis(0, 1, 0), Zaxis(0, 0, 1) }

  2. 在人眼系统中,找到物体顶点坐标和平面法线。平面方程为p.normal=D,其中D是到平面的距离,p是平面点,法线是平面法线。人眼到顶点的光线为k*[x,y,z];当 k 改变时,你沿着射线行进。现在你需要做的就是沿着光线行进直到它与平面相交,即

    k*[x, y, z] 。正常=D;
    找到k,恢复点p=k*[x, y, z],这将给出射线与平面的交点;

  3. 将人眼系统的所有交集变换到相机系统;

  4. 使用 openGL 或光线追踪将这些坐标投影到屏幕上。由于直线在透视投影后仍然保持直线,如果您的对象由线条组成,您可以只使用它们。因此,您所需要做的就是投影线端点并将它们重新连接为屏幕上的线。
  1. Create a 3D coordinate system centered on human’s eye. Write function to transform points from one system to another. You might also have another system tied to the object. Remember that creating a system is nothing but writing coordinate of system origin and axes in some other default coordinate system. For example:
    System_human_eye = {Point3f Origin(10, 0, 3), Xaxis(1, 0, 0), Yaxis(0, 1, 0), Zaxis(0, 0, 1) }

  2. In the human eye system, find coordinates of the object vertices and plane normal. Plane equation is p.normal=D, where D is the distance to the plane, p is plane point and normal is plane normal. Ray from human eye to the vertex is k*[x, y, z]; as k changes you travel along the ray. All you need to do now is to travel along the ray till it intersect plane, that is

    k*[x, y, z] . normal = D;
    find k, restore point p=k*[x, y, z] and this will give you the intersection of the ray with the plane;

  3. Transform all the intersections from the human's eye system to the camera system;

  4. Project these coordinates on screen using openGL or ray tracing. Since straight lines remain straight after perspective projection you may just use them if your object consists of lines. So all you need is to project line endpoints and reconnect them as lines on screen.
乱世争霸 2024-11-26 09:11:55

一般来说,您想要进行透视投影

然而,这涉及大量的理论和数学,你必须头脑清楚。如果你想做一些更简单的事情,对于对象中的每个顶点,只需计算将眼睛连接到顶点的线,然后将其与平面相交。

In general, you want to do a perspective projection.

However, that involves a chunk of theory and math you have to get your head around. If you want to do something simpler, for every vertex in your object just calculate the line that joins the eye to the vertex, then intersect it with the plane.

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