CG实验4th:消隐
来源:互联网 发布:网络道德现状 编辑:程序博客网 时间:2024/06/07 02:04
消隐采用的是深度排序算法(油画家算法)
运行结果:
源程序:
#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <queue>#include "graphics.h"using namespace std;struct MyRectangle {double x0;double y0;double x1;double y1;MyRectangle():x0(0), y0(0), x1(0), y1(0){}};// 每一个元素由一个矩形和它的深度及颜色组成struct Element {MyRectangle rec;double buffer;COLORREF color;Element():buffer(0), color(0){}bool operator<(const Element &other) const {return this->buffer > other.buffer;// 让深度较小的排在前面,先出队}};void Draw(priority_queue Q){initgraph(500, 500);while (!Q.empty()){Element tmp = Q.top();Q.pop();int x0 = (int)tmp.rec.x0;int y0 = (int)tmp.rec.y0;int x1 = (int)tmp.rec.x1;int y1 = (int)tmp.rec.y1;COLORREF color = tmp.color;setfillstyle(color);bar(x0, y0, x1, y1);Sleep(2000);}closegraph();}int main(int argc, char **argv){freopen("cin.txt", "r", stdin);priority_queue<Element> Q;// 按深度来排的优先队列Element tmp;while (cin >> tmp.rec.x0 >> tmp.rec.y0 >> tmp.rec.x1 >> tmp.rec.y1 >> tmp.buffer)// Element最好重载>>{// 颜色用十六进制输入,如:0xA80000或A80000scanf("%x", &tmp.color);Q.push(tmp);}Draw(Q);return 0;}/**cin.txt0 0 200 200 0.70xA8000027 27 300 30020x00A80035 440 90 10 10xA8A800470 40 10 160 30x0000A8*/
- CG实验4th:消隐
- CG实验4th:Bezier曲线
- 机械版CG 实验4 裁剪
- CG实验4 三维几何变换
- CG实验1 三角形绘制
- 机械版CG 实验3 变换
- 机械版CG 实验5 Bezier曲线
- 机械版CG 附加实验2 投影变换
- CG实验2 二维几何变换
- CG实验5 简单光照明模型
- CG实验6 交互与动画
- CG
- cg
- cg
- 机械版CG 实验1 像素点的生成
- 机械版CG 实验2 直线生成算法的实现
- 机械版CG 实验3 变换参考实例
- 机械版CG 实验6 简单光照明模型实现
- 在64位Linux上安装MemCached
- 图搜索算法(一):图搜索的一般算法
- JQuery的自定义事件
- Web中无法调试解决方案
- 栈与堆的区别及其探讨
- CG实验4th:消隐
- 浅谈C++的智能指针
- centos 命令学习
- C++程序员经常问的11个问题
- 10大在线自学平台
- DM架构设计
- Set_XXX_Property Build-Ins
- hdu 1175 连连看(广搜)
- 本机CSS变量