perl-opengl几何变换函数

来源:互联网 发布:整型变量的数据范围 编辑:程序博客网 时间:2024/04/30 23:31
Perl代码 复制代码 收藏代码
  1. #!/usr/bin/perl -w   
  2. use strict;   
  3. use warnings;   
  4. use OpenGL qw/ :all /;   
  5. use OpenGL::Config;      
  6.   
  7. glutInit();   
  8. glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);   
  9. glutInitWindowPosition(100,100);   
  10. glutInitWindowSize(400,400);   
  11. glutCreateWindow("opengl");   
  12. glClearColor(0,0,0,255);   
  13. glClear(GL_COLOR_BUFFER_BIT);     
  14. glMatrixMode(GL_PROJECTION);   
  15. gluOrtho2D(-100,100,-100,100);   
  16. glMatrixMode(GL_MODELVIEW);   
  17. glutDisplayFunc(\&mydis);   
  18. glutMainLoop();   
  19. return 0;   
  20.   
  21. sub mydis()   
  22. {   
  23.   glClearColor(0,0,0,255);   
  24.   glClear(GL_COLOR_BUFFER_BIT);    
  25.   glLoadIdentity();   
  26.   glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);     
  27.   glColor3f(1,1,1);   
  28.   glBegin(GL_LINES);   
  29.   glVertex2f(-100,0);   
  30.   glVertex2f(100,0);    
  31.   glEnd();   
  32.   glBegin(GL_LINES);   
  33.   glVertex2f(0,-100);   
  34.   glVertex2f(0,100);    
  35.   glEnd();    
  36.   # 画矩形   
  37.   glColor3f(0.5,0.1,0);     
  38.   glRecti(-50,-50,50,50);   
  39.   glFlush();   
  40.   glPushMatrix();   
  41.   #向x方向移动3.5个单位,y方向移动8.5个单位   
  42.   glColor3f(0.1,0.1,0.9);     
  43.   glTranslatef(3.5,8.5,0);   
  44.   glRecti(-50,-50,50,50);   
  45.   glFlush();     
  46.   glPopMatrix();   
  47.   glPushMatrix();     
  48.   #x方向放大到1.2倍,y方向放大到1.8倍   
  49.   glColor3f(0.1,0.9,0.1);    
  50.   glScalef(1.2,1.8,1);    
  51.   glRecti(-50,-50,50,50);   
  52.   glFlush();    
  53.   glPopMatrix();   
  54.   glPushMatrix();      
  55.   #x方向缩小至0.5倍,y方向缩小至0.8倍   
  56.   glColor3f(0.9,0.9,0.9);    
  57.   glScalef(0.5,0.8,1);    
  58.   glRecti(-50,-50,50,50);   
  59.   glFlush();    
  60.   glPopMatrix();   
  61.   glPushMatrix();     
  62.   #二维旋转,相对于坐标原点的   
  63.   glColor3f(0.7,0.8,0.7);   
  64.   my ($x1,$y1,$x2,$y2)=(15,15,15,50);   
  65.   for (my $theta=5;$theta<360;$theta+=5)   
  66.   {    
  67.     glRotatef($theta,0,0,1);#相对于z轴   
  68.     glRecti(-50,-50,50,50);    
  69.   }       
  70.   glFlush();     
  71. }  

 

 

原创粉丝点击