When we control the event,we control your lives
 
IndexTrợ giúpTìm kiếmThành viênNhómĐăng kýĐăng Nhập
Tìm kiếm
 
 

Display results as :
 
Rechercher Advanced Search
Latest topics
» Tô màu theo vùng quét
Tue Aug 13, 2013 4:18 pm by minhlap

» authentischen Hermes Lindy Taschen
Wed Jan 23, 2013 11:15 am by cangliang

» Hermes Bag
Wed Jan 23, 2013 11:14 am by cangliang

» Hermes Evelyn pm
Wed Jan 23, 2013 11:13 am by cangliang

» Hermes Kelly bag billig
Mon Jan 21, 2013 8:57 am by cangliang

» Hermes Constance Bag
Mon Jan 21, 2013 8:56 am by cangliang

» Discout Hermes Belt
Mon Jan 21, 2013 8:55 am by cangliang

» Christian Louboutin Love Flats
Tue Jan 15, 2013 12:25 pm by cangliang

» Christian Louboutin Love Flats
Tue Jan 15, 2013 12:25 pm by cangliang

Navigation
 Portal
 Diễn Đàn
 Thành viên
 Lý lịch
 Trợ giúp
 Tìm kiếm
December 2016
MonTueWedThuFriSatSun
   1234
567891011
12131415161718
19202122232425
262728293031 
CalendarCalendar
Diễn Đàn
Affiliates
free forum


Share | 
 

 Bai bat quai

Xem chủ đề cũ hơn Xem chủ đề mới hơn Go down 
Tác giảThông điệp
minhlap
Admin - Quản trị viên
Admin - Quản trị viên


Tổng số bài gửi : 129
Points : 374
Reputation : 5
Join date : 22/07/2009
Age : 27
Đến từ : TP Hồ Chí Minh

Bài gửiTiêu đề: Bai bat quai   Sat Dec 12, 2009 6:50 pm

v#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
#include
#include
#include"Afine.h"
#include "glut.h"
#define Round(x) int(x+0.5)
int width,height,xc=200,yc=200,xi,yi;
void DrawLineDDA(int x1,int y1,int x2,int y2);
void swap(int &a,int &b);
void FillCircle(int xc,int yc,int r);
void Fill4Line(int xc,int yc,int x,int y);
void FillLine(int a,int b,int y);
// bien toan cuc de xoay
int dx=10,dy=10;
int cung=0;
float xtam1=xc+20,ytam1=yc-5,xtam2=xc-20,ytam2=yc+5;
float xc1=xc-20,yc1=yc+10,xc2=xc+20,yc2=yc-10;
/*
xtam1=xc+20;
xtam2=xc-20;
ytam1=yc-5;
ytam2=yc+5;
xc1=xc-20; yc1 = yc+10;
xc2 = xc+20; yc2 = yc -10;
*/
void FillCung(int x,int y,int r,int begin,int end);
struct colorentry
{
GLubyte Red;
GLubyte Blue;
GLubyte Green;
colorentry() {Red=Green=Blue=0; }
colorentry(GLbyte R,GLbyte G,GLbyte B)
{
Red=R;
Green=G;
Blue=B;
}
int operator==(colorentry &c)
{
return (Red==c.Red && Green==c.Green && Blue==c.Blue);
}
int operator!=(colorentry &c)
{
return !(*this==c);
}
};

void PutPixel(int x,int y,colorentry c);
void PutPixel(int x,int y);
colorentry GetPixel(int x,int y);
void tamgiac(int x1,int y1,int x2,int y2,int goc)
{
float xout,yout;
matrix33 m;
matrix_id(m);
glBegin(GL_POLYGON);
glVertex2f(x1,y1);
glVertex2f(x2,y2);
matrix_rotate(m,goc,x1,y1);
mul_matrix(x2,y2,m,xout,yout);
glVertex2f(xout,yout);
glEnd();
}
void batgiacfull(int x,int y,int r);
void consau(int r)// ve tai tam man hinh
{
glColor3ub(0,0,0);
FillCung(xc,yc,40,cung,cung+180);
glColor3ub(0,255,0);
FillCung(xc,yc,40,cung+180,cung+360);

glColor3ub(0,255,0);
FillCung(xtam1,ytam1,20,cung,cung+180);

glColor3ub(0,0,0);

FillCung(xtam2,ytam2,20,cung+180,cung+360);


}
void batgiac(int x,int y,int r);
void tua(int x,int y,int r);
void batquai()
{
batgiac(xc,yc,100);
tua(xc,yc,100);
glColor3ub(255,255,0);

batgiacfull(xc,yc,80);

consau(40);
glColor3ub(255,255,0);
FillCircle(xc1,yc1,10);
glColor3ub(0,0,0);
FillCircle(xc2,yc2,10);
}
//-----------------------------------

void mydraw()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3ub(255,0,0);
batquai();

glFlush();
glutSwapBuffers();
}
void myInit()
{
width=glutGet(GLUT_WINDOW_WIDTH);
height=glutGet(GLUT_WINDOW_HEIGHT);
// xc=width/2;
// yc=height/2;


}
void onkey(unsigned char key,int x,int y);
void OnSize(int width,int height);
void myidle();
void ontime(int ns)
{
float x1,y1;

cung+=10;
matrix33 mkq;
matrix_id(mkq);
matrix_rotate(mkq,10,xc,yc);
mul_matrix(xtam1,ytam1,mkq,xtam1,ytam1);
mul_matrix(xtam2,ytam2,mkq,xtam2,ytam2);
mul_matrix(xc1,yc1,mkq,xc1,yc1);
mul_matrix(xc2,yc2,mkq,xc2,yc2);
//di chuyen dung goc man hinh doi lai



glutTimerFunc(100,ontime,100);
}
void main()
{
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);
glutInitWindowPosition(100,100);
glutInitWindowSize(640,480);
glutCreateWindow("hello");
myInit();
glutDisplayFunc(mydraw);
glutReshapeFunc(OnSize);
glutKeyboardFunc(onkey);
glutTimerFunc(100,ontime,100);
glutIdleFunc(myidle);
glutMainLoop();
}
void onkey(unsigned char key,int x,int y)
{
switch(key)
{
case 27:
exit(0);
}
}
void OnSize(int width,int height)
{
glViewport(0, 0 , (GLsizei)width,(GLsizei)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,(GLdouble)width,0, (GLdouble)height);
}
void myidle()
{
glutPostRedisplay();
}
void batgiacfull(int x,int y,int r)
{
float x1,y1,x1out,y1out;
x1=x+r;
y1=y;
matrix33 mkq; matrix_id(mkq);
matrix_rotate(mkq,22.5,x,y); // xoay quanh xc,yc
mul_matrix(x1,y1,mkq,x1out,y1out);
glColor3ub(255,0,255);
tamgiac(x,y,x1out,y1out,45);

glColor3ub(0,0,255);
matrix_rotate(mkq,45,x,y); // xoay quanh xc,yc
mul_matrix(x1,y1,mkq,x1out,y1out);
tamgiac(x,y,x1out,y1out,45);

glColor3ub(0,255,255);
matrix_rotate(mkq,45,x,y); // xoay quanh xc,yc
mul_matrix(x1,y1,mkq,x1out,y1out);
tamgiac(x,y,x1out,y1out,45);

glColor3ub(255,255,0);
matrix_rotate(mkq,45,x,y); // xoay quanh xc,yc
mul_matrix(x1,y1,mkq,x1out,y1out);
tamgiac(x,y,x1out,y1out,45);

glColor3ub(100,100,255);
matrix_rotate(mkq,45,x,y); // xoay quanh xc,yc
mul_matrix(x1,y1,mkq,x1out,y1out);
tamgiac(x,y,x1out,y1out,45);

glColor3ub(0,100,255);
matrix_rotate(mkq,45,x,y); // xoay quanh xc,yc
mul_matrix(x1,y1,mkq,x1out,y1out);
tamgiac(x,y,x1out,y1out,45);

glColor3ub(100,0,100);
matrix_rotate(mkq,45,x,y); // xoay quanh xc,yc
mul_matrix(x1,y1,mkq,x1out,y1out);
tamgiac(x,y,x1out,y1out,45);

glColor3ub(200,100,255);
matrix_rotate(mkq,45,x,y); // xoay quanh xc,yc
mul_matrix(x1,y1,mkq,x1out,y1out);
tamgiac(x,y,x1out,y1out,45);

}
void PutPixel(int x,int y,colorentry c)
{
glColor3ub(c.Red,c.Green,c.Blue);
glBegin(GL_POINTS);
glVertex2f(x,y);
glEnd();
}
void PutPixel(int x,int y)
{
glBegin(GL_POINTS);
glVertex2f(x,y);
glEnd();
}
colorentry GetPixel(int x,int y)
{
GLbyte color[3];
float Pos[4];
glRasterPos2d(x,y);
glGetFloatv(GL_CURRENT_RASTER_POSITION,Pos);
glReadPixels(Pos[0],Pos[1],1,1,GL_RGB,GL_UNSIGNED_BYTE,color);
return colorentry(color[0],color[1],color[2]);
}

void DrawLineDDA(int x1,int y1,int x2,int y2)
{
float ax,ay,x,y;
float m;
ax=x2-x1;
ay=y2-y1;
if(abs(ax)>= abs(ay))
{
if(x1>x2)
{
swap(x1,x2);
swap(y1,y2);
}
m=(float)(y2-y1)/(x2-x1);
y=y1;
for(x=x1;x {
PutPixel(x,Round(y));
y+=m;
}
}
else
{
if(y1>y2)
{
swap(x1,x2);
swap(y1,y2);
}
x=x1;
m=(float)(x2-x1)/(y2-y1);
for(y=y1;y {
PutPixel(Round(x),y);
x+=m;
}
}
}
void swap(int &a,int &b)
{
int x=a;
a=b;
b=x;
}
void Fill4Line(int xc,int yc,int x,int y)
{
FillLine(-x+xc,x+xc,y+yc);
FillLine(-x+xc,x+xc,-y+yc);
FillLine(-y+xc,y+xc,x+yc);
FillLine(-y+xc,y+xc,-x+yc);

}
void FillCircle(int xc,int yc,int r)
{
int x=0,y=r;
int p=1-r;
Fill4Line(xc,yc,x,y);
while(x {
if(p<0)
p+=(x<<1)+3;
else
{
p+=((x-y)<<1)+5;
y--;
}
++x;
Fill4Line(xc,yc,x,y);
}
}
void FillLine(int a,int b,int y)
{
for(int i=a;i PutPixel(i,y);
}

void batgiac(int x,int y,int r)
{
float x1,y1,x1out,y1out;
x1=x+r;
y1=y;
matrix33 mkq; matrix_id(mkq);
glBegin(GL_LINE_LOOP);
matrix_rotate(mkq,22.5,x,y); // xoay quanh xc,yc
mul_matrix(x1,y1,mkq,x1out,y1out);
glVertex2f(x1out,y1out);
for(float i=0;i<360-22.5;i+=45)
{
matrix_rotate(mkq,45,x,y); // xoay quanh xc,yc
mul_matrix(x1,y1,mkq,x1out,y1out);
glVertex2f(x1out,y1out);
}
glEnd();
}
void tua(int x,int y,int r)
{
float x1,y1,x1out,y1out;
x1=x+r;
y1=y;
matrix33 mkq; matrix_id(mkq);
matrix_rotate(mkq,22.5,x,y); // xoay quanh xc,yc
mul_matrix(x1,y1,mkq,x1out,y1out);
DrawLineDDA(x,y,x1out,y1out);
for(float i=22.5;i<360+22.5;i+=45)
{
matrix_rotate(mkq,45,x,y); // xoay quanh xc,yc
mul_matrix(x1,y1,mkq,x1out,y1out);
DrawLineDDA(x,y,x1out,y1out);
}
}
void FillCung(int x,int y,int r,int begin,int end)
{
int x1,y1;
glBegin(GL_POLYGON);
glVertex2f(x,y);
for(int i=begin;i {
x1=x+r*cos(RAD(i));
y1=y+r*sin(RAD(i));
glVertex2f(x1,y1);
}
glEnd();
}

_________________
minhlapit
Về Đầu Trang Go down
Xem lý lịch thành viên http://minhlap.allgoo.us
 
Bai bat quai
Xem chủ đề cũ hơn Xem chủ đề mới hơn Về Đầu Trang 
Trang 1 trong tổng số 1 trang
 Similar topics
-
» IN TUI XỐP, IN TUI XOP, IN BAO XỐP GIÁ RẺ - ĐT: 0937.345.224
» Hướng Dẫn Chơi [Neon Ninja]

Permissions in this forum:Bạn không có quyền trả lời bài viết
minhlap.allgoo.us :: Lập trình :: Lập Trình Hướng Đối Tượng,Đồ Họa OpenGL C, C++-
Chuyển đến