2013年9月5日星期四(8-5,缩放)

2023-11-04

缩放很简单,就是把各个坐标乘以缩放因子即可。

 

这次是一个多边形

 

int Scale_Polygon2D(POLYGON2D_PTR poly, float sx, float sy)

{

         // this function scalesthe local coordinates of the polygon

 

         // test for valid pointer

         if (!poly)

                   return(0);

 

         // loop and scale each point

         for (int curr_vert = 0; curr_vert < poly->num_verts; curr_vert++)

         {

                   // scale and store result back

                   poly->vlist[curr_vert].x *= sx;

                   poly->vlist[curr_vert].y *= sy;

 

         } // end for curr_vert

 

         // return success

         return(1);

 

} // end Scale_Polygon2D

 

POLYGON2D asteroid;

在game_init()中,

 

 

         // define points of asteroid

         VERTEX2DF asteroid_vertices[8] = {33,-3, 9,-18, -12,-9, -21,-12, -9,6, -15,15, -3,27, 21,21};

 

         // initialize asteroid

         asteroid.state       = 1;   // turn it on

         asteroid.num_verts   = 8; 

         asteroid.x0          = SCREEN_WIDTH/2; // position it

         asteroid.y0          = SCREEN_HEIGHT/2;

         asteroid.xv          = 0;

         asteroid.yv          = 0;

         asteroid.color       = 255; // white

         asteroid.vlist       = new VERTEX2DF [asteroid.num_verts];

 

         for (int index = 0; index < asteroid.num_verts; index++)

                   asteroid.vlist[index] = asteroid_vertices[index];

在game_main()中,按 s和a键,可以放缩

 

         // do the graphics

         Draw_Polygon2D(&asteroid, (UCHAR *)ddsd.lpSurface, ddsd.lPitch);

 

         // test for scale

         if (KEYDOWN('A')) // scale up

                   Scale_Polygon2D(&asteroid, 1.1, 1.1);

         else

                   if (KEYDOWN('S')) // scale down

                            Scale_Polygon2D(&asteroid, 0.9, 0.9);

 

         // rotate the polygon by 5 degrees

         Rotate_Polygon2D(&asteroid, 5);

截图如下:

现在进行封装

只需要加个成员函数即可。

int DDRAW_Interface::Scale_Polygon2D(POLYGON2D_PTR poly, float sx, float sy)

{

         // this function scalesthe local coordinates of the polygon

 

         // test for valid pointer

         if (!poly)

                   return(0);

 

         // loop and scale each point

         for (int curr_vert = 0; curr_vert < poly->num_verts; curr_vert++)

         {

                   // scale and store result back

                   poly->vlist[curr_vert].x *= sx;

                   poly->vlist[curr_vert].y *= sy;

 

         } // end for curr_vert

 

         // return success

         return(1);

 

}

但是由于cos_look和sin_look在成员变量中,所以,进行了设置

 

void DDRAW_Interface::setCosLook( int i , float cos_value )

{

         cos_look[i]        = cos_value;

 

}

void DDRAW_Interface::setSinLook( int i , float sin_value )

{

         sin_look[i]         = sin_value;

 

}

 

在game_init()中

        

         // define points of asteroid

         VERTEX2DF asteroid_vertices[8] = {33,-3, 9,-18, -12,-9, -21,-12, -9,6, -15,15, -3,27, 21,21};

 

         // initialize asteroid

         asteroid.state       = 1;   // turn it on

         asteroid.num_verts   = 8; 

         asteroid.x0          = SCREEN_WIDTH/2; // position it

         asteroid.y0          = SCREEN_HEIGHT/2;

         asteroid.xv          = 0;

         asteroid.yv          = 0;

         asteroid.color       = 255; // white

         asteroid.vlist       = new VERTEX2DF [asteroid.num_verts];

 

         for (int index = 0; index < asteroid.num_verts; index++)

                   asteroid.vlist[index] = asteroid_vertices[index];

 

 

 

         // generate the tables

         for (int ang = 0; ang < 360; ang++)

         {

                   // convert ang to radians

                   float theta = (float)ang*PI/(float)180;

 

        

 

                   ddraw->setCosLook( ang, cos(theta) );

                   ddraw->setSinLook(ang, sin( theta));

         } // end for ang

 

在game_main()中,ddraw->Draw_Polygon2D(&asteroid, ddraw->getbackbuffer(), ddraw->getbacklpitch());

 

         // test for scale

         if (KEYDOWN('A')) // scale up

                   ddraw->Scale_Polygon2D(&asteroid, 1.1, 1.1);

         else

                   if (KEYDOWN('S')) // scale down

                            ddraw->Scale_Polygon2D(&asteroid, 0.9, 0.9);

 

         // rotate the polygon by 5 degrees

         ddraw->Rotate_Polygon2D(&asteroid, 5);

 

        

         ddraw->DDraw_Unlock_Back_Surface();

        

         ddraw->DDraw_Flip();

        

         //while( FAILED( ddraw->DDraw_Flip() ) );

 

         Sleep( 33 );

 

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

2013年9月5日星期四(8-5,缩放) 的相关文章

随机推荐

  • Functions___CH_12

    12 1 Function Pointers Pointers to functions The syntax for creating a non const function pointer is one of the ugliest
  • 历时6个月, 非CS专业的我, 终于在毕业前拿到了谷歌软件工程师offer!

    本文作者 Isabel 本科就读于上海财经 研究生就读于CMU information management相关专业 在来Offer的帮助下成功 转码 入职谷歌 就在离毕业还有一个多月的时候 我收到了来自谷歌的offer 至此 心中的一块大
  • 机器视觉、目标检测常见应用场景

    机器视觉 目标检测常见应用场景 人脸人体检测 智能美肤 在保持皮肤质感的同时 自动对脸部进行匀肤 去瑕疵 痘 痘印 雀斑等 操作 并对全身皮肤进行美白 智能瘦脸 系统自动检测并分析人脸五官特征 生成脸部五官调整瘦脸后的图像 图像人脸融合 图
  • 华为OD机考题目(自动化测试)

    目次 1 求第k长的字串的长度 2 上N阶台阶问题 3 踢出石子问题 1 求第k长的字串的长度 描述 一个字符串只包含大写字母 求其连续相同字母子串中 长度第K长的子串长度 相同字母只取 最长那个子串 例 AAAAHHHBBCDHHHH K
  • SpringBoot集成Hutool 实现数据库数据导出到Excel 功能

    日常开发中 在B端页面上 经常需要将数据库中的数据 导出到Excel 我们今天用Hutool工具包 实现一下这个功能 一 Hutool简介 Hutool是一个功能丰富且易用的Java工具库 通过诸多实用工具类的使用 旨在帮助开发者快速 便捷
  • Lua UnPack函数用法

    这篇文章主要介绍了Lua UnPack函数用法实例 unpack它接受一个数组 table 作为参数 并默认从下标1开始返回数组的所有元素 local info 1 2 3 4 5 6 local a b c d e f unpack in
  • jenkins_svn_maven持续集成

    详解Jenkins svn maven 项目持续集成 第一步 由于刚刚接触jenkins 并不知道他是个什么东西 首先百度一下 然后进入官网 下载安装包 第二步 windows 安装 下载完了 打开里面有2个文件 setup exe Jen
  • JVM内存模型详解

    目录 1 JVM整体架构 2 JVM运行时内存 2 1 PC程序计数器 2 2 虚拟机栈 2 2 1 什么是栈帧 2 2 2 局部变量表 2 2 3 操作数栈 2 2 4 动态链接 2 2 5 方法返回地址 2 3 本地方法栈 2 4 堆
  • LNK1104 无法打开文件 libboost_system-vc142-mt-gd-x64-1_74.lib

    LNK1104 无法打开文件 libboost system vc142 mt gd x64 1 74 lib 问题 解决
  • 【应急响应】挖矿脚本检测指南&威胁情报&样本定性&文件清除&入口修复

    文章目录 挖矿样本 Win Linux 危害 定性 Linux Web安全漏洞导致挖矿事件 Windows 系统口令爆破导致挖矿事件 Linux 个人真实服务器被植入挖矿分析 挖矿样本 Win Linux 危害 定性 危害 CPU拉满 网络
  • vue-admin-beautiful 同时使用Api和MockJs

    根据项目修改接口地址config net config js 此处按自己所需组装 把utils request js复制一份 并重命名为request mock js 把baseURL设置为 vab mock server 使用mock数据
  • print()函数中引号的用法

    首先在开头强调非常重要的一点 在python学习中 默认所有的正确的语法 包括括号 标点符号等都是 英文 print 函数的用法有四种 1 无引号 2 单引号 3 双引号 4 三引号 1 无引号 print 520 没有引号的作用是为了让计
  • ThinkPHP5 三表联合查询

    使用ThinkPHP5 查询构建起进行三表联合查询 account info Db name third party tasks gt alias a gt join third party taskgroups b a taskGroup
  • [4G&5G专题-128]:5G培训关键技术篇-1-5G的网络概述

    作者主页 https blog csdn net HiWangWenBing 本文网址 https blog csdn net HiWangWenBing article details 118459771 目录 第1部分 移动业务需求趋势
  • 超详细html5登录注册页面总结

    一 HTML5简介 HTML是互联网上应用最广泛的标记语言 HTML文件就是普通文本 HTML标记 而不同的HTML标记能表示不同的效果 HTML5优势 HTML5并不是一种革新的的升级 而是一种向规范向习惯的妥协 因此HTML5并不会带给
  • VS开发QT项目,手写按钮槽函数避坑

    VS开发QT项目 手写按钮槽函数避坑 1 QT Creator按钮槽函数 2 VS中添加按钮槽函数 3 踩坑 由于最近开发需要在VS2017上配置QT开发环境 进行QT项目的开发 之前从来没有这样使用过 在此记一些坑 1 QT Creato
  • Android深入浅出之Binder机制

    转自 http www cnblogs com innost archive 2011 01 09 1931456 html Android深入浅出之Binder机制 一 说明 Android系统最常见也是初学者最难搞明白的就是Binder
  • ue4修改缓存路径到项目文件下面

    InstalledDerivedDataBackendGraph Path ENGINEVERSIONAGNOSTICUSERDIR DerivedDataCache EditorOverrideSetting LocalDerivedDa
  • android自动化静态代码分析,使用Android Studio Lint静态分析(一)

    主要内容 使用Android Studio提供的工具 配置Lint扫描范围和检查项 在使用 Lint 改进您的代码文档中 属于手动运行检查 程序静态分析 程序静态分析是指在不运行代码的方式下 通过词法分析 语法分析 控制流 数据流分析等技术
  • 2013年9月5日星期四(8-5,缩放)

    缩放很简单 就是把各个坐标乘以缩放因子即可 这次是一个多边形 int Scale Polygon2D POLYGON2D PTR poly float sx float sy this function scalesthe local co