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