~ubuntu-branches/ubuntu/lucid/pdl/lucid

« back to all changes in this revision

Viewing changes to Graphics/TriD/TriD/Object.pm

  • Committer: Bazaar Package Importer
  • Author(s): Ben Gertzfield
  • Date: 2002-04-08 18:47:16 UTC
  • Revision ID: james.westby@ubuntu.com-20020408184716-0hf64dc96kin3htp
Tags: upstream-2.3.2
ImportĀ upstreamĀ versionĀ 2.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
###################################
 
2
#
 
3
#
 
4
package PDL::Graphics::TriD::Object;
 
5
 
 
6
use strict;
 
7
 
 
8
use fields qw(Objects ValidList ChangedSub List VRML);
 
9
sub new{
 
10
  my $class = shift;
 
11
  no strict 'refs';
 
12
  my $self = bless [ \%{"$class\::FIELDS"}], $class;
 
13
  $self;
 
14
}
 
15
 
 
16
sub clear_objects {
 
17
        my($this) = @_;
 
18
        $this->{Objects} = [];
 
19
        $this->{ValidList} = 0;
 
20
}
 
21
 
 
22
 
 
23
sub delete_object {
 
24
  my($this,$object) = @_;
 
25
  return unless(defined $object && defined $this->{Objects});
 
26
  for(0..$#{$this->{Objects}}){
 
27
    if($object == $this->{Objects}[$_]){
 
28
      splice(@{$this->{Objects}},$_,1);
 
29
      redo;
 
30
    }
 
31
  }
 
32
}
 
33
 
 
34
# XXXXXXXXX sub {} makes all these objects and this window immortal!
 
35
sub add_object {
 
36
  my($this,$object) = @_;
 
37
  push @{$this->{Objects}},$object;
 
38
  $this->{ValidList} = 0;
 
39
  for(@{$this->{ChangedSub}}) {
 
40
    $object->add_changedsub($_);
 
41
  }
 
42
  if($this->i_keep_list) {
 
43
    $object->add_changedsub(sub {$this->changed_from_above()});
 
44
  }
 
45
}
 
46
 
 
47
sub changed_from_above {
 
48
        my($this) = @_;
 
49
        print "CHANGED_FROM_ABOVE\n" if $PDL::Graphics::TriD::verbose;
 
50
        $this->changed();
 
51
}
 
52
 
 
53
sub add_changedsub {
 
54
        my($this,$chsub) = @_;
 
55
        push @{$this->{ChangedSub}}, $chsub;
 
56
        for (@{$this->{Objects}}) {
 
57
                $_->add_changedsub($chsub);
 
58
        }
 
59
}
 
60
 
 
61
 
 
62
sub clear {
 
63
        my($this) = @_;
 
64
        # print "Clear: $this\n";
 
65
        for(@{$this->{Objects}}) {
 
66
                $_->clear();
 
67
        }
 
68
        $this->delete_displist();
 
69
        delete $this->{ChangedSub};
 
70
        delete $this->{Objects};
 
71
}
 
72
 
 
73
sub changed {
 
74
        my($this) = @_;
 
75
        print "VALID0 $this\n" if $PDL::Graphics::TriD::verbose;
 
76
        $this->{ValidList} = 0;
 
77
        for(@{$this->{ChangedSub}}) {
 
78
                &$_($this);
 
79
        }
 
80
}
 
81
 
 
82
sub i_keep_list {
 
83
        return 0;
 
84
}
 
85
 
 
86
 
 
87
sub vrml_update {
 
88
  my ($this) = @_;
 
89
  use PDL::Graphics::VRML;
 
90
 
 
91
  $this->{VRML} = new PDL::Graphics::VRMLNode('Transform',
 
92
                                   'translation' => "-1 -1 -1",
 
93
                                   'scale' => "2 2 2");
 
94
  $this->{ValidList} = 1;
 
95
}
 
96
 
 
97
sub tovrml {
 
98
        my($this) = @_;
 
99
 
 
100
   print ref($this)," valid=",$this->{ValidList}," tovrml\n";
 
101
 
 
102
        if (!$this->{ValidList}) {
 
103
          $this->vrml_update();
 
104
        }
 
105
        $this->{VRML}->add('children',
 
106
                           [map {$_->tovrml()} @{$this->{Objects}}]);
 
107
}
 
108
 
 
109
 
 
110
1;