gameloft数学算法.doc

  1. 1、本文档共11页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
gameloft数学算法

Table of Contents 1 Introduction 4 1.1 Purpose and Scope 4 1.2 Abbreviation 4 1.3 Reference 4 1.4 Other 4 2 Mathematics in 2D Games 4 2.1 定点数 4 2.1.1 定点数的的应用 4 2.1.2 定点数算法 4 2.2 距离的计算 4 2.2.1 点到点 4 2.2.2 点到直线 4 2.3 三角函数 5 2.4 碰撞和裁剪 5 2.4.1 点和矩形 5 2.4.2 直线和矩形 5 2.4.3 矩形和矩形 5 2.4.4 剪裁区域 5 2.5 其他算法 5 2.5.1 平方根 5 2.5.2 排序 5 2.5.3 环行队列 5 List of Tables Table 21 The first table’s caption. 4 Table 22 The second table’s caption. 4 List of Figures Figure 21 The first figure’s caption. 4 Figure 22 The second figure’s caption. 4Introduction Purpose and Scope Abbreviation <For example: > GD Game Design Reference <In form of: No., Author Name or/and Company Name, Document Name, Document Version, Document ID optional. For example: > Yu Fei, Gameloft, “Game Design Specification”, V0.001. Other <Optional> <If you have any introduction information specific to this document, please write them here or add a new “Heading 2” to hold them. > Mathematics in 2D Games 定点数 定点数就是用整数来表示浮点数。方法是把浮点数扩大一定倍数,取整成整数。在计算机里,这个倍数通常是2的幂,这样方便快速计算。 定点数的的应用 由于手机通常不支持浮点数,J2ME也不支持,所以定点数被大量用于模拟浮点数。在2D游戏中,定点数主要用于存坐标值,这样移动速度就可以是半个象素,四分之一个象素,等等。 定点数算法 以下都假设a, b是两个定点数,c是计算结果,f是因子,就是扩大的倍数。 浮点数转换到定点数 定点数 = 浮点数 * 转换因子(倍数) 加法 c a + b 减法 c a – b 乘法 c a * b / f,如果f是2的幂,那么可以用右移做除法 除法 c a / b,这里假设小数部分会被抵消,精确的计算比较麻烦,在2D游戏里基本不用。其实除法在2D游戏里用得也很少。 距离的计算 点到点 假设有两点(X0,Y0),X1,Y1 dx X1-X0 ; dy Y1-Y0 计算两点间距离的精确算法是 distance2D =sqt(abs(dx)+abs(dy))。 由于J2ME不支持浮点运算,在J2ME 2D游戏中也可以用近似算法计算两点间距离,一方面能取得较快速度,精度上也不会有太大损失。 int approx_distance2D int dx, int dyint min, max;if dx < 0 dx -dx;if dy < 0 dy -dy;if dx < dymin dx;max dy;elsemin dy;max dx;// coefficients equivalent to 123/128 * max and 51/128 * minreturn max << 8 + max << 3 - max << 4 - max << 1 +min << 7 - min << 5 + min << 3 - min << 1 >> 8 ; 如果在游戏需要经常计算点到点的距离,同时对精度要求也不太高,我们可以损失一点精度而取得更快的速度。这就是下面的快速近似算法。 int fastDistance2Dint dx, int dy// this function computes the distance from 0,0 to x,y with 3.5% error// first compute the absolute

文档评论(0)

kabudou + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档