问题描述
- 计算机图形学OpenGL的问题,急求大神指点
-
用多边形逼近算法花了一个多边形,然后需要修改一个点的坐标,让其不规则,请问如何修改一个点的坐标?逼近算法如下:
void COpenGLView::BiJin(int radius,Ploygon *ploygon)
{
int i,n;
float x,y,xnew,ynew,alfa,co,si;
alfa=2*acos(((float)radius-DELTA)/(float)radius);
n=(int)(2*3.14159/alfa);
alfa=2*3.14159/n;
ploygon->pointNum=n;
pointnumber=n;
ploygon->vertices=(Point *)malloc(n*sizeof(Point));
x=0.0;
y=(float)radius;
ploygon->vertices[0].x=0;
ploygon->vertices[0].y=radius;
co=cos(alfa);
si=sin(alfa);
SetPixel(ploygon->vertices[0].x,ploygon->vertices[0].y,1,0,0);
for(i=1;i
{
xnew=co*x-si*y;
ynew=si*x+co*y;
x=xnew;
y=ynew;
ploygon->vertices[i].x=(int)(x+0.5);
ploygon->vertices[i].y=(int)(y+0.5);
SetPixel(ploygon->vertices[i].x,ploygon->vertices[i].y,1,0,0);
glColor3f(1,0,0);
glLineWidth(1.0f);
glBegin(GL_LINES);
glVertex2f(ploygon->vertices[i-1].x,ploygon->vertices[i-1].y);
glVertex2f(ploygon->vertices[i].x,ploygon->vertices[i].y);glEnd();
}
glColor3f(1,0,0);
glLineWidth(1.0f);
glBegin(GL_LINES);
glVertex2f(ploygon->vertices[i-1].x,ploygon->vertices[i-1].y);
glVertex2f(ploygon->vertices[0].x,ploygon->vertices[0].y);glEnd();
}
然后是扫描线填充,调用这个算法:
BiJin(radius,ploygon);//改变一个点
老师说只需要在这条语句后边改变任意点的坐标,然后再用扫描线填充。可是不知道怎么变啊,这些点不是整体画出来的吗?求指教
时间: 2024-10-27 02:25:19