2013-06-11 5 views
0

마우스 끌기시 부드러운 원을 그립니다. 첫 번째 마우스 클릭시 시작점이 설정되고 마우스를 끌면 끝점이 업데이트되고 원이 확장됩니다. 나는 어딘가에 라인 스트립을 사용하여 그릴 수 있다고 읽었다. 그러나 그것은 나의 요구 사항에 맞지 않을 것이다.OpenGL - 마우스 끌기시 부드러운 원 그리기

간단히 말해서 OpenGL을 사용하여 주어진 두 점을 사용하여 원을 그리는 논리가 필요합니다.

+1

시작 지점과 끝 지점은 무엇을 나타 냅니까? 중심과 반경 (처음부터 끝까지의 거리) 또는 원 경계의 상단 왼쪽과 하단 오른쪽? –

+0

@ Vite Falcon 왼쪽 위 오른쪽 아래 – CodeRider

+0

@ViteFalcon 제발 도와주세요 – CodeRider

답변

2

글쎄, 당신은있는 경우 :

CenterX = X1 + (radius * (sin(-atan2(Y2-Y1,X2-X1)))); 
CenterY = Y1 + (radius * (cos(-atan2(Y2-Y1,X2-X1)))); 
: 당신은 또한

diameter (sqrt([X2-X1]^2+[Y2-Y1]^2)) 
radius (diameter/2) 

및 센터를

top-left position (X1 Y1) 

bottom-right position (X2 Y2) 

0

그 지점에서 원한다면 원하는 반경으로 중심에서 원을 그릴 수 있습니다! 정확하게이 코드를 수정하여 :

ByTheWay

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(); 
} 

출력 :

당신도 이것이 내가 내 코드에서 원을 그리는 방법이다, 어쨌든 ( while(current<=max))

을은 "의사 원"의 일부를 그릴 수 있습니다

enter image description here