3DWorld/Actor/Teapot.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 54 CC 2 SCAR 10.3
CC
2
Cov
0%
new
6.0
init
2.0
display
2.0
CRAP 2.8
1 package SDL::Tutorial::3DWorld::Actor::Teapot;
2  
3  
4 =pod
5  
6 =head1 NAME
7  
8 SDL::Tutorial::3DWorld::Actor::Teapot - A moving teapot within the game world
9  
10 =head1 SYNOPSIS
11  
12 # Create a vertical stack of teapots
13 my @stack = ();
14 foreach my $height ( 1 .. 10 ) {
15 push @stack, SDL::Tutorial::3DWorld::Actor::Teapot->new(
16 X => 0,
17 Y => $height * 0.30, # Each teapot is 30cm high
18 Z => 0,
19 );
20 }
21  
22 =head1 DESCRIPTION
23  
24 SDL::Tutorial::3DWorld::Actor::Teapot is a little teapot, short and stout.
25  
26 It is drawn with the GLUT C<glutCreateTeapot> function.
27  
28 =head1 METHODS
29  
30 This class does not contain any additional methods beyond those in the base
31 class L<SDL::Tutorial::3DWorld::Actor>.
32  
33 =cut
34  
35 use 5.008;
36 use strict;
37 use warnings;
38 use SDL::Tutorial::3DWorld::OpenGL ();
39 use SDL::Tutorial::3DWorld::Actor ();
40 use SDL::Tutorial::3DWorld::Bound;
41  
42 our $VERSION = '0.33';
43 our @ISA = 'SDL::Tutorial::3DWorld::Actor';
44  
45 =pod
46  
47 =head2 new
48  
49 # I want to be a little teapot, short and stout (and the default colour)
50 my $teapot = SDL::Tutorial::3DWorld::Actor::Teapot->new(
51 size => 0.15, # 15cm
52 );
53  
54 In additional to the regular material properties provided by the parent
55 L<SDL::Tutorial::3DWorld::Actor> class teapots take an additional C<size>
56 parameter to control how big the teapot is.
57  
58 Teapots are 20cm high by default (because tea is best with friends and so
59 we'll need to brew several cups).
60  
61 =cut
62  
63 sub new {
64 my $class = shift;
65 my $self = $class->SUPER::new(
66 @_,
67 );
68  
69 # By default teapots are about 20cm in size (I'm making this up)
70 $self->{size} ||= 0.20;
71  
72 # Teapots don't support scaling because they are a heavy drawing
73 # task as it, and rendering with GL_NORMALIZE would be ugly.
74 if ( $self->{scale} ) {
75 die "Teapot actors do not support scale, use size";
76 }
77  
78 return $self;
79 }
80  
81  
82  
83  
84  
85 ######################################################################
86 # Engine Interface Methods
87  
88 sub init {
89 my $self = shift;
90 $self->SUPER::init(@_);
91  
92 # Generate the bounding box
93 $self->{bound} = SDL::Tutorial::3DWorld::Bound->box(
94 $self->{size} * -1.5,
95 $self->{size} * -0.75,
96 $self->{size} * -1,
97 $self->{size} * 1.75,
98 $self->{size} * 0.85,
99 $self->{size} * 1,
100 );
101  
102 return 1;
103 }
104  
105 sub display {
106 my $self = shift;
107 $self->SUPER::display(@_);
108  
109 # Draw the teapot.
110 # Disable culling temporarily as the teapot needs back faces.
111 $self->{material}->display;
112 OpenGL::glDisable( OpenGL::GL_CULL_FACE );
113 OpenGL::glutSolidTeapot($self->{size});
114 OpenGL::glEnable( OpenGL::GL_CULL_FACE );
115  
116 return;
117 }
118  
119 1;
120  
121 =pod
122  
123 =head1 SUPPORT
124  
125 Bugs should be reported via the CPAN bug tracker at
126  
127 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SDL-Tutorial-3DWorld>
128  
129 =head1 AUTHOR
130  
131 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
132  
133 =head1 SEE ALSO
134  
135 L<SDL>, L<OpenGL>
136  
137 =head1 COPYRIGHT
138  
139 Copyright 2010 Adam Kennedy.
140  
141 This program is free software; you can redistribute
142 it and/or modify it under the same terms as Perl itself.
143  
144 The full text of the license can be found in the
145 LICENSE file included with this module.
146  
147 =cut