in reply to help with Z-buffer algorithm

When I ran your code with perl 5.8, I got these warnings:
Using an array as a reference is deprecated at /tmp/3dgraphics.perl li +ne 989. Using an array as a reference is deprecated at /tmp/3dgraphics.perl li +ne 990. Using a hash as a reference is deprecated at /tmp/3dgraphics.perl line + 1004. Using a hash as a reference is deprecated at /tmp/3dgraphics.perl line + 1004. Using a hash as a reference is deprecated at /tmp/3dgraphics.perl line + 1004. Using a hash as a reference is deprecated at /tmp/3dgraphics.perl line + 1064. Using a hash as a reference is deprecated at /tmp/3dgraphics.perl line + 1064. Using a hash as a reference is deprecated at /tmp/3dgraphics.perl line + 1076. Using a hash as a reference is deprecated at /tmp/3dgraphics.perl line + 1077. Using a hash as a reference is deprecated at /tmp/3dgraphics.perl line + 1081. Using a hash as a reference is deprecated at /tmp/3dgraphics.perl line + 1082. Using a hash as a reference is deprecated at /tmp/3dgraphics.perl line + 1087. Using a hash as a reference is deprecated at /tmp/3dgraphics.perl line + 1091. Using an array as a reference is deprecated at /tmp/3dgraphics.perl li +ne 1092. Using an array as a reference is deprecated at /tmp/3dgraphics.perl li +ne 1094. Using a hash as a reference is deprecated at /tmp/3dgraphics.perl line + 1101. Using a hash as a reference is deprecated at /tmp/3dgraphics.perl line + 1107. Using a hash as a reference is deprecated at /tmp/3dgraphics.perl line + 1108. Using a hash as a reference is deprecated at /tmp/3dgraphics.perl line + 1108. Using an array as a reference is deprecated at /tmp/3dgraphics.perl li +ne 1127.
This stuff arises from lines like this (this is the code at line 1064):
@AET = sort{ %{$a}->{Xbot} <=> %{$b}->{Xbot} } @AET;
Sure enough, you're using the "%" sigil on a value that is supposed to be treated as a scalar.

You should try to adjust the lines involved to see if you can avoid those warnings -- then see if the code behaves the same way. (There's a chance that the values you are manipulating are not what you're expecting them to be.)

update: forgot to mention: just because you're using Tk doesn't mean you can't use the perl debugger. Run the script with "perl -d" and put breakpoints at some of those lines that are setting and testing Z-buffer values; when the code gets to one of those lines, look at the values being tested or assigned. (And figure out if it's just something simple, like adding when you should be subtracting, or whatever.)

Replies are listed 'Best First'.
Re: Re: help with Z-buffer algorithm
by rbc (Curate) on Nov 07, 2002 at 04:37 UTC
        Well, I still get the following set of warnings (maybe not the same ones, but at least fewer of them) -- and two of the lines you just quoted are among them:
        Using an array as a reference is deprecated at /tmp/3dgraphics2.perl l +ine 989. Using an array as a reference is deprecated at /tmp/3dgraphics2.perl l +ine 990. Using an array as a reference is deprecated at /tmp/3dgraphics2.perl l +ine 1094. Using an array as a reference is deprecated at /tmp/3dgraphics2.perl l +ine 1096. Using an array as a reference is deprecated at /tmp/3dgraphics2.perl l +ine 1129.
        where this is offending expression at lines 1094 and 1096:
        @{$zbuffer}->[$x]->[$y]
        I tried changing these two to be:
        $$zbuffer[$x][$y]
        the code still ran and still did the wrong things, same as before. As for what you may be doing wrong in one or the other spot of code, I couldn't guess, but consider doing "perl -d yourscript" to run it with the debugger.

        When you see the "DB<1>" prompt, type "b 251" -- that sets a breakpoint at the start of this expression:

        my $rec = { edge => [$A, $B], dx => abs($X1 - $X2), dz => $Z1 - $Z2, z => ( $X1 < $X2 ) ? ($Z1) : ($Z2) };
        then type "c" to run the script till it reaches that break point. The GUI comes up, you can set parameters (I chose to set "rotX" of "40" instead of "0"), and hit the "Draw" button. Eventually the program will stop when it hits the chosen line, and you get the "DB" prompt back; see "perldebug" and "perldebtut" for fun things to try.