父视图坐标转换为子视图

透视视角 (Perspective-vue)

Designing a 2D game for a 2D screen is pretty simple to us. But it comes to design a 3D environment for a 2D computer screen we tend to adopt game engines thinking that's a lot of complex math we can't handle. Though there's no denying the reliability of game engines, some features of the 3D environment can be implemented with really simple mathematics we learnt at school. This repository is intented to demonstrate that.

为2D屏幕设计2D游戏对我们来说非常简单。 但是在为2D电脑屏幕设计3D环境时,我们倾向于采用游戏引擎,因为这是我们无法处理的许多复杂数学运算。 尽管不能否认游戏引擎的可靠性,但是3D环境的某些功能可以用我们在学校学到的非常简单的数学来实现。 该存储库旨在证明这一点。

Perspective drawing is a drawing technique used to illustrate dimension through a flat surface. This is how we see a flat surface image and perceive a 3D environment in our brain depending on the position and sizes of the objects drawn. So if we can do the math to calculate how large or small the object needs to be drawn depending on how far it is from the screen, that's all we need to have a 3D layout.

透视图是一种用于说明平面尺寸的绘图技术。 这就是我们看到平面图像并在大脑中感知3D环境的方式,具体取决于绘制对象的位置和大小。 因此,如果我们可以根据距离屏幕的距离进行数学运算来计算需要绘制对象的大小,那么我们就需要3D布局。

View Demo 查看演示 View Github 查看Github

入门 (Getting Started)

This is a vue app, clone the repository, set it up, play around.

这是一个Vue应用程序,克隆存储库,进行设置,播放。

项目设置 (Project setup)

yarn install

编译和热重装以进行开发 (Compiles and hot-reloads for development)

yarn run serve

编译并最小化生产 (Compiles and minifies for production)

yarn run build

整理和修复文件 (Lints and fixes files)

yarn run lint

数学 (The Math)

Let's see how easy the math is.

让我们看看数学有多么容易。

On the left we have a 2D view of a football field and on the right a 3D perspective drawing of the same field. In your mind it has 3 axes (x, y, z) but the paper you would be drawing on has only 2 axes just like the first one and (x', y') is the point on that paper that represents the point (x, y) on the left figure. There is no z-axis on drawing paper, so what appears to be the z-axis on the right figure is actually the y-axis of the paper.

左侧是足球场的2D视图,右侧是同一个足球场的3D透视图。 在您的脑海中,它有3个轴(x, y, z)但是您要绘制的纸张只有2个轴,就像第一个轴一样,并且(x', y')是该纸张上代表该点的点(x, y)在左图。 绘图纸上没有z轴,因此右图上的z轴实际上是纸张的y轴。

So if you look closely the point on the right figure that represents (x, y) is actually (d + x', y') with respect to the drawing paper where d is the displacement due to the shifting of left side of the rectangle from the y-axis.

因此,如果您仔细观察右图上代表(x, y)点实际上是相对于工程图的(d + x', y') ,其中d是矩形矩形左侧移动引起的位移从y轴开始。

If we extend the unparallel sides of the trapeze backwards they meet at a point of projection P which is at infinity distance from the screen. Say the point is at a height p from x-axis on the drawing paper. We can calculate the length of p from the two similar triangles in the figure below.

如果我们将飞人的不平行的边向后延伸,它们会在投影点P处相遇,而投影点P距屏幕无穷远。 假设该点在绘图纸上距x轴的高度为p 。 我们可以从下图中的两个相似三角形计算p的长度。

Comparing similar triangles we can calculate the value of d from the following figure.

比较相似的三角形,我们可以从下图计算d的值。

Now let's calculate the size of objects at different distances from the viewer. Any object which appears to be of length x when positioned at the x-asis will appear smaller when we move it away from the screen. Say it appears to be of length x' when positioned at a distance y' from x-axis on the drawing paper (y' is not equal to y, it is the height on the paper where x' is drawn which we will calculate in next step). So we calculate the value of x' at a distance y' comparing the two similar triangles in the following figure.

现在,让我们计算距查看器不同距离的对象的大小。 当我们将其移离屏幕时,任何看起来长度为x对象在x-asis处都会显得较小。 假设当它位于绘图纸上与x轴的距离y'处时,它的长度似乎为x' ( y'不等于y ,它是绘制x'的纸张高度,我们将在其中计算下一步)。 因此,我们比较下图中的两个相似三角形,计算出距离y' x'处的x'值。

Now calculating the value of y' is slightly complicated. If an object is in the middle of the 2D space, it won't be in the middle of the 3D space drawn on a 2D screen/paper. For better understanding we squeeze the height of the rectangle to match that of the the trapezium. The middle point of both the field is where the diagonals meet and they don't meet at the same height on the drawing paper.

现在,计算y'的值有些复杂。 如果对象在2D空间的中间,则不会在2D屏幕/纸张上绘制的3D空间的中间。 为了更好地理解,我们挤压矩形的高度以匹配梯形的高度。 这两个场的中间点是对角线相交的地方,它们在工程纸上的高度不同。

The following table shows corresponding values of y' with respect to y.

下表显示了相对于yy'对应值。

y y'
0 0
h/2 ah/(a+h)
h h
p
ÿ '
0 0
h / 2 ah /(a + h)
H H
p

The ratio of distances of y' from a and b is proportional to the lengths of a and b. The relationship is illustrated in the figure below.

的距离之比y'ab成比例的长度ab 。 该关系如下图所示。

This equation satisfies all the corresponding values shown in the table above. If you get stuck verifying the last one, the trick is the term bh is negligible to the term ∞(a-b) and thus can be taken off the equation.

该公式满足上表中显示的所有相应值。 如果您无法验证最后一个,则诀窍是bh项对于∞(ab)可以忽略不计,因此可以从等式中删除。

致谢 (Acknowledgments)

This repository is just intended to demonstrate use of simple math to solve complex looking challenges.

该存储库仅用于演示如何使用简单的数学方法来解决复杂的外观难题。

翻译自: https://vuejsexamples.com/simple-math-to-convert-simple-2d-game-view-to-a-perspective-3d-view/

父视图坐标转换为子视图

父视图坐标转换为子视图_简单的数学将简单的2D游戏视图转换为透视3D视图相关推荐

  1. 点击父组件按钮 显示子组件_按钮设计用户界面组件系列

    点击父组件按钮 显示子组件 重点 (Top highlight) In order to design the right interactions, we need to look back at ...

  2. java父窗口传值给子窗口_【赖国荣】js实现父窗口与子窗口传值

    1.变量的定义与使用,条件语句,循环语句和数组的使用: 2.定义和使用对象:this语句的使用:isNaN,eval函数的使用: 4.类型转换函数parseInt,parseFloat使用: 5.打开 ...

  3. python求正方体体积_「高中数学」简单几何体的面积与体积相关知识点整理+例题...

    一.知识要点 (一)圆柱.圆锥.圆台的侧面积 将侧面沿母线展开在平面上,则其侧面展开图的面积即为侧面面积. 1.圆柱的侧面展开图--矩形 圆柱的侧面积 2.圆锥的侧面展开图--扇形 圆锥的侧面积 3. ...

  4. unity游戏开发毕设_毕设分享:用 Unity 探究 2D 游戏的打击感

    这是我毕业设计的一部分 emmm--我的毕设和格斗游戏相关,而对于打击感的研究算是其中我比较在意的一环.现在临近毕业,我将毕设中开发部分的一些内容整理出来分享,希望能通过这样学习到更多的东西. 打击感 ...

  5. python外星人入侵游戏图片_外星人入侵,使用python开发的2D游戏

    开学自学的python,通过敲代码练习的项目<外星人入侵>. 游戏介绍:游戏在玩家每消灭一群向下移动的外星人后,都将玩家的等级提高一个等级:而等级越高,游戏的节奏越快,难度越大 我使用的是 ...

  6. 【Unity3D】3D 视图操作 ( 视图基本元素 | 导航器 | 栅格 | 天空盒 | 3D 视图操作 | 视图旋转 | 视图缩放 | 视图平移 | 导航器操作 | 恢复方向 | 顶、右、前视图 )

    文章目录 一.3D 视图基本元素 1.导航器 Gizmo 2.栅格 Grid 3.天空盒 Skybox 二.3D 视图操作 1.视图旋转 2.视图缩放 3.视图平移 三.导航器操作 1.恢复方向 2. ...

  7. 地质勘测软件surfer使用教程:以 3D 视图查看钻孔图层

    使用 Surfer 的 3D 视图以 3D 方式查看您的钻孔,3D 视图使您能够以真正的 3D 形式可视化油井及其数据内容(例如污染物浓度.矿化浓度.化验结果.地球物理特性等).钻孔路径.数据点和间隔 ...

  8. 让超出自己视图范围的子视图响应事件

    有时需要让子视图的位置超出父视图,这时子视图不会响应点击事件,在父视图中实现这个方法,可以让子视图超出的部分也响应点击事件 父视图需要是view的子类 这个方法可以判断出自己的子视图,和子视图的子视图 ...

  9. cocos子节点转父节点坐标 原理浅析(局部坐标转世界坐标同理)

    在CCNode的类中,有一个得到 一个节点坐标系转换父亲坐标系的一个矩阵,节点内坐标乘以这个矩阵,就可以转换为在节点父节点中的坐标,方法名为: Mat4& Node::getNodeToPar ...

最新文章

  1. 双击.exe文件出现Debug Error: abort() has been called解决办法(之一)
  2. java applet退出功能_java-如何使用内置在applet中的Button在浏览器中停止applet?
  3. 共享一PYTHON 相关应用领域的介绍资料
  4. [C# 项目实战]: 制作一个备忘录(经典)
  5. Java转JSON串的几种方式
  6. python对操作系统要求_python之--并发编程__操作系统
  7. 融完5亿美元创始人出局?腾讯投资的明星无人车公司Zoox地震了
  8. 通俗理解路由器和交换机的区别?
  9. HCIP-Routing Switching V2.5考试大纲
  10. 计算机软件实习每日学习打卡(4)20201206
  11. mc服务器linux配置,详细教程——基于Centos搭建MC服务器(outdated)
  12. 基于android的资源文件管理器
  13. 传统零售商与B2C电子商务
  14. 计算机科学导论第五版第二章答案,计算机科学导论样题1答案
  15. python pdf 转换成txt,csv,doc 及doc转换为pdf初级
  16. 【文献学习】 2021 Deep-Waveform: A Learned OFDM Receiver Based on Deep Complex Convolutional Networks
  17. 乐视max2 在开发中无法打印某些logcat 解决方案
  18. cesium加载接入百度地图(cesium篇.2)
  19. Dubbo入门及Dubbo-admin安装
  20. 《新概念英语》有声电子书的实现

热门文章

  1. 大兴公寓的那场火,烧毁了我的所有
  2. 校园快递管理系统-JAVA.JSP【数据库设计、论文、源码、开题报告】
  3. 2021这份电子书单请收好(品类齐全)!
  4. Conflux 网络(Hydra)2.0.3 版本升级公告
  5. 一文带你读懂Java字节码
  6. 校内练习 华山论剑 [最短路]
  7. idea如何创建工作空间和项目
  8. ATAC-seq分析:差异分析(10)
  9. 关于去中心化技术实现的意义
  10. mysql数据库 排序中文字段_MySQL对中文进行排序的实例