Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

3d for Perl?

by iSina (Acolyte)
on Oct 21, 2007 at 17:54 UTC ( #646281=perlquestion: print w/replies, xml ) Need Help??
iSina has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I have some experience in using perl/tk. But I do not know how to add an interactive 3d windows in a perl/tk created window. Is there an addition like opengl where I can use it to create an interactive 3d "grid" in my program? I would appreciate any names and resources that I can study... Thanks

Replies are listed 'Best First'.
Re: 3d for Perl?
by shmem (Chancellor) on Oct 21, 2007 at 18:09 UTC
    PDL has a OpenGL 3D extension. Maybe that can serve as a starting point.


    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: 3d for Perl?
by Corion (Pope) on Oct 21, 2007 at 18:06 UTC

    There are OpenGL and OpenGL::Simple, but I'm not aware of any widget sets for either that would make displaying (3d) graphs easier.

      is it possible to include these as interactive widgets in a program written by perl/tk?
Re: 3d for Perl?
by marto (Bishop) on Oct 21, 2007 at 23:38 UTC
Re: 3d for Perl?
by zentara (Archbishop) on Oct 22, 2007 at 11:30 UTC
    PDL's OpenGL stuff can be displayed in a Tk window. How interactive it is, is can rotate with left-click drag, and zoom in/out with a right-click drag. Here is an example. (Don't ask for too many answers from me. The OpenGL coordinate view-space is "relative" to the largest axis, NOT straight cartesian. It's hard to explain it's behavior, but when you try and plot, you will see what I mean. I just hacked this :-) )
    #!/usr/bin/perl use warnings; use strict; use Tk; use PDL; use PDL::Graphics::TriD; use PDL::Graphics::TriD::Contours; use PDL::Graphics::TriD::GL; use PDL::Graphics::TriD::Tk; my $TriDW; # declare the graph object in main, defined in initializ +e my $MW = MainWindow->new(); my $bframe = $MW->Frame()->pack( -side => 'top', -fill => 'x' ); # This is the TriD Tk widget it is a Tk Frame widget and has all of th +e # attributes of a Frame $TriDW = $MW->Tk()->pack( -expand => 1, -fill => 'both'); # The exit button my $e_button = $bframe->Button( -text => "Exit", -command => sub { exit } )->pack( -side => 'right', -anchor => 'nw', -fill => 'y' ); # Sets a default focus style for viewport #setfocusstyle( 'Pointer' ); # This sets the graphic that will be displayed when the window is firs +t opened $e_button->bind( "<Configure>", [ sub { my $but = shift; Torusdemos(); $e_button->bind( "<Configure>", '' ); } ] ); $TriDW->MainLoop; sub Torusdemos { my ( $bh ) = @_; return unless defined $TriDW->{ GLwin }; my $graph; $graph = $TriDW->{ GLwin }->current_viewport->graph(); # define the graph object $graph = new PDL::Graphics::TriD::Graph(); $graph->default_axes(); my $data; my $s = 40; my $a = zeroes 2 * $s, $s / 2; my $t = $a->xlinvals( 0, 6.284 ); my $u = $a->ylinvals( 0, 6.284 ); my $o = 0.5; my $i = 0.1; my $v = $o + $i * sin $u; my $x = $v * sin $t; my $y = $v * cos $t; my $z = $i * cos( $u ) + $o * sin( 3 * $t ); # color $data = new PDL::Graphics::TriD::SLattice( [ $x, $y, $z ], [ 0.5 * ( 1 + sin $t ), 0.5 * ( 1 + cos $t ), 0.25 * ( 2 + cos( $u ) + sin( 3 * $t ) ) ] ); # black and white # $data = new PDL::Graphics::TriD::SLattice_S( [ $x, $y, $z ] ); $graph->add_dataseries( $data, 'Torus-demo' ); $graph->scalethings(); $TriDW->current_viewport()->delete_graph( $graph ); $TriDW->current_viewport()->graph( $graph ); $TriDW->refresh(); }

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      Dear Zentara, In order to understand PDL graphics, I tried to run it.... but fail. There is no PDL::Graphics::TriD::Tk; or any such module. #Can't locate use PDL::Graphics::TriD::Tk; :( Please help me in this regard. Thanks

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://646281]
Approved by Joost
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2017-05-01 01:08 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (543 votes). Check out past polls.