3DWorld/Actor/Sprite.pm untested

filter: Statementstmt 0.0% 0 / 48 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 60 CC 1 SCAR 6.9
CC
1
Cov
0%
new
2.0
display
2.0
BEGIN
2.0
CRAP 2.0
1 package SDL::Tutorial::3DWorld::Actor::Sprite;
2  
3 use 5.008;
4 use strict;
5 use warnings;
6 use SDL::Tutorial::3DWorld ();
7 use SDL::Tutorial::3DWorld::OpenGL ();
8 use SDL::Tutorial::3DWorld::Texture ();
9 use SDL::Tutorial::3DWorld::Material ();
10 use SDL::Tutorial::3DWorld::Actor ();
11  
12 our $VERSION = '0.33';
13 our @ISA = 'SDL::Tutorial::3DWorld::Actor';
14  
15  
16  
17  
18  
19 ######################################################################
20 # Constructor and Accessors
21  
22 sub new {
23 my $self = shift->SUPER::new(
24 blending => 1,
25 @_,
26 );
27  
28 # Convert the texture to a full material
29 $self->{material} = SDL::Tutorial::3DWorld::Material->new(
30 ambient => [ 1, 1, 1, 0.5 ],
31 diffuse => [ 1, 1, 1, 0.5 ],
32 texture => SDL::Tutorial::3DWorld::Texture->new(
33 file => $self->{texture},
34 tile => 0,
35 mag_filter => OpenGL::GL_NEAREST,
36 ),
37 );
38  
39 return $self;
40 }
41  
42 sub display {
43 my $self = shift;
44 $self->SUPER::display(@_);
45  
46 # Rotate towards the camera
47 OpenGL::glRotatef(
48 -SDL::Tutorial::3DWorld->current->camera->{angle},
49 0, 1, 0,
50 );
51  
52 # Switch to the sprite
53 $self->{material}->display;
54  
55 # Draw the sprite quad.
56 # The texture seems to wrap a little unless we use the 0.01 here.
57 OpenGL::glDisable( OpenGL::GL_LIGHTING );
58 OpenGL::glBegin( OpenGL::GL_QUADS );
59 OpenGL::glTexCoord2f( 0, 0 ); OpenGL::glVertex3f( -0.5, 1, 0 ); # Top Left
60 OpenGL::glTexCoord2f( 0, 1 ); OpenGL::glVertex3f( -0.5, 0, 0 ); # Bottom Left
61 OpenGL::glTexCoord2f( 1, 1 ); OpenGL::glVertex3f( 0.5, 0, 0 ); # Bottom Right
62 OpenGL::glTexCoord2f( 1, 0 ); OpenGL::glVertex3f( 0.5, 1, 0 ); # Top Right
63 OpenGL::glEnd();
64 OpenGL::glEnable( OpenGL::GL_LIGHTING );
65  
66 return 1;
67 }
68  
69 1;