File: ViewPort.pm

package info (click to toggle)
libpdl-graphics-trid-perl 2.102-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 476 kB
  • sloc: perl: 5,082; ansic: 683; makefile: 8
file content (109 lines) | stat: -rw-r--r-- 2,223 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#
# The PDL::Graphics::TriD::ViewPort is already partially defined in
# the appropriate gdriver (GL or VRML), items defined here are common
# to both
# 
package PDL::Graphics::TriD::ViewPort;
use strict;
use warnings;
use base qw/PDL::Graphics::TriD::Object/;
use fields qw/X0 Y0 W H Transformer EHandler Active ResizeCommands
              DefMaterial AspectRatio Graphs/;

$PDL::Graphics::TriD::verbose //= 0;

sub new {
     my($type,$x0,$y0,$w,$h) = @_;
	  
	  my $this= $type->SUPER::new();

	  $this->{X0} = $x0;
	  $this->{Y0} = $y0;
	  $this->{W} = $w;
	  $this->{H} = $h;
	  $this->{DefMaterial} = PDL::Graphics::TriD::Material->new;

     return $this;
}

sub graph {
  my($this,$graph) = @_;
  if(defined($graph)){  
	 $this->add_object($graph);
	 push(@{$this->{Graphs}},$graph);
  }elsif(defined $this->{Graphs}){
	 $graph = $this->{Graphs}[0];
  }
  return($graph);
}  

sub delete_graph {
  my($this,$graph) = @_;
  
  $this->delete_object($graph);
  for(0..$#{$this->{Graphs}}){
    if($graph == $this->{Graphs}[$_]){
      splice(@{$this->{Graphs}},$_,1);
      redo;
    }
  }
}

sub resize {
  my($this,$x0,$y0,$w,$h) = @_;
  $this->{X0} = $x0;
  $this->{Y0} = $y0;
  $this->{W} = $w;
  $this->{H} = $h;
  return $this;
}

sub add_resizecommand {
	my($this,$com) = @_;
	push @{$this->{ResizeCommands}},$com;
	print "ARC: $this->{W},$this->{H}\n" if($PDL::Graphics::TriD::verbose);
	&$com($this->{W},$this->{H});
}

sub set_material {
  $_[0]->{DefMaterial} = $_[1];
}

sub eventhandler {
  my ($this,$eh) = @_;
  if(defined $eh){
	 $this->{EHandler} = $eh;
  }
  return $this->{EHandler};
}

sub set_transformer {
  $_[0]->transformer($_[1]);
}

sub transformer {
  my ($this,$t) = @_;
  if(defined $t){
	 $this->{Transformer} = $t;
  }
  return $this->{Transformer};
}

#
# restore the image view to a known value
#
sub setview{
  my($vp,$view) = @_;
  my $transformer = $vp->transformer();
  if(ref($view) eq "ARRAY"){
	 $transformer->set({WRotation=>$view});
  }elsif($view eq "Top"){
	 $transformer->set({WRotation=>[1,0,0,0]});
  }elsif($view eq "East"){
	 $transformer->set({WRotation=>[0.5,-0.5,-0.5,-0.5]});
  }elsif($view eq "South"){
	 $transformer->set({WRotation=>[0.6,-0.6,0,0]});
  }
}

1;