首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 平面设计 > 图形图像 >

perl-opengl根本图形操作-缩放,二维旋转,二维平移

2013-02-02 
perl-opengl基本图形操作-缩放,二维旋转,二维平移#!/usr/bin/perl -wuse strictuse warningsuse OpenGL

perl-opengl基本图形操作-缩放,二维旋转,二维平移
#!/usr/bin/perl -wuse strict;use warnings;use OpenGL qw/ :all /;use OpenGL::Config; glutInit();glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);glutInitWindowPosition(100,100);glutInitWindowSize(400,400);glutCreateWindow("平移");glClearColor(0,0,0,255);glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION);gluOrtho2D(-100,100,-100,100);glutDisplayFunc(\&mydis);glutMainLoop();return 0;sub mydis(){ glColor3f(0,255,0); glBegin(GL_LINES); glVertex2f(-100,0); glVertex2f(100,0); glEnd(); glBegin(GL_LINES); glVertex2f(0,-100); glVertex2f(0,100); glEnd(); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); # 画矩形 glColor3f(0.5,0.5,0); glRecti(-50,-50,50,50); glFlush(); #向x方向移动5个单位,y方向移动10个单位 glColor3f(0.2,0.2,0.9); glRecti(-50+5,-50+10,50+5,50+10); glFlush(); #直线的二维旋转,以(5,10)为基准点旋转 glColor3f(0.1,0.8,0.5); my ($x1,$y1,$x2,$y2)=(15,15,15,50); for (my $theta=10;$theta<360;$theta+=10) { glBegin(GL_LINES); glVertex2f(5+($x1-5)*cos($theta)-($y1-10)*sin($theta),10+($x1-5)*sin($theta)+($y1-10)*cos($theta)); glVertex2f(5+($x2-5)*cos($theta)-($y2-10)*sin($theta),10+($x2-5)*sin($theta)+($y2-10)*cos($theta)); glEnd(); glFlush(); } #缩放 #缩小成原来大小的0.8 glColor3f(0.6,0.1,0.1); glRecti((-50+5)*0.8,(-50+10)*0.8,(50+5)*0.8,(50+10)*0.8); glFlush(); #放大成原来大小的1.5 glColor3f(0.1,0.9,0.1); glRecti((-50+5)*1.5,(-50+10)*1.5,(50+5)*1.5,(50+10)*1.5); glFlush(); }

?


perl-opengl根本图形操作-缩放,二维旋转,二维平移
?

热点排行