#!/usr/bin/perl use warnings; use strict; use PDL::LiteF; use PDL::Graphics::TriD; use PDL::Graphics::TriD::GL; use PDL::Graphics::OpenGL; # hit 'q' repeatedly to cycle thru the script package TOBJ; BEGIN{@TOBJ::ISA = qw/PDL::Graphics::TriD::Object/;} use PDL::Graphics::OpenGLQ; use PDL::Graphics::OpenGL; my $self; sub new { my ($pkg, $lb, $text, $pos) = @_; # print "@_\n"; $self = bless { "lb" => $lb, "text" => $text, "x" => $pos->[0], "y" => $pos->[1], "z" => $pos->[2], }, $pkg; return $self; } sub togl { # print "togl @_\n"; glDisable(&GL_LIGHTING); glColor3f(1,0,1); glRasterPos3f($self->{'x'},$self->{'y'},$self->{'z'}); PDL::Graphics::OpenGL::glpPrintString($self->{'lb'}, $self->{'text'}); glEnable(&GL_LIGHTING); } sub ctext{ print "ctext @_\n"; $self->{'text'} = $_[1]; if( $_[2] ){ my $pos = $_[2]; $self->{'x'} = $pos->[0], $self->{'y'} = $pos->[1], $self->{'z'} = $pos->[2], } } 1; ####################################################### package main; # little piddle to add some color my $pdlc = zeroes(3); #each elem has 3 elements my $col = $pdlc->slice('1:1,:,:'); #green #$col = $pdlc->slice('0:0,:,:'); #red $col += 1; #get GL window to pass to text object my $win = PDL::Graphics::TriD::get_current_window(); my $vp = $win->current_viewport; my $lb = $win->glpRasterFont("10x20",0,255); # glShadeModel (&GL_FLAT); glShadeModel (&GL_SMOOTH); my $tobj = new TOBJ($lb,'points3d SURF2D', [0,0,0]); $win->add_object($tobj); hold3d(); #objects built up to this point will be held my $nx = 20; my $t = (xvals zeroes $nx+1,$nx+1)/$nx; my $u = (yvals zeroes $nx+1,$nx+1)/$nx; my $x = sin($u*15 + $t * 3)/2+0.5 + 5*($t-0.5)**2; points3d(['SURF2D',$x],$pdlc); $vp->setview([3,3,3]); $tobj->ctext('line3d SURF2D',[0,0,0]); line3d(['SURF2D',$x],$pdlc); $vp->setview([3,-3,3]); $tobj->ctext('mesh3d',[0,0,.75]); mesh3d([$x]); $vp->setview([3,-3,-3]); $tobj->ctext('imag3d Lines=>0',[1,1,1]); imag3d([$x],{Lines => 0}); $vp->setview([-3,-3,-3]); $tobj->ctext('imag3d Lines => 0, Smooth => 1',[.75,.75,.75]); imag3d([$x],{Lines => 0, Smooth => 1}); $vp->setview([0,0,3]); $tobj->ctext('imag3d',[0,0,.5]); imag3d_ns([$x]);