用Perl在3D立方体中的点或球体

用Perl在3D立方体中的点或球体,第1张

概述假设我有@points [$number] [$x] [$y] [$z] [$color],我只是出于调试目的,希望它们在3D立方体中可视化以更好地观察我拥有的内容.通常我将它们导出到* .txt并使用R 3D绘图,但也许在Perl中有简单的方法可以做到这一点? 拥有半径的球体会更好. 我的回答:使用OpenGL perl绑定 我还没有完全回答你的问题,但我确信你可以采用这个代码 我以前没有做过O 假设我有@points [$number] [$x] [$y] [$z] [$color],我只是出于调试目的,希望它们在3D立方体中可视化以更好地观察我拥有的内容.通常我将它们导出到* .txt并使用R 3D绘图,但也许在Perl中有简单的方法可以做到这一点?
拥有半径的球体会更好.解决方法 我的回答:使用OpenGL perl绑定

我还没有完全回答你的问题,但我确信你可以采用这个代码

我以前没有做过OpenGL,但这是一个有趣的小夜晚项目

use OpenGL qw/ :all /;use constant ESCAPE => 27;# Global variable for our windowmy $window;my $CubeRot = 0;my $xCord = 1;my $yCord = 1;my $zCord = 0;my $rotSpeed = 0.02 ;($wIDth,$height) = (1366,768);@points = ( [ 30,40,[100,0]],#red            [ 100,100,[0,#green            [ 100,10,60,100]],#turquoise            [ 200,200,100]] #blue            );sub reshape  {  glVIEwport(0,$wIDth,$height); # Set our vIEwport to the size of our window  glMatrixMode(GL_PROJECTION); # Switch to the projection matrix so that we can manipulate how our scene is vIEwed  glLoadIDentity(); # reset the projection matrix to the IDentity matrix so that we don't get any artifacts (cleaning up)  gluPerspective(60,$wIDth / $height,1.0,100.0); # Set the FIEld of vIEw angle (in degrees),the aspect ratio of our window,and the new and far planes  glMatrixMode(GL_MODELVIEW); # Switch back to the model vIEw matrix,so that we can start drawing shapes correctly  glOrtho(0,$height,-1,1);   # Map abstract coords directly to window coords.   glScalef(1,1);           # Invert Y axis so increasing Y goes down.   glTranslatef(0,-h,0);       # Shift origin up to upper-left corner. }  sub keypressed {    # Shift the unsigned char key,and the x,y placement off @_,in    # that order.    my ($key,$x,$y) = @_;    # If escape is pressed,kill everything.    if ($key == ESCAPE)     {         # Shut down our window         glutDestroyWindow($window);         # Exit the program...normal termination.        exit(0);                       }}sub InitGL {                  # Shift the wIDth and height off of @_,in that order    my ($wIDth,$height) = @_;    # Set the background "clearing color" to black    glClearcolor(0.0,0.0,0.0);    # Enables clearing of the Depth buffer     glClearDepth(1.0);                        glDepthFunc(GL_LESS);             # Enables depth testing with that type    glEnable(GL_DEPTH_TEST);                  # Enables smooth color shading    glShadeModel(GL_SMOOTH);          # reset the projection matrix    glMatrixMode(GL_PROJECTION);    glLoadIDentity;    # reset the modelvIEw matrix    glMatrixMode(GL_MODELVIEW);}    sub display {      glClearcolor(1.0,1.0);     glClear(GL_color_BUFFER_BIT);    glLoadIDentity;    glTranslatef(0.0,-5.0); # Push eveything 5 units back into the scene,otherwise we won't see the primitive      #glPushmatrix();    #glrotatef($CubeRot,$xCord,$yCord,$zCord);   # this is where the drawing happens,adjust glTranslate to match your coordinates   # the centre is is 0,0    for my $sphere ( @points ) {        glPushmatrix();        glcolor3b( @{$sphere->[3]}) ;        glrotatef($CubeRot,$zCord);        glTranslatef($sphere->[0]/50 -2,$sphere->[1]/50 -2,$sphere->[2]/50 -2);        glutWireSphere(1.0,24,24); # Render the primitive          glPopMatrix();        }    $CubeRot += $rotSpeed;    glFlush; # Flush the OpenGL buffers to the window      }  # Initialize gluT stateglutinit;  # Depth buffer */  glutinitdisplayMode(gluT_SINGLE);# The window starts at the upper left corner of the screenglutinitwindowposition(0,0);  # Open the window  $window = glutCreateWindow("Press escape to quit");# Register the function to do all our OpenGL drawing.glutdisplayFunc(\&display);  # Go fullscreen.  This is as soon as possible. glutFullScreen;glutReshapeFunc(\&reshape);# Even if there are no events,redraw our gl scene.glutIDleFunc(\&display);# Register the function called when the keyboard is pressed.glutKeyboardFunc(\&keypressed);# Initialize our window.InitGL($wIDth,$height);# Start Event Processing EngineglutMainLoop;  return 1;
总结

以上是内存溢出为你收集整理的用Perl在3D立方体中的点或球体全部内容,希望文章能够帮你解决用Perl在3D立方体中的点或球体所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1236365.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存