Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

drawing 3D rectangle in Perl/Tk

by Anonymous Monk
on Mar 29, 2003 at 11:20 UTC ( [id://246603]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, i am new to Perl. I came to know that Perl/Tk is one of the best choices for graphics interface. Before selecting Perl/Tk for my project, i want to clear some doubts that arised in my mind when i studied Perl/Tk document. In my application i need to draw 3D rectangles. Is it poosible to draw 3D rectangles in Perl/Tk? Is there any command for that? If not how to draw a 3D rectangle? Thanx.

Replies are listed 'Best First'.
Re: drawing 3D rectangle in Perl/Tk
by dakkar (Hermit) on Mar 29, 2003 at 12:30 UTC

    And what is a 3-D rectangle? Do you mean a bidimensional representation of an otherwise solid object (like an isometric or perspective drawing of a prism), or a rectangle (which is a 2-dimensional, flat object) drawn "skewed" to appear as if it's "rotated around some appropriate axis"?

    Anyway, Perl/Tk has a great widget for drawing, Tk::Canvas. For 2-D drawing, that is.

    If you really need simulated 3-d, I'd suggest you use OpenGL.

    -- 
            dakkar - Mobilis in mobile
    
Re: drawing 3D rectangle in Perl/Tk
by zentara (Archbishop) on Mar 29, 2003 at 19:07 UTC
    You can get good 3d drawings in the Perl SDL module.Check it out at SDL
Re: drawing 3D rectangle in Perl/Tk
by pg (Canon) on Mar 29, 2003 at 17:05 UTC
    Also, you may want to have a look at Game::3D (and it has lots of sub classes).
Re: drawing 3D rectangle in Perl/Tk
by aquarium (Curate) on Mar 29, 2003 at 22:44 UTC
    If you want/need to stick with Perl/Tk...then you need to to matrix math. With the right matrix you can re-position, rotate, re-size an object by applying the matrix to each point of the object. Then finally there's a matrix to project each 3d point onto a 2d plane (your viewing canvas.) Now that you have all the co-ordinates in 2d, just draw it with Perl/Tk. Instead of using matrices you can also simulate some (limited) 3d objects or objects in 3d world. A rectangle spinning on Y axis is fairly easy: in a loop first contract corner x co-ordinates (slightly contracting y co-ordinates for one edge to show perspective) until it becomes a line (x co-ordinates for all corners are same), then expand the x co-ordinates to original (increasing slightly y co-ordinates of opposite edge of rectangle.) Chris
      "3D rectangle" is kind of vague. If he used terminologies like cube, tetrahedron, dodecahedron etc, I would be 100% percent sure about what he meant, but "3d rectangle"...

      There is a chance that he might actually mean a rectangle with certain relief, and 3D alike, for example, a Tk button created like this:
      $mw->Button(relief => "sunken");
      is 3D alike.

      If this is what he meant, what he really want is simply 2D shapes with "shadows". If this is the case, then much less maths is needed, and more importantly one needs a sharp sense of colors.
Re: drawing 3D rectangle in Perl/Tk
by Dr. Mu (Hermit) on Mar 29, 2003 at 23:33 UTC
    Another option is the VRML (virtual reality modeling language) module. The docs for this module are a little sketchy, and it helps to study the structure of wrl files you find on the web before you really "get it". The following example script (vrml_test.pl) draws a red cube:
    use strict; use VRML; my $vrml = new VRML(2); $vrml->Group->Shape( sub{$vrml->IndexedFaceSet( sub{$vrml->Coordinate('0 0 0', '0 0 1', '0 1 0', '0 1 1', '1 0 + 0', '1 0 1', '1 1 0', '1 1 1', )->insert('solid FALSE')}, ['0 1 3 2', '0 1 5 4', '0 4 6 2', '4 5 7 6', '2 3 7 6', '1 3 7 + 5'] )}, sub{$vrml->Appearance( sub{$vrml->Material( ambientIntensity => .5, diffuseColor => '1 0 0', emissiveColor => '.25 0 0' )} )} )->back; $vrml->print; $vrml->save; exec 'vrmlview /home/phil/usr/vrml_test.wrl'; #Substitute your own vie +wer and path info here.
    You need a VRML viewer to see your work. This particular app runs on Linux and uses vrmlview, available free from Systems in Motion. Windows users have a lot of choices. Just type "windows vrml-viewer" into Google to find them.

    Aside from allowing you to see complex shapes that are hard to visualize otherwise, the effects of grabbing an object with your mouse and rotating it in multiple axes can be downright intoxicating! Try it because it's fun, if for no other reason!

Re: drawing 3D rectangle in Perl/Tk
by dws (Chancellor) on Mar 30, 2003 at 00:29 UTC
    Is it possible to draw 3D rectangles in Perl/Tk?

    For an approach that uses Z-buffering to draw shapes in 3-space, see this node. It isn't fast, though.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://246603]
Approved by davis
Front-paged by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-24 08:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found