Tin Kien Giang K31
Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.

Tin Kien Giang K31

Chao mung den voi dien dan Tin-KG Khoa 31
 
Trang ChínhTìm kiếmLatest imagesĐăng kýĐăng Nhập

 

 Vẽ Đường Thẳng Và Đường Tròn

Go down 
Tác giảThông điệp
vvhungtam




Tổng số bài gửi : 11
Registration date : 16/09/2007

Vẽ Đường Thẳng Và Đường Tròn Empty
Bài gửiTiêu đề: Vẽ Đường Thẳng Và Đường Tròn   Vẽ Đường Thẳng Và Đường Tròn Empty6/10/2008, 23:01

Trong C++ không có thư viện graphics.h nên mình dùng thư viện Glut.h, các bạn có thể download3 file glut.dll, glut.lib, glut.h theo sự chỉ dẫn của bạn Huấn. Sau đó:

chep file glut32.dll vào C:\WINDOWS\system32 chep file glut32.dll
chep file glut32.lib vào C:\Program Files\Microsoft Visual Studio\VC98\Lib chep file glut32.lib
chep file glut.h vào C:\Program Files\Microsoft Visual Studio\VC98\Include\GL

Bạn nào không download 3 file được thi cứ liên lạc với mình.

Chương trình ví dụ về vẽ đường tròn và dường thẳng như sau:
Code:

#include <gl/glut.h>
#include <iostream>
#include <windows.h>

using namespace std;

GLsizei wh = 450 ;
GLsizei ww = 600 ;

struct Diem
{
   int x;
   int y;
};

Diem P1,P2,P,I;
int BK;

void Besenham (Diem P1,Diem P2)
{
   glClear ( GL_COLOR_BUFFER_BIT ); //clear pixel buffer
   glBegin(GL_POINTS); // render with points

   int Dx,Dy,p,Const1,Const2;
   Diem P;
   
   Dx= P2.x-P1.x;
   Dy= P2.y-P1.y;

   p=2*Dy-Dx;

   Const1=2*Dy;
   Const2=2*(Dy-Dx);

   P.x=P1.x;
   P.y=P1.y;
   
   glVertex2i(P.x,P.y);

   for(int i=P1.x;i<P2.x;i++)
   {
      if(p<0)
         p+=Const1;
      else
      {
         p+=Const2;
         P.y++;
      }
      P.x++;
      glVertex2i(P.x,P.y);
   }
   glEnd();
   glFlush();
}//display a point

void Besenham_Phu ()
{
   Besenham (P1,P2);
}

void Put8Pixel (int x,int y)
{
   glVertex2i(x,y);
   glVertex2i(y+I.x-I.y,x-I.x+I.y);
   glVertex2i(y+I.x-I.y,-x+I.x+I.y);
   glVertex2i(x,2*I.y-y);
   glVertex2i(-x+2*I.x,-y+2*I.y);
   glVertex2i(-y+I.x+I.y,-x+I.x+I.y);
   glVertex2i(-y+I.x+I.y,x-I.x+I.y);
   glVertex2i(2*I.x-x,y);
}

void CircleMidPoint (Diem I,int R)
{
   glClear ( GL_COLOR_BUFFER_BIT ); //clear pixel buffer
   glBegin(GL_POINTS); // render with points

   int x=I.x , y=I.y+R;
   Put8Pixel(x,y);
   float p=5/4-R;
   while(x-I.x<y-I.y)
   {
      if(p<0)
            p+=2*(x-I.x)+3;
      else
      {
         p+=2*(x-I.x-y+I.y)+5;
         y--;
      }

      x++;
      Put8Pixel(x,y);
   }
   glEnd();
   glFlush();
}

void CircleMidPoint_Phu ()
{
   CircleMidPoint (I,BK);
}

void MyInit (float R,float G,float B)
{
   cout << glGetString(GL_VERSION) <<"\n";
   cout << glGetString(GL_VENDOR) <<"\n";
   glClearColor ( 1.0, 1.0, 1.0,0.0);    //white background
   glColor3f(G,R,B);                      //green drawing colour
   glPointSize(2);                      //10 pixel dot!
   glMatrixMode ( GL_PROJECTION );
   glLoadIdentity ( );
   gluOrtho2D ( 0.0, (GLdouble)ww, 0.0, (GLdouble)wh ); //Display area
}

void main ()
{
   float R,G,B;
   cout<<"Nhap Toa Do Tam Duong Tron: ";  cin>>I.x>>I.y;
   cout<<"Nhap Ban Kinh Duong Tron: ";    cin>>BK;
   cout<<"Nhap Gia Tri RGP ([0,1]): ";    cin>>R>>G>>B;
   //cout<<"Nhap Toa Do Diem Dau: ";      cin>>P1.x>>P1.y;
   //cout<<"Nhap Toa Do Diem Cuoi: ";      cin>>P2.x>>P2.y;

   glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );
   glutInitWindowSize( ww, wh ); // window size
   glutInitWindowPosition ( 90, 80 ); // & position on screen
   glutCreateWindow ( "Ve duong tron" );
   MyInit (R,G,B);
   glutDisplayFunc (CircleMidPoint_Phu);
   //glutDisplayFunc (Besenham_Phu);
   glutMainLoop ();
}
Về Đầu Trang Go down
 
Vẽ Đường Thẳng Và Đường Tròn
Về Đầu Trang 
Trang 1 trong tổng số 1 trang

Permissions in this forum:Bạn không có quyền trả lời bài viết
Tin Kien Giang K31 :: Cộng Đồng :: Cộng Đồng :: Tài liệu tham khảo-
Chuyển đến