diff options
author | Brian <runningnak3d@gmail.com> | 2010-06-07 18:32:20 -0600 |
---|---|---|
committer | Brian <runningnak3d@gmail.com> | 2010-06-07 18:32:20 -0600 |
commit | 1fd70827128177aba3ac1334135fc12422819db0 (patch) | |
tree | 83355f4e124ef9d8e5ad47f9f904bfb001dcd3f9 /externals/g3dlite/G3D.lib/source/GLight.cpp | |
parent | 726a76e93aa3f20f4e642a01027f977f368a979e (diff) |
* Reverted to the old G3D library, however collision still will not compile
* and is therefore commented out.
--HG--
branch : trunk
Diffstat (limited to 'externals/g3dlite/G3D.lib/source/GLight.cpp')
-rw-r--r-- | externals/g3dlite/G3D.lib/source/GLight.cpp | 143 |
1 files changed, 0 insertions, 143 deletions
diff --git a/externals/g3dlite/G3D.lib/source/GLight.cpp b/externals/g3dlite/G3D.lib/source/GLight.cpp deleted file mode 100644 index 8acb066ef54..00000000000 --- a/externals/g3dlite/G3D.lib/source/GLight.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/** - @file GLight.cpp - - @maintainer Morgan McGuire, matrix@graphics3d.com - - @created 2003-11-12 - @edited 2007-10-22 -*/ - -#include "G3D/GLight.h" -#include "G3D/Sphere.h" - -namespace G3D { - -GLight::GLight() { - position = Vector4(0, 0, 0, 0); - color = Color3::white(); - spotDirection = Vector3(0, 0, -1); - spotCutoff = 180; - enabled = false; - attenuation[0] = 1.0; - attenuation[1] = 0.0; - attenuation[2] = 0.0; - specular = true; - diffuse = true; -} - - -GLight GLight::directional(const Vector3& toLight, const Color3& color, bool s, bool d) { - GLight L; - L.position = Vector4(toLight.direction(), 0); - L.color = color; - L.specular = s; - L.diffuse = d; - return L; -} - - -GLight GLight::point(const Vector3& pos, const Color3& color, float constAtt, float linAtt, float quadAtt, bool s, bool d) { - GLight L; - L.position = Vector4(pos, 1); - L.color = color; - L.attenuation[0] = constAtt; - L.attenuation[1] = linAtt; - L.attenuation[2] = quadAtt; - L.specular = s; - L.diffuse = d; - return L; -} - - -GLight GLight::spot(const Vector3& pos, const Vector3& pointDirection, float cutOffAngleDegrees, const Color3& color, float constAtt, float linAtt, float quadAtt, bool s, bool d) { - GLight L; - L.position = Vector4(pos, 1.0f); - L.spotDirection = pointDirection.direction(); - debugAssert(cutOffAngleDegrees <= 90); - L.spotCutoff = cutOffAngleDegrees; - L.color = color; - L.attenuation[0] = constAtt; - L.attenuation[1] = linAtt; - L.attenuation[2] = quadAtt; - L.specular = s; - L.diffuse = d; - return L; -} - - -bool GLight::operator==(const GLight& other) const { - return (position == other.position) && - (spotDirection == other.spotDirection) && - (spotCutoff == other.spotCutoff) && - (attenuation[0] == other.attenuation[0]) && - (attenuation[1] == other.attenuation[1]) && - (attenuation[2] == other.attenuation[2]) && - (color == other.color) && - (enabled == other.enabled) && - (specular == other.specular) && - (diffuse == other.diffuse); -} - -bool GLight::operator!=(const GLight& other) const { - return !(*this == other); -} - - -Sphere GLight::effectSphere(float cutoff) const { - if (position.w == 0) { - // Directional light - return Sphere(Vector3::zero(), (float)inf()); - } else { - // Avoid divide by zero - cutoff = max(cutoff, 0.0001f); - float maxIntensity = max(color.r, max(color.g, color.b)); - - float radius = (float)inf(); - - if (attenuation[2] != 0) { - - // Solve I / attenuation.dot(1, r, r^2) < cutoff for r - // - // a[0] + a[1] r + a[2] r^2 > I/cutoff - // - - float a = attenuation[2]; - float b = attenuation[1]; - float c = attenuation[0] - maxIntensity / cutoff; - - float discrim = square(b) - 4 * a * c; - - if (discrim >= 0) { - discrim = sqrt(discrim); - - float r1 = (-b + discrim) / (2 * a); - float r2 = (-b - discrim) / (2 * a); - - if (r1 < 0) { - if (r2 > 0) { - radius = r2; - } - } else if (r2 > 0) { - radius = min(r1, r2); - } else { - radius = r1; - } - } - - } else if (attenuation[1] != 0) { - - // Solve I / attenuation.dot(1, r) < cutoff for r - // - // r * a[1] + a[0] = I / cutoff - // r = (I / cutoff - a[0]) / a[1] - - float radius = (maxIntensity / cutoff - attenuation[0]) / attenuation[1]; - radius = max(radius, 0.0f); - } - - return Sphere(position.xyz(), radius); - - } -} - -} |