现在的位置: 首页 > 综合 > 正文

Allegro学习笔记八

2013年02月13日 ⁄ 综合 ⁄ 共 1522字 ⁄ 字号 评论关闭

http://wiki.allegro.cc/AllegroExamples 以上是英文例子站点。

by Shawn Hargreaves,allegro的作者

目录: 1 Allegro 例子

1.1 exhello
1.2 exmem
1.3 expat
1.4 expal
1.5 exflame
1.6 exbuf
1.7 exflip
1.8 exfixed

这个范例展示了如何使用fixed类型的数--32位有符号数据
--整数部分放在高16位,小数部分放在低16位。这个范例
同时也展示了使用allegro专有的allegro_message()来与
用户的交流--其中大部分技巧并不常用。(原文..但是我觉得
很有用,类似printf的格式输出)

#include <allegro.h>

 

int main(void)
{
   /* declare three 32 bit (16.16) fixed point variables */
   fixed x, y, z;

   if (allegro_init() != 0)
      return 1;

   /* convert integers to fixed point like this */
   x = itofix(10);

   /* convert floating point to fixed point like this */
   y = ftofix(3.14);

   /* fixed point variables can be assigned, added, subtracted, negated,
    * and compared just like integers, eg:
    */
   z = x + y;
   allegro_message("%f + %f = %f/n", fixtof(x), fixtof(y), fixtof(z));

   /* you can't add integers or floating point to fixed point, though:
    *    z = x + 3;
    * would give the wrong result.
    */

   /* fixed point variables can be multiplied or divided by integers or
    * floating point numbers, eg:
    */
   z = y * 2;
   allegro_message("%f * 2 = %f/n", fixtof(y), fixtof(z));

   /* you can't multiply or divide two fixed point numbers, though:
    *    z = x * y;
    * would give the wrong result. Use fixmul() and fixdiv() instead, eg:
    */
   z = fixmul(x, y);
   allegro_message("%f * %f = %f/n", fixtof(x), fixtof(y), fixtof(z));

   /* fixed point trig and square root are also available, eg: */
   z = fixsqrt(x);
   allegro_message("fixsqrt(%f) = %f/n", fixtof(x), fixtof(z));

   return 0;
}
END_OF_MAIN()
------------------------------------------------------
小结八:
1、fixed类型,可以看作是扩展了的实数型,但是是定点数。

2、由于不涉及图像显示,所以不需要设置显示模式之类的。

3、x = itofix(10);y = ftofix(3.14);格式输出等等等等,这些还是参照帮助文档来吧...偶不是潭浩强教授: 

抱歉!评论已关闭.