渲染三维点或面 [英] Rendering a point or plane in 3D

查看:374
本文介绍了渲染三维点或面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我目前的项目是XNA,这个问题是关于3D的基本数学2D绘图。事实上,和出于同样的原因,我们假设一个WinForms图形表面上绘制

Although my current project is XNA, this question is about the basic mathematics of 3D to 2D mapping. In fact, and for the same reason, let's assume a WinForms graphics surface to draw on.

我有以下配置:

  • 的摄像机位置(x = 0,Y = 0,Z = 0)的和方向向量(x = 0,Y = 0,Z = 0)。
  • 的线段在3D与以下几点:(10,10,10),(100,100,100)

我想在2D表面上把这些坐标,绘制它们。因此,根据在摄像机上,线段应该从(X1,Y1,Z1),(X2,Y2,Z2)变换到(X1,Y1),(X2,Y2)。

I want to transform these coordinates and draw them on a 2D surface. So depending on the camera, the line segment should transform from (x1, y1, z1),(x2, y2, z2) to (x1, y1),(x2, y2).

推荐答案

我认为你正在寻找一个正交或透视投影。有很多资料在网上,如果你搜索,但这里是要点。

I think you are looking for an orthogonal or perspective projection. There is a lot of information online if you search for it but here is the gist.

在照相机看原点,位于距离 D 沿Z轴将投影点(X,Y,Z) 上飞机为:

A camera looking at the origin, located a distance d along the z-axis will project a point at (x,y,z) onto a plane as:

// Orthogonal
planar_x = x
planar_y = y

// Perspective
planar_x = x*d/(d-z)
planar_y = y*d/(d-z)

示例

一个点(10,10,10)与位于 500 沿z的距离相机轴将具有平面坐标(10 * 500 /(500-10),10 * 500 /(500-10))=(10.204,10.204)

Example

A point at (10,10,10) with the camera located a distance of 500 along the z axis will have planar coordinates (10*500/(500-10), 10*500/(500-10)) = (10.204, 10.204)

一个点(10,10,100)与位于距离相机 500 沿Z轴将有平面坐标(10 * 500 /(500-100),10 * 500 /(500-100))=(12.5,12.5)

A point at (10,10,100) with the camera located a distance of 500 along the z axis will have planar coordinates (10*500/(500-100), 10*500/(500-100)) = (12.5, 12.5)

所以越接近的形状是相机的大出现。

So the closer a shape is to the camera the larger it appears.

要转换的平面模型坐标到像素坐标我用下面的比例

To transform the planar model coordinates to pixel coordinates I use the following scaling

scale = max_model_size/Math.Min(Height,Width);
pixel_x = Width/2 + x/scale;
pixel_y = Height/2- y/scale;

这是我怎么可以使用 GDI 来绘制3D形状的窗口的形式。

This is how I can use GDI to draw 3D shapes on a windows form.

当然,如果你想使用的OpenGL 再看看这里对于类似的问题。

Of course if you want to use OpenGL then look here for a similar question.

这篇关于渲染三维点或面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆