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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
/*
* Modification History
*
* 2000-December-20 Jason Rohrer
* Created.
*/
#ifndef MULTI_LIGHTING_GL_INCLUDED
#define MULTI_LIGHTING_GL_INCLUDED
#include <stdio.h>
#include "LightingGL.h"
#include "minorGems/util/SimpleVector.h"
/**
* A LightingGL implementation that contains a collection of
* LightingGLs.
*
* @author Jason Rohrer
*/
class MultiLightingGL : public LightingGL {
public:
/**
* Constructs a MultiLighting.
*/
MultiLightingGL();
~MultiLightingGL();
/**
* Adds a lighting to this MultiLighting.
*
* @param inLighting lighting to add. Is not
* destroyed when the MultiLighting is destroyed.
*/
void addLighting( LightingGL *inLighting );
/**
* Removes a lighting to this MultiLighting.
*
* @param inLighting lighting to remove.
*/
void removeLighting( LightingGL *inLighting );
// implements LightingGL interface
void getLighting( Vector3D *inPoint, Vector3D *inNormal,
Color *outColor );
private:
SimpleVector<LightingGL*> *mLightingVector;
};
inline MultiLightingGL::MultiLightingGL()
: mLightingVector( new SimpleVector<LightingGL*>() ) {
}
inline MultiLightingGL::~MultiLightingGL() {
delete mLightingVector;
}
inline void MultiLightingGL::addLighting( LightingGL *inLighting ) {
mLightingVector->push_back( inLighting );
}
inline void MultiLightingGL::removeLighting( LightingGL *inLighting ) {
mLightingVector->deleteElement( inLighting );
}
inline void MultiLightingGL::getLighting( Vector3D *inPoint,
Vector3D *inNormal, Color *outColor ) {
int numLightings = mLightingVector->size();
outColor->r = 0;
outColor->g = 0;
outColor->b = 0;
// sum lighting contributions from each lighting
for( int i=0; i<numLightings; i++ ) {
Color *tempColor = new Color( 0, 0, 0 );
LightingGL *thisLighting = *( mLightingVector->getElement( i ) );
thisLighting->getLighting( inPoint, inNormal, tempColor );
outColor->r += tempColor->r;
outColor->g += tempColor->g;
outColor->b += tempColor->b;
delete tempColor;
}
// clip color components:
if( outColor->r > 1.0 ) {
outColor->r = 1.0;
}
if( outColor->g > 1.0 ) {
outColor->g = 1.0;
}
if( outColor->b > 1.0 ) {
outColor->b = 1.0;
}
}
#endif
|