C++ Opengl-鼠标拖动绘制平滑圆
我想用鼠标拖动画一个平滑的圆。也就是说,在第一次单击鼠标时,将设置起点,在拖动鼠标时,将更新终点并展开圆。我在某个地方读到过,可以用线条条画画。但那不符合我的要求 简而言之,我需要使用opengl使用给定的两点绘制一个圆的逻辑。如果您有:C++ Opengl-鼠标拖动绘制平滑圆,c++,opengl,mouse,C++,Opengl,Mouse,我想用鼠标拖动画一个平滑的圆。也就是说,在第一次单击鼠标时,将设置起点,在拖动鼠标时,将更新终点并展开圆。我在某个地方读到过,可以用线条条画画。但那不符合我的要求 简而言之,我需要使用opengl使用给定的两点绘制一个圆的逻辑。如果您有: top-left position (X1 Y1) 及 你也有 diameter (sqrt([X2-X1]^2+[Y2-Y1]^2)) radius (diameter/2) 和中心: CenterX = X1 + (radius * (sin(-at
top-left position (X1 Y1)
及
你也有
diameter (sqrt([X2-X1]^2+[Y2-Y1]^2))
radius (diameter/2)
和中心:
CenterX = X1 + (radius * (sin(-atan2(Y2-Y1,X2-X1))));
CenterY = Y1 + (radius * (cos(-atan2(Y2-Y1,X2-X1))));
从那一点开始,你可以用你喜欢的任何方式从中心画一个半径为给定的圆
double max = 2.0 * PI;
double precision = 0.1;
double current = 0.0;
struct point
{
double x;
double y;
};
while(current <= max)
{
point one;
point two;
one.x = Center.x + (radius * (sin(-current)));
one.y = Center.y + (radius * (cos(-current)));
current += precision;
two.x = Center.x + (radius * (sin(-current)));
two.y = Center.y + (radius * (cos(-current)));
//draw line between one and two?
//draw here
}
double max=2.0*PI;
双精度=0.1;
双电流=0.0;
结构点
{
双x;
双y;
};
而(当前绘制线(D3DXVECTOR3((float)1.x,(float)1.y,1.0),D3DXVECTOR3((float)2.x,(float)2.y,1.0),0xFFFFFFFF);
}
//render->EndRender();
}
输出:
起点和终点代表什么?中心和半径(从起点到终点的距离)还是圆圈边界的左上角和右下角?@Vite Falcon左上角和右下角right@ViteFalcon那么,什么符合你的要求呢?计算机不能画一个完美的圆,它们总是近似的。如果线条条不适合你,最好知道还有什么。
double max = 2.0 * PI;
double precision = 0.1;
double current = 0.0;
struct point
{
double x;
double y;
};
while(current <= max)
{
point one;
point two;
one.x = Center.x + (radius * (sin(-current)));
one.y = Center.y + (radius * (cos(-current)));
current += precision;
two.x = Center.x + (radius * (sin(-current)));
two.y = Center.y + (radius * (cos(-current)));
//draw line between one and two?
//draw here
}
//draw fun
{
struct point
{
double x,y;
point(double x,double y) : x(x), y(y) {}
point(){ x = 0.0, y = 0.0; }
};
point start(100.0,100.0);
point end(150.0,150.0);
point center;
double diameter = sqrt(pow(end.x-start.x,2.0)+pow(end.y-start.y,2.0));
double radius = diameter/2.0;
double max = 2.0 * PId;
double precision = max/180.0;
double current = 0.0;
center.x = start.x + (radius * (sin(-atan2(end.y-start.y,end.x-start.x))));
center.y = start.y + (radius * (cos(-atan2(end.y-start.y,end.x-start.x))));
//render->BeginRender();
while(current <= max)
{
point one;
//point two;
one.x = center.x + (radius * (sin(-current)));
one.y = center.y + (radius * (cos(-current)));
render->D3DBox((float)one.x,(float)one.y,1.0f,1.0f,0xFFFFFFFF);//create a dot
current += precision;
//two.x = center.x + (radius * (sin(-current)));
//two.y = center.y + (radius * (cos(-current)));
//
//render->DrawLine(D3DXVECTOR3((float)one.x,(float)one.y,1.0),D3DXVECTOR3((float)two.x,(float)two.y,1.0),0xFFFFFFFF);
}
//render->EndRender();
}