~ubuntu-branches/ubuntu/precise/primrose/precise

« back to all changes in this revision

Viewing changes to minorGems/graphics/openGL/DirectionLightingGL.h

  • Committer: Bazaar Package Importer
  • Author(s): Paul Wise
  • Date: 2009-04-06 19:26:56 UTC
  • Revision ID: james.westby@ubuntu.com-20090406192656-cri7503gebyvfl8t
Tags: upstream-5+dfsg1
ImportĀ upstreamĀ versionĀ 5+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Modification History
 
3
 *
 
4
 * 2000-December-20             Jason Rohrer
 
5
 * Created. 
 
6
 */
 
7
 
 
8
 
 
9
#ifndef DIRECTION_LIGHTING_GL_INCLUDED
 
10
#define DIRECTION_LIGHTING_GL_INCLUDED
 
11
 
 
12
#include <stdio.h>
 
13
 
 
14
#include "LightingGL.h"
 
15
 
 
16
/**
 
17
 * A LightingGL implementation with a single point light source
 
18
 * at distance infinity.
 
19
 *
 
20
 * @author Jason Rohrer 
 
21
 */
 
22
class DirectionLightingGL : public LightingGL { 
 
23
        
 
24
        public:
 
25
                
 
26
                /**
 
27
                 * Constructs a DirectionLighting.
 
28
                 *
 
29
                 * @param inColor color of lighting for a surface
 
30
                 *   that is facing directly into the light source.
 
31
                 *   Is not copied, so cannot be accessed again by caller.
 
32
                 * @param inDirection incoming direction of light source.
 
33
                 *   Is not copied, so cannot be accessed again by caller.
 
34
                 */
 
35
                DirectionLightingGL( Color *inColor, Vector3D *inDirection );
 
36
                
 
37
                
 
38
                ~DirectionLightingGL();
 
39
                
 
40
                
 
41
                // implements LightingGL interface
 
42
                void getLighting( Vector3D *inPoint, Vector3D *inNormal,
 
43
                        Color *outColor );
 
44
        
 
45
        
 
46
        private:
 
47
                Color *mColor;
 
48
                // direction pointing *towards* light source
 
49
                Vector3D *mDirection;
 
50
                
 
51
        };
 
52
 
 
53
 
 
54
 
 
55
inline DirectionLightingGL::DirectionLightingGL( Color *inColor,
 
56
        Vector3D *inDirection )
 
57
        : mColor( inColor ), mDirection( inDirection ) {
 
58
 
 
59
        // reverse the passed-in direction
 
60
        mDirection->scale( -1 );
 
61
        }
 
62
 
 
63
 
 
64
 
 
65
inline DirectionLightingGL::~DirectionLightingGL() {
 
66
 
 
67
        delete mColor;
 
68
        delete mDirection;
 
69
        }
 
70
 
 
71
 
 
72
 
 
73
inline void DirectionLightingGL::getLighting( Vector3D *inPoint, 
 
74
        Vector3D *inNormal, Color *outColor ) {
 
75
        
 
76
        double dot = inNormal->dot( mDirection );
 
77
        
 
78
        if( dot > 0 ) {
 
79
                outColor->r = mColor->r * dot;
 
80
                outColor->g = mColor->g * dot;
 
81
                outColor->b = mColor->b * dot;
 
82
                }
 
83
        else {
 
84
                outColor->r = 0;
 
85
                outColor->g = 0;
 
86
                outColor->b = 0;
 
87
                }
 
88
        }
 
89
 
 
90
 
 
91
        
 
92
#endif