|
@@ -6,11 +6,7 @@ namespace gameplay
|
|
|
|
|
|
|
|
Light::Light(void) :
|
|
Light::Light(void) :
|
|
|
_lightType(0),
|
|
_lightType(0),
|
|
|
- _constantAttenuation(0.0f),
|
|
|
|
|
- _linearAttenuation(0.0f),
|
|
|
|
|
- _quadraticAttenuation(0.0f),
|
|
|
|
|
- _falloffExponent(0.0f),
|
|
|
|
|
- _range(-1.0f),
|
|
|
|
|
|
|
+ _range(1.0f),
|
|
|
_innerAngle(-1.0f),
|
|
_innerAngle(-1.0f),
|
|
|
_outerAngle(0.0f)
|
|
_outerAngle(0.0f)
|
|
|
{
|
|
{
|
|
@@ -30,43 +26,12 @@ const char* Light::getElementName(void) const
|
|
|
return "Light";
|
|
return "Light";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-float Light::computeRange(float constantAttenuation, float linearAttenuation, float quadraticAttenuation)
|
|
|
|
|
-{
|
|
|
|
|
- if (constantAttenuation == 0.0f && linearAttenuation == 0.0f && quadraticAttenuation == 0.0f)
|
|
|
|
|
- {
|
|
|
|
|
- return 0.0f;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Constant Attenuation is currently not supported.
|
|
|
|
|
- if (constantAttenuation == 1.0f)
|
|
|
|
|
- {
|
|
|
|
|
- return 1.0f;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const float step = 0.01f;
|
|
|
|
|
- float range = 0.01f;
|
|
|
|
|
- float att = 1.0f;
|
|
|
|
|
- while (att > 0.01f)
|
|
|
|
|
- {
|
|
|
|
|
- att = 1 / (constantAttenuation + (range * linearAttenuation) + (range * range * quadraticAttenuation));
|
|
|
|
|
- range += step;
|
|
|
|
|
- }
|
|
|
|
|
- return range;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
void Light::writeBinary(FILE* file)
|
|
void Light::writeBinary(FILE* file)
|
|
|
{
|
|
{
|
|
|
Object::writeBinary(file);
|
|
Object::writeBinary(file);
|
|
|
write(_lightType, file);
|
|
write(_lightType, file);
|
|
|
write(_color, COLOR_SIZE, file);
|
|
write(_color, COLOR_SIZE, file);
|
|
|
|
|
|
|
|
- // Compute an approximate light range with Collada's attenuation parameters.
|
|
|
|
|
- // This facilitates bringing in the light nodes directly from maya to gameplay.
|
|
|
|
|
- if (_range == -1.0f)
|
|
|
|
|
- {
|
|
|
|
|
- _range = computeRange(_constantAttenuation, _linearAttenuation, _quadraticAttenuation);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
if (_lightType == SpotLight)
|
|
if (_lightType == SpotLight)
|
|
|
{
|
|
{
|
|
|
write(_range, file);
|
|
write(_range, file);
|
|
@@ -85,13 +50,6 @@ void Light::writeText(FILE* file)
|
|
|
fprintfElement(file, "lightType", _lightType);
|
|
fprintfElement(file, "lightType", _lightType);
|
|
|
fprintfElement(file, "color", _color, COLOR_SIZE);
|
|
fprintfElement(file, "color", _color, COLOR_SIZE);
|
|
|
|
|
|
|
|
- // Compute an approximate light range with Collada's attenuation parameters.
|
|
|
|
|
- // This facilitates bringing in the light nodes directly from maya to gameplay.
|
|
|
|
|
- if (_range == -1.0f)
|
|
|
|
|
- {
|
|
|
|
|
- _range = computeRange(_constantAttenuation, _linearAttenuation, _quadraticAttenuation);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
if (_lightType == SpotLight)
|
|
if (_lightType == SpotLight)
|
|
|
{
|
|
{
|
|
|
fprintfElement(file, "range", _range);
|
|
fprintfElement(file, "range", _range);
|
|
@@ -147,18 +105,10 @@ void Light::setColor(float r, float g, float b)
|
|
|
_color[1] = g;
|
|
_color[1] = g;
|
|
|
_color[2] = b;
|
|
_color[2] = b;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-void Light::setConstantAttenuation(float value)
|
|
|
|
|
-{
|
|
|
|
|
- _constantAttenuation = value;
|
|
|
|
|
-}
|
|
|
|
|
-void Light::setLinearAttenuation(float value)
|
|
|
|
|
|
|
+
|
|
|
|
|
+void Light::setRange(float value)
|
|
|
{
|
|
{
|
|
|
- _linearAttenuation = value;
|
|
|
|
|
-}
|
|
|
|
|
-void Light::setQuadraticAttenuation(float value)
|
|
|
|
|
-{
|
|
|
|
|
- _quadraticAttenuation = value;
|
|
|
|
|
|
|
+ _range = value;
|
|
|
}
|
|
}
|
|
|
void Light::setInnerAngle(float value)
|
|
void Light::setInnerAngle(float value)
|
|
|
{
|
|
{
|
|
@@ -168,13 +118,5 @@ void Light::setOuterAngle(float value)
|
|
|
{
|
|
{
|
|
|
_outerAngle = value;
|
|
_outerAngle = value;
|
|
|
}
|
|
}
|
|
|
-void Light::setFalloffExponent(float value)
|
|
|
|
|
-{
|
|
|
|
|
- _falloffExponent = value;
|
|
|
|
|
- if ( value != 1.0)
|
|
|
|
|
- {
|
|
|
|
|
- LOG(1, "Warning: spot light falloff_exponent must be 1.0. \n");
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|