数学和游戏编程 [英] Mathematics and Game Programming

查看:32
本文介绍了数学和游戏编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写比我已经知道的基本 2D 内容更复杂的图形 2D 游戏.我不想做 3D 编程.只是更复杂的 2D 东西.我还没来得及学很多东西就辍学了,所以我带着足够的代数知识离开了我的支票簿,并做了一些简单的 2D 笛卡尔编程.

I want to program graphical 2D games more complex than the basic 2D stuff I already know. I don't want to do 3D programming. Just more complex 2D stuff. I dropped high school before I could learn a lot of stuff so I walked away with enough algebra knowledge to balance my checkbook and do some light 2D Cartesian programming.

是否有任何好的资源可供注意力有限的人(比如我非常感兴趣的主题每人 20 分钟)逐渐学习如何在编程中使用数学做一些更有用的事情?

Are there any good resources out there for a guy with a limited attention span (say 20 minutes apiece for a subject I'm keenly interested in) to learn, gradually, how to do something more useful with math in programming?

推荐答案

你需要精通三角学:维基百科数学世界

即使您不想进行 3D 编程,2D 游戏也使用向量和矩阵.(来自线性代数)

Even though you don't wish to do 3D programming, 2D games also use vectors and matrices. (from Linear Algebra)

线性代数资源:维基百科数学世界

可以在 Trig 编程中为您节省大量精力的一点是意识到需要 atan2() 函数,而不是 atan() 函数.这在确定两点之间的方向时很重要.

One point that will save you a lot of effort in Trig programming is realizing the need for the atan2() function, rather than the atan() function. This is important when determining the direction between two points.

能够在各种坐标系之间移动是一大优点.这将伴随着经验而来.两个常见的绊倒人的事情是:

Being able to move between various coordinate systems is a big plus. This will come with experience. Two common things that trip people up are:

a) 大多数屏幕系统将原点 (0,0) 放在左上角,x 轴正方向向右延伸,y 轴正方向向下延伸.标准笛卡尔坐标假设象限 1 的原点(其中 x 和 y 始终为正数或零)位于左下方.这需要程序员在某个阶段翻转"y 方向.

a) Most screen systems place the origin (0,0) in the upper left corner, with the positive x axis extending to the right and the positive y axis extending down. Standard Cartesian coordinates suppose the origin of Quadrant 1 (where x and y are always positive or zero) in the lower left. This requires a programmer to 'flip' the y orientation at some stage.

b) 典型的地理将 0 度作为北,正度顺时针扫描.所有 Trig 函数都将 0 度设为东,正度数以逆时针方向扫描.

b) Typical geography places 0 degrees as North and positive degrees sweep clockwise. All the Trig functions place 0 degrees as East with positive degrees sweeping counter-clockwise.

最后,尽管我们倾向于以度数来思考,但真正的图书馆会使用弧度.最佳做法是将角度存储为弧度(以数学"方向而不是地理"方向)并在显示调试信息时进行转换.

Finally, even though we tend to think in degrees, real libraries will use radians. A best practice is to store angles as radians (in 'math' orientation rather than 'geo') and convert things when displaying debug information..

这篇关于数学和游戏编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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