计算机图形学第三版中心画圆法算法代码


计算机图形学(第三版)中心画圆法算法代码:代码运行软件版本(Visual Studio 2017)【软件安装教程百度“VS2015安装+OpenGL环境配置及测试”】 参考书本代码85~86页代码,稍作修改,实现中心画圆。
资源截图
代码片段和文件信息
#include “Dependenciesglewglew.h“
#include “Dependenciesfreeglutfreeglut.h“
#include 

GLint array[1000][2]; //保存要显示的坐标点
int length=0;
class screenPt {
private:
GLint x y;
public:
/*  Default Constructor:initializes coordinate position to (00).  */
screenPt() {
x = y = 0;
}
void setCoords(GLint xCoordValue GLint yCoordValue) {
x = xCoordValue;
y = yCoordValue;
}

GLint getx() const {
return x;
}

GLint gety() const {
return y;
}
void incrementx() {
x++;
}
void decrementy() {
y--;
}

};

void init(void) {
glClearColor(1.0 1.0 1.0 0.0);//窗口颜色(红:[0.0~1.0]R 绿:[0.0~1.0]G,蓝:[0.0~1.0]B 透明度:[0.0~1.0]A)

 /*使用正投影将世界坐标系二位矩形区域的内容映射到屏幕上,区域的x坐标值从0.0到200.0,y坐标值从0.0到150.0*/
glMatrixMode(GL_PROGRAM);
gluOrtho2D(0.0 200.0 0.0 150.0);
}

void setPixel(void)
{
glClear(GL_COLOR_BUFFER_BIT);//GL_COLOR_BUFFER_BIT是一个OpenGL符号常量,用来指定它的颜色缓存(刷新缓存)中的位值,该缓存将使用glClearColor函数中指定的值来设定。
glColor3f(1.0f 0.0f 0.0f);//设置线段颜色为红色

glPointSize(5.f); //设置点的大小

glBegin(GL_POINTS);

for (size_t i = 0; i <=length; i++)
{
glVertex2i(array[i][1] array[i][2]);
}

glEnd();

glFlush();//执行所有的OpenGL程序
}

void circlePlotPoints(GLint xc GLint yc screenPt circPt)
{
//setPixel(xc + circPt.getx() yc + circPt.gety());
//setPixel(xc - circPt.getx() yc + circPt.gety());
//setPixel(xc + circPt.getx() yc - circPt.gety());
//setPixel(xc - circPt.getx() yc - circPt.gety());
//setPixel(xc + circPt.gety() yc + circPt.getx());
//setPixel(xc - circPt.gety() yc + circPt.getx());
//setPixel(xc + circPt.gety() yc - circPt.getx());
//setPixel(xc - circPt.gety() yc - circPt.getx());
printf(“(%d%d)
“ xc + circPt.getx() yc + circPt.gety());
//要显示的坐标点保存至array[1000][2]
array[length][1] = xc + circPt.getx() array[length][2] = yc + circPt.gety();

}

void circleMidpoint(void)
{
screenPt circPt;
GLint xc = 0;
GLint yc = 0;
GLint radius = 50;
GLint p = 1 - radius;           // Initial value for midpiont parameter.

circPt.setCoords(0 radius);// Set coords for top point of circle.

void circlePlotPoints(GLint GLint screenPt);
/*  Plot the initial point in each circle quadrant. */
circlePlotPoints(xc yc circPt);
/*  Calculate next point and plot in each octant.  */
while (circPt.getx() length++;
circPt.incrementx();
if (p<0)
p += 2 * circPt.getx() + 1;
else {
circPt.decrementy();
p += 2 * (circPt.getx() - circPt.gety()) + 1;
}
circlePlotPoints(xc yc circPt);
}

}


int main(int argc char *argv[])
{
glutInit(&argc argv);//初始化GULT
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);//设置显示模式
glutInitWindowPosition(300500);//设置左上角窗口显示位置
glutInitWindowSize(400 300);//设置窗口显示的宽与高
glutCreateWindow(“中点画圆算法“);//创建一个窗口
init();//执行初始化程序
circleMidpoint();
glutDisplayFunc(setPixel);//把图形显示在窗口
glutMainLoop();//显示所有并进入等待状态
}




 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     32256  2017-09-21 13:48  circle.vscirclev15.suo

     文件   32075776  2017-09-21 13:48  circle.vscirclev15Browse.VC.db

     文件   33947648  2017-09-21 13:46  circle.vscirclev15ipchAutoPCH20e3d3569fc1d5c8SOURCECPP.ipch

     文件       6497  2017-09-20 19:20  circlecirclecircle.vcxproj

     文件        950  2017-09-20 19:19  circlecirclecircle.vcxproj.filters

     文件        703  2015-03-14 15:34  circlecircleDependenciesfreeglutfreeglut.h

     文件      36518  2015-03-14 15:24  circlecircleDependenciesfreeglutfreeglut.lib

     文件      10682  2015-03-14 15:34  circlecircleDependenciesfreeglutfreeglut_ext.h

     文件      27470  2015-07-22 08:45  circlecircleDependenciesfreeglutfreeglut_std.h

     文件        660  2015-03-14 15:34  circlecircleDependenciesfreeglutglut.h

     文件    1038562  2015-08-10 21:54  circlecircleDependenciesglewglew.h

     文件     609776  2015-08-10 21:53  circlecircleDependenciesglewglew32.lib

     文件      74912  2015-08-10 21:54  circlecircleDependenciesglewglxew.h

     文件      64836  2015-08-10 21:54  circlecircleDependenciesglewwglew.h

     文件     235008  2015-03-14 16:02  circlecirclefreeglut.dll

     文件       3182  2017-09-21 13:47  circlecirclesourcecpp.cpp

     文件        858  2017-09-20 20:16  circlecirclex64Debugcircle.Build.CppClean.log

     文件        188  2017-09-21 13:47  circlecirclex64Debugcircle.log

     文件        208  2017-09-21 13:47  circlecirclex64Debugcircle.tlogcircle.lastbuildstate

     文件        604  2017-09-21 13:47  circlecirclex64Debugcircle.tlogCL.command.1.tlog

     文件      17658  2017-09-21 13:47  circlecirclex64Debugcircle.tlogCL.read.1.tlog

     文件        504  2017-09-21 13:47  circlecirclex64Debugcircle.tlogCL.write.1.tlog

     文件       1528  2017-09-21 13:47  circlecirclex64Debugcircle.tloglink.command.1.tlog

     文件       3816  2017-09-21 13:47  circlecirclex64Debugcircle.tloglink.read.1.tlog

     文件        480  2017-09-21 13:47  circlecirclex64Debugcircle.tloglink.write.1.tlog

     文件     235008  2015-03-14 16:02  circlecirclex64Debugfreeglut.dll

     文件      31149  2017-09-21 13:47  circlecirclex64Debugsourcecpp.obj

     文件     355328  2017-09-21 13:47  circlecirclex64Debugvc141.idb

     文件     126976  2017-09-21 13:47  circlecirclex64Debugvc141.pdb

     文件       1430  2017-09-20 19:14  circlecircle.sln

............此处省略22个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)