Perl代码 perl-opengl几何变换函数 perl-opengl几何变换函数perl-opengl几何变换函数
  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. }  
#!/usr/bin/perl -w
use strict;
use warnings;
use OpenGL qw/ :all /;
use OpenGL::Config;   

glutInit();
glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);
glutInitWindowPosition(100,100);
glutInitWindowSize(400,400);
glutCreateWindow("opengl");
glClearColor(0,0,0,255);
glClear(GL_COLOR_BUFFER_BIT);  
glMatrixMode(GL_PROJECTION);
gluOrtho2D(-100,100,-100,100);
glMatrixMode(GL_MODELVIEW);
glutDisplayFunc(\&mydis);
glutMainLoop();
return 0;

sub mydis()
{
  glClearColor(0,0,0,255);
  glClear(GL_COLOR_BUFFER_BIT); 
  glLoadIdentity();
  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);  
  glColor3f(1,1,1);
  glBegin(GL_LINES);
  glVertex2f(-100,0);
  glVertex2f(100,0); 
  glEnd();
  glBegin(GL_LINES);
  glVertex2f(0,-100);
  glVertex2f(0,100); 
  glEnd(); 
  # 画矩形
  glColor3f(0.5,0.1,0);  
  glRecti(-50,-50,50,50);
  glFlush();
  glPushMatrix();
  #向x方向移动3.5个单位,y方向移动8.5个单位
  glColor3f(0.1,0.1,0.9);  
  glTranslatef(3.5,8.5,0);
  glRecti(-50,-50,50,50);
  glFlush();  
  glPopMatrix();
  glPushMatrix();  
  #x方向放大到1.2倍,y方向放大到1.8倍
  glColor3f(0.1,0.9,0.1); 
  glScalef(1.2,1.8,1); 
  glRecti(-50,-50,50,50);
  glFlush(); 
  glPopMatrix();
  glPushMatrix();   
  #x方向缩小至0.5倍,y方向缩小至0.8倍
  glColor3f(0.9,0.9,0.9); 
  glScalef(0.5,0.8,1); 
  glRecti(-50,-50,50,50);
  glFlush(); 
  glPopMatrix();
  glPushMatrix();  
  #二维旋转,相对于坐标原点的
  glColor3f(0.7,0.8,0.7);
  my ($x1,$y1,$x2,$y2)=(15,15,15,50);
  for (my $theta=5;$theta<360;$theta+=5)
  { 
	glRotatef($theta,0,0,1);#相对于z轴
    glRecti(-50,-50,50,50); 
  }    
  glFlush();  
}


 
perl-opengl几何变换函数
 

转载于:https://www.cnblogs.com/shhaoran/archive/2013/02/02/2924535.html

分类:

技术点:

相关文章: