求代码注释:计算机图形学的OpenGL画四面体。高手来吧。争取每句都注释下。谢谢

作者&投稿:彩湛 (若有异议请与网页底部的电邮联系)
求计算机图形学画扇形全部代码?~

void CDrawtest1View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (m_bDraw)
{
CClientDC dc(this);
dc.SetROP2(R2_COPYPEN);
CPen pen(PS_SOLID,1,RGB(255,0,0));
CPen *pOldPen = dc.SelectObject(&pen);

dc.MoveTo(m_ptStart);
dc.LineTo(m_ptEnd);
dc.LineTo(point);
m_ptEnd = point;
dc.SelectObject(pOldPen);
}
CView::OnMouseMove(nFlags, point);
}
全部太多垃圾。关键部分作参考吧。

第一步,尝试从项目->生成自定义里面加入fx.rules文件,结果发现只支持.targets和.props文件格式,在网上找寻fx.targets未果。
然后,尝试使用fxc,在工具->外部工具里新建fxc选项,参数用的是:/DWPF /Od /T ps_2_0 /E $(ItemFileName)PS /Fo$(ProjectDir)$(ItemFileName).ps $(ItemPath),
编译dx自带的例子比如Tutorial02,会出现
error X3501: 'Tutorial02PS': entrypoint not found
compilation failed; no code produced
这样的错误,但是程序可以运行,即使把程序改成带有明显错误的,也提示这个错误,只不过程序不能运行了。我觉得可能是哪里设置错误,

#include <gl/glut.h>
#define WIDTH 400
#define HEIGHT 400
#include <math.h>
#define ColoredVertex(c, v) do{ glColor3fv(c); glVertex3fv(v); }while(0) //这段就不用解释了吧……
GLfloat angle = 0.0f; //设定转角
void myDisplay(void) //绘图函数
{

static int list = 0;
if( list == 0 )
{
// 如果显示列表不存在,则创建

GLfloat //GLfloat为OpenGL用到的数据类型,与C的float基本一致

PointA[] = {-0.5, -5*sqrt(5)/48, sqrt(3)/6}, //此处为4个顶点的坐标,因为时3D坐标系下的,所以每个坐标有3个分量,分别对应X,Y,Z轴。至于各轴方向定义……默认下屏幕水平为X,竖直为Y,里外为Z。
PointB[] = { 0.5, -5*sqrt(5)/48, sqrt(3)/6},
PointC[] = { 0, -5*sqrt(5)/48, -sqrt(3)/3},
PointD[] = { 0, 11*sqrt(6)/48, 0};
/*GLfloat
PointA[] = { 0.5f, -sqrt(6.0f)/12, -sqrt(3.0f)/6},
PointB[] = {-0.5f, -sqrt(6.0f)/12, -sqrt(3.0f)/6},
PointC[] = { 0.0f, -sqrt(6.0f)/12, sqrt(3.0f)/3},
PointD[] = { 0.0f, sqrt(6.0f)/4, 0};
*/
GLfloat

ColorR[] = {1, 0, 0}, //定义颜色数组,每个数组为一个颜色,也含有3个分量,对应红,绿,蓝,分量范围[0,1],每种颜色都可看做是这3个颜色混合得到。可一自己改变下其中的数值看看具体效果。
ColorG[] = {0, 1, 0},
ColorB[] = {0, 0, 1},
ColorY[] = {1, 1, 0};

list = glGenLists(1);
glNewList(list, GL_COMPILE); //创建一个顶点表,这个表里包含有绘图的顶点信息
glBegin(GL_TRIANGLES); //开始绘图,(GL_TRIANGLES)表示绘制三角形
// 平面ABC
ColoredVertex(ColorR, PointA); //以颜色R绘制点A,以下类推,ColoredVertex()函数在程序开头定义了。
ColoredVertex(ColorG, PointB);
ColoredVertex(ColorB, PointC);
// 平面ACD
ColoredVertex(ColorR, PointA);
ColoredVertex(ColorB, PointC);
ColoredVertex(ColorY, PointD);
// 平面CBD
ColoredVertex(ColorB, PointC);
ColoredVertex(ColorG, PointB);
ColoredVertex(ColorY, PointD);
// 平面BAD
ColoredVertex(ColorG, PointB);
ColoredVertex(ColorR, PointA);
ColoredVertex(ColorY, PointD);
glEnd();
glEndList(); //结束绘图 结束绘图顶点表。
glEnable(GL_DEPTH_TEST); //打开深度测试。打开深度测试的作用是:如果在场景中有多个物体,而它们相对观察者的距离不同(简单理解为远近),那么这个时候,前面的物体则可以挡住后面的物体(没错吧),使场景具有深度感。如果不打开深度测试,那么绘图会按绘制的顺序,后绘制的物体覆盖住现绘制的物体。这里要注意的是,深度仅影响物体重合时谁显示谁不显示,并不影响其3D效果,远处的物体仍然会变“小”,物体在空间中的位置仍为三维的。

}

// 已经创建了显示列表,在每次绘制正四面体时将调用它
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //清除颜色缓存和深度缓存
glPushMatrix(); //绘图坐标系入栈,可以简单理解为存下了这次画图时画笔的起始位置
glRotatef(angle, 1, 0.5, 0); //绘图坐标系绕(1,0.5,0)轴旋转angle角,可理解为模型绕该轴旋转angle角。
glCallList(list); //调用顶点表,绘制四面体模型
glPopMatrix(); //绘图坐标系出栈,则回到了刚才的绘图起始位置
glutSwapBuffers(); //使用双缓存(第一个在前面显示模型,另一个在后面绘制新的模型,当新模型绘制完毕后送给第一个缓存显示。这样不会出现模型上一些点已经绘制完了,而另一些点还在绘制的情况。)
}
void myIdle(void)
{
++angle;
if( angle >= 360.0f )
angle = 0.0f; //转角超过360度,将其置零。
myDisplay(); //绘制模型}
int main(int argc, char* argv[]) { glutInit(&argc, argv); //创建绘图窗口
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); //设置绘图模式
glutInitWindowPosition(200, 200); //设置窗口位置
glutInitWindowSize(WIDTH, HEIGHT); //设置窗口大小
glutCreateWindow("OpenGL 窗口"); //设置窗口标题
glutDisplayFunc(&myDisplay); //重复调用函数
glutIdleFunc(&myIdle);//重复调用函数
glutMainLoop(); //该循环用来对上述两个重复调用函数不断调用
return 0;
}

回答完毕。

很专业的,有专门论坛吧,用于#3D的一种方法。可是我们不采用,也不相信是有效的。换一个吧。
图杭GIs软件真3D软件。

我也不是很懂,你验收一下(有两个参考资料)
CS 535
WEILER-ATHERTON
PROBLEM
Implement Weiler-Atherton. You should draw each polygon in a different color and fill the clip areas generated with a third color.
NOTES:
The Weiler-Atherton algorithm is the most general of the clipping algorithms. We have two 2D polygons (may be convex or concave and they both may have holes). The polygon to be clipped is called the SUBJECT polygon and the polygon defining the clipping area is called the CLIP polygon. To make the algorithm work easier (in the data structures, etc.) we usually assume that the exterior vertices are given clockwise and the hole vertices are given counterclockwise. In clipping we usually want to find the parts of the subject polygon that are inside the clip polygon. However, this algorithm can be used in modeling to find the "union", "intersection", and "difference" of the polygons.
The data structures are several circular linked lists of vertices which are also linked together and the clipping is done by traversing these. The lists could be doubly linked. This enables the traversal in either direction at any node in the list. Starting at a particular node and traversing in one direction will produce the interior polygon(s) while starting at a different node and traversing can produce the outside. Note that producing the exterior does need the doubly linking and care must be taken in performing the traversal.

STEP 1:
The first phase of the building of the data structures occurs when we input the edges and put them in two linked lists - the SUBJ list and the CLIP list. The vertices are place in order from input (thus clockwise). There are separate lists for the exterior and for each hole. Thus, the initial build is a standard queue insert (input a vertex - insert it at end of list). Note that this creates a list in which a standard list traversal is equivalent to "walking around" the polygon edge visiting the vertices in order.
STEP 2:
The second phase of the list building is computing and inserting the INTERSECTION points. If we have a SUBJECT polygon edge (SVi to SVi+1) that intersects a CLIP polygon edge (CVj to CVj+1) at a point INTER. Note that the edges form straight lines that may intersect, we are assuming that the line segments SVi to SVi+1 intersects the line segment CVj to CVj+1. The intersection point INTER is then inserted on BOTH of the linked lists - SUBJ and CLIP. It is inserted BETWEEN SVi and SVi+1 on the SUBJ list and CVj and CVj+1 on the CLIP list. The idea is still that traversing the list using a standard list traversal we would encounter the points in their geometric order. Note that there may be several intersection points between any given pair of vertices and they must be inserted in the correct order in the lists. This is done by using the t and u values computed in the vector line intersection subprogram. Each intersection point thus has TWO nodes - one on each list (SUBJ and CLIP). We link these two entries together which provides a way of getting from one list to the other.
STEP 2.5:
Any straight line divides the plane into two half-planes. Thus each polygon edge (extended to a line) will divide the plane into two half-planes. Because we listed the vertices clockwise, we consider the half-plane to the right as containing the interior of the polygon. Thus the right half-plane is called the interior half-plane. If we consider ourselves as "walking along" a polygon edge, then we can categorize each of the INTERSECTION points as "entering" or "exiting". This is usually done from the SUBJ polygon's point of view. Thus, as we walk along the SUBJ polygon edge SVi to SVi+1 and we encounter intersection point INTER, we can ask the question - am I "entering" the CLIP polygon or am I "exiting" the CLIP polygon? The second part of computing the intersection point is to classify them as "entering" or "exiting". We create one or two lists - one for entering intersections and one for exiting intersections.
STEP3:
Once the lists are built the basic idea to do the clipping is as follows
Pick an entry from the ENTERING list - it will be an intersection point (and delete it)
Locate that point on the SUBJ list
Traverse the current (SUBJ) list until you find the next intersection point - it should be an exiting or entering point. Output each vertex encountered to some data structure, say POLY
Follow the link from the current (SUBJ) list to the other (CLIP) list and
Continue the traversal until you find the next intersection (Note: delete each entering intersection from the ENTERING list - not the linked lists. By deleting it we will get the distinct intersecting polygons and not duplicate a polygon multiple times).
Terminate the traversal when you get to an intersection that is the SAME as the initial one that you removed from the ENTERING list. At this point POLY will have one of the clip regions and can be output.
REPEAT the construction and output of POLY until the ENTERING list is empty.
Remark: For the exterior, try starting with an EXITING point. Start the traversal on the SUBJ list (same direction as the Interior). At what point do you need to use the double link and to traverse in the opposite direction? (Hint: look at the CLIP polygon list).
IMPLEMENTATION:
In the below data structures we place all of the vertices and intersection points in a 1D array and use the subscript instead of the actual coordinates.
const int MAXVERT = 500;
const int MAXPOLYV = 50;
const int MAXH = 10;

struct Point2D
{float x,y;
};
typedef Point2D Vertices[MAXVERT];

enum VerType = ;

typedef struct ClipListRec * ClipPtr;
struct ClipListRec
{ int Vindex;
ClipPtr next;
VerType Kind;
float t;
ClipPtr otherList;
}

struct Polygon
{ int nVertex;
int vert[MAXPOLYV];
ClipPtr list;
}
struct GenPolygon
{ Polygon exterior;
int numHoles;
Polygon Holes[MAXH];
}

GenPolygon Sub,Clip;
int entering[MAXVERT],exiting[MAXVERT];
Vertices V;
int numVertex = 0; // size of the array of verticies
int clipPoly[MAXVERT]; // a clip polygon

int readPoint();
{ cin >> inX; cin >> inY;
if (numVertex < MAXVERT)
{ V[numVertex].x = inX;
V[numVertex].y = inY;
idNo = numVertex;
numVertex++;
}
else
idNo = -1;
return idNo;
}

void readPolygon (GenPolygon p)
{ cin >> p.exterior.nVertex;
for (i = 0; i < p.exterior.nVertex; i++)
{ newId = readPoint();
if (newId < 0)
error
else
{ insertAtRear (p.exterior.list,newId);
p.exterior.vert[i] = newId;
}
}
// now do the holes basically the same way
. . .
}
// the "main" program loop would then be (pseudocode)
while (!EMPTY(entering))
{ nextInter = delete (entering);
SEARCH (SubjectPolygon,nextInter,ptr1);
AddToOutputList (ptr1->. . .)
StartPoint = ptr1->. . .
ptr1 = prt1->next;
while (ptr1->. . . != StartPoint)
{ AddToOutputList (ptr1->. . .);
if (ptr1-> . . == INTERSECTION)
ptr1 = prt1->otherList->next;
else
ptr1 = ptr1->next;
}
FixListForOutput();
DrawPolygon();
EmptyOutputList();
}
参考资料:


...是线性函数与非线性函数?( 含有笔记、代码、注释 )
二、Python中的编码与解码艺术 在Python编程中,字符串msg存储着珍贵的信息,如"我爱北京天安门"。我们可以通过msg.encode("utf-8")将其转换为字节序列(bytes),这个过程是将字符编码成二进制序列,以便于计算机处理。运行结果如下:msg.encode("utf-8")会输出:b'\\xe6\\x88\\x91\\xe7\\x88\\xb1\\...

java注解大全?
附上代码: [java]?viewplain?copy span?style="font-size:18px;"*\/ \/**javadoc注释的内容 *\/ public?class?Hello{ \/**属性上的注释*\/ public?String?name; \/**这是main方法,是程序的入口 *@param?args?用户输入参数 *\/ public?static?void?main(String[]?args){ System.out.println("Hello?World!"...

点云入门学习(matlab代码详细中文注释,R2023a版本)
点云学习指南,详细代码注释,适配Matlab R2023a版本。本文内容结构化为多个模块,旨在全面覆盖点云处理的基本与进阶操作。A_基础操作 计算点云质心 去质心化 计算曲率 计算面状指数 计算粗糙度 最大距离计算 矩阵Moore-Penrose伪逆 3D椭圆点云生成 三点定圆 B_读写保存 las点云解析(1)las\/laz文件...

电脑主板诊断卡怎么使用呀?
1、诊断显示代码。2、关电源,取出所有扩展插卡。将诊断卡插入ISA槽或PCI槽(注意:诊断卡的的元件面朝向电源。若插反,本卡和主板不会损坏,但都不工作。)3、开电源,检查各发光二极管指示是否正常(其中BIOS信号灯可能闪烁)。4、如果不正常,关电源,参照以下“指示灯功能速查表”排错,排错完毕后返回...

怎样知道计算机代码
第一步:同时按住键盘上的"Win+R",打开开始菜单下的运行框,如下图所示:第二步:在运行框里输入“dxdiag”操作指令。如下图所示:第三步:跳出“dxdiag”诊断工具框,选择上面菜单第一项“系统”,可以看到下面计算机的编号了。这个编号是出厂时设置的,不能更改的如下图所示:...

电脑\/\/\/
-s 关闭此计算机 -r 关闭并重启动此计算机 -a 放弃系统关机 -m \\computername 远程计算机关机\/重启动\/放弃 -t xx 设置关闭的超时为 xx 秒 -c "comment" 关闭注释(最大 127 个字符)-f 强制运行的应用程序关闭而没有警告 -d [u][p]:xx:yy 关闭原因代码 u 是用户代码 p 是一个计划的关闭...

大学学术论文的格式
e. 某些重要的原始数据、数学推导、计算程序、框图、结构图、注释、统计表、计算机打印输出件等。7.2 附录与正文连续编页码。每一附录的各种序号的编排见4.2和6.2.4。7.3 每一附录均另页起。如报告、论文分装几册。凡属于某一册的附录应置于备该册正文之后。8 结尾部分(必要时)为了将报告、论文迅速存储人电子...

计算机文件一般有哪几种注释方法
第一种:单行注释,以\/\/开始,到本行结束。单行注释是能写一行。第二种:多行注释,多行注释以\/*开始,以*\/结束。第三种注释:文档注释,用于对类和方法进行注释。计算机文件(或称文件、电脑档案、档案),是计算机上相关信息的集合,可储存在长期储存设备上。所谓“长期储存设备”一般指磁盘、光盘、...

10分钟了解C语言基本语法知识
(稍后我们会讨论什么是计算机语言里面的函数,以及主函数在C语言程序中的存在意义。) 双斜杠后面的为注释,打一个比较形象的比喻,注释就类似于老师在作业本上的批注。 一般来说,注释用于标注这段代码的用途或解释思路等。因为注释不会被当做代码进行编译,所以无论添加什么注释内容,都不会对代码的实际运行产生任何影响...

python代码注册有多少种方式
python代码的注释有几种python代码的注释有两种。一、python单行注释符号(#)python中单行注释采用#开头,示例:#thisisacomment。二、批量、多行注释符号 多行注释是用三引号,例如:输入'''或者""",将要注释的代码插在中间。Python由荷兰数学和计算机科学研究学会的吉多·范罗苏姆于1990年代初设计,...

宁晋县13521751290: 求一个带注释的opengl代码,简单点的就好,交作业用 -
素琬卤米: #include <stdlib.h>#include <stdio.h>#include <memory.h>#include <windows.h> #include <GL/gl.h>#include <GL/glu.h>#include <GL/glut.h>//#include "bmp.h"#include "GL/glext.h"#pragma comment( linker, "/subsystem:\"windows\" /entry...

宁晋县13521751290: 求帮助!!!!计算机图形学,opengl -
素琬卤米: 不要用粒子系统,你搞复杂了.openGL中有直接画线和画点的函数.

宁晋县13521751290: 求计算机图形学要用的open gl安装包,我上网没找到下载.我只有easyx,但是那个图形库只能支持Windows -
素琬卤米: 个人意见:初学编程的时候,不要在意环境.不管 linux 还是 win,熟悉哪个用哪个.如果因为配置环境影响了学习编程的进度,那就得不偿失了.对于大多数人而言,win 的环境配置比较简单,所以我建议你用 win + easyx 这样简单的配置,可以在几分钟内搞定,然后专心学习编程.熟悉编程后,不管是 opengl 还是 directx,都可以很快适应,根本不存在找不到安装包的问题.

宁晋县13521751290: 采用OpenGL实现二维物体的各种变换,例如:平移、旋转灯 求代码及运行结果 计算机图形学 -
素琬卤米: glTranslate(float x, float y, float z); x, y, z表示平移量,二维平移可以将z设成0glRotate(float theta, float x, float y, float z); theta表示旋转角度,x,y,z表示旋转轴

宁晋县13521751290: 求程序的详细注解opencv谢谢 -
素琬卤米: #include "stdafx.h" /* Windows 标准信息头文件 */#include"cv.h" /* 这个不用说了吧 ?*/#include"highgui.h" /* Opencv 的显示库文件名 */ int main(int argc,char** argv) { /* 声明 并创建两个 3x3 的浮点数据类型的矩阵 */ CvPoint2D32f srcTri[3],...

宁晋县13521751290: #include<stdio.h> main() {int i,j=2; if((i=fork())==0) {j++;} else{j -- ;} printf("%d",j); } -
素琬卤米: //代码功能注释如下:#include#include int main() { int i, j=2; if((i=fork())==0) { //子进程执行 j++; } else{ //父进程执行 j--; } printf("%d",j); return 0; } fork==0时表示是子进程.这里的变量j,在fork之后,父子进程都是独立拥有一个j变量的,所以输出可能是 13 也可能是31, 通常是13,父进程没有wait子进程速度较快,先退出了.

宁晋县13521751290: C语言程序求注释 -
素琬卤米: 楼主你好. void output(Student stuArray[]) { int i,j; printf("| 学号 | 姓名 | 成绩1 | 成绩2 | 成绩3 | 成绩4 | 总分 | 平均分|\n");//打印表头 printf("|------|--------------|-------|-------|-------|-------|-------|-------|\n"); for(i=0;i<length;i++) { printf("|%-6s|%-14s|", ...

宁晋县13521751290: 跪求能用Visual C++软件运行起来的图形的代码,现在我们有门课《计算机图形学》,老师要求用代码能随便运 -
素琬卤米: openGL库可以吧 你可以试试 随便搜咯openGL的代码 网上有的是 但是你需要在本机配置openGL的环境 这个网上也有很多教程

宁晋县13521751290: Open GL可以用来干什么 -
素琬卤米: OpenGL(全写Open Graphics Library)是个定义了一个跨编程语言、跨平台的编程接口的规格,它用于三维图象(二维的亦可).OpenGL是个专业的图形程序接口,是一个功能强大,调用方便的底层图形库.OpenGL™ 是行业领域中最为广...

宁晋县13521751290: 计算机图形学问题,给出完整代码,急!急!...
素琬卤米: 把这里的OnPain函数换成下面的就可以了: http://wenwen.soso.com/z/q137035891.htm void CMainWnd::OnPaint() { CPaintDC dc(this); RECT rect; TEXTMETRIC tm; GetClientRect(&rect); CString a("学号:0001"); CString b("姓名:゜...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网