如何用vc++画圆形图像
来源:百度知道 编辑:UC知道 时间:2024/06/18 03:25:17
#include<GL/glut.h>
class screenPt
{
private:
Glint x,y;
public
x=y=0;
}
void setCoords(Glint xCoordValue, Glint yCoordValue){
x=xCoordValue;
y=yCoordValue;
}
Glint getx()const{
return x;
}
Glint gety()const{
return y;
}
Void incrementsx(){
x++;
}
Void decrementy(){
y--;
}
};
Void setPixel(Glint xCoord,Glint yCoord)
{
glBegin(GL_POINTS);
glVertex2i(xCoord,yCoord);
glEnd();
}
void circleMidpoint(Glint xc,Glint yc,Glint radius)
{
screenPt circPt;
Glint o=1-radius;
circPt.setCoords(0,radius);
void circlePlotPoints(Glint,Glint,screenPt);
circlePlotPoints(xc,yc,circPt);
while(circPt.get()<circPt.gety()){
circpt.incrementx();
if(p,0)
p+=2*circPt.getx()+1;
else{
circPt.decrementy();<
class screenPt
{
private:
Glint x,y;
public
x=y=0;
}
void setCoords(Glint xCoordValue, Glint yCoordValue){
x=xCoordValue;
y=yCoordValue;
}
Glint getx()const{
return x;
}
Glint gety()const{
return y;
}
Void incrementsx(){
x++;
}
Void decrementy(){
y--;
}
};
Void setPixel(Glint xCoord,Glint yCoord)
{
glBegin(GL_POINTS);
glVertex2i(xCoord,yCoord);
glEnd();
}
void circleMidpoint(Glint xc,Glint yc,Glint radius)
{
screenPt circPt;
Glint o=1-radius;
circPt.setCoords(0,radius);
void circlePlotPoints(Glint,Glint,screenPt);
circlePlotPoints(xc,yc,circPt);
while(circPt.get()<circPt.gety()){
circpt.incrementx();
if(p,0)
p+=2*circPt.getx()+1;
else{
circPt.decrementy();<
楼主是不是想通过你给的代码来画出圆形?
如果是的话, 你就按照圆形的参数方程 x = r*cos(d)
y = r* sin (d)
计算出每个园上 每个点的坐标,在用你的类里面的circlePlotPoints 函数 或者 setPixel 把每个点画出来就行了
如果是想问用什么函数画园, 可以选择用mfc中的 pDC->Ellipse(); 参数去查msdn
或者 opengl 中的函数。
VC++画圆形可以使用API函数:Ellipse(int x1, int y1, int x2, int y2);
其画圆的原理是矩形的内切圆,四个参数中的前两个是矩形左上角坐标,后两个是矩形右下角坐标。VC++画图形前得先有一块画布DC即设备上下文。下面个例子:
void CrrDlg::PaintCircle() //画实心圆函数
{
CDC *pDC = this->GetDC(); //获取DC
CBrush brush,*oldbrush; //画刷
//通过定时器中num递增,实现红色圆形与绿色圆形交替出现,即闪灯现象
if (num%2){ //num为定时器计数参数,其为偶数时画红色圆形
brush.CreateSolidBrush(RGB(255,0,0));
}
else{ //num为奇数时,画绿色圆形
brush.CreateSolidBrush(RGB(0,255,0));
}
oldbrush=pDC->SelectObject(&brush);
<