Skip to content

Commit

Permalink
point light bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lrsb committed Aug 17, 2020
1 parent 7ac036c commit c17367c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
24 changes: 12 additions & 12 deletions js/lights.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,21 @@ function changeDirectLight() {
}

function changePointLight() {
lights.point.x = $('#point-light-position-x').val()
lights.point.y = $('#point-light-position-y').val()
lights.point.z = $('#point-light-position-z').val()
lights.point.decay = $('#point-light-decay').val()
lights.point.x = parseFloat($('#point-light-position-x').val())
lights.point.y = parseFloat($('#point-light-position-y').val())
lights.point.z = parseFloat($('#point-light-position-z').val())
lights.point.decay = parseFloat($('#point-light-decay').val())
}

function changeSpotLight() {
lights.spot.x = $('#spot-light-position-x').val()
lights.spot.y = $('#spot-light-position-y').val()
lights.spot.z = $('#spot-light-position-z').val()
lights.spot.decay = $('#spot-light-decay').val()
lights.spot.x = parseFloat($('#spot-light-position-x').val())
lights.spot.y = parseFloat($('#spot-light-position-y').val())
lights.spot.z = parseFloat($('#spot-light-position-z').val())
lights.spot.decay = parseFloat($('#spot-light-decay').val())
lights.spot.phi = utils.degToRad($('#spot-light-position-phi').val())
lights.spot.theta = utils.degToRad($('#spot-light-position-theta').val())
lights.spot.coneIn = $('#spot-light-cone-in').val()
lights.spot.coneOut = $('#spot-light-cone-out').val()
lights.spot.coneIn = parseFloat($('#spot-light-cone-in').val())
lights.spot.coneOut = parseFloat($('#spot-light-cone-out').val())
}

function setColor() {
Expand All @@ -114,9 +114,9 @@ function setColor() {
}

function setSpecShine() {
lights.shiny = $('#specular-shiny').val()
lights.shiny = parseFloat($('#specular-shiny').val())
}

function setTextureMix() {
lights.tMix = $('#texture-mix').val()
lights.tMix = parseFloat($('#texture-mix').val())
}
5 changes: 3 additions & 2 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ function drawScene() {
drawModel(missile.model1 ? models.missile1 : models.missile2, missileWorldMatrix, cm)
drawModel(models.landscape, utils.MakeWorld(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1), cm)
if (lights.lightType[1] === 1) {
drawModel(models.sphere, utils.MakeWorld(lights.point.x, lights.point.y + 0.1, lights.point.z, 0, 0, 0, 0.05),
cm, decodeColor(lights.colors.light), true)
let lightColor = decodeColor(lights.colors.light)
for (let i = 0; i < lightColor.length; i++) lightColor[i] *= 0.8 + lights.point.decay / 10.0
drawModel(models.sphere, utils.MakeWorld(lights.point.x, lights.point.y, lights.point.z, 0, 0, 0, 0.05), cm, lightColor, true)
} else if (lights.lightType[2] === 1) {
const angle = lights.lightType[2] === 1 ? lights.spot.phi : 0
const elevation = lights.lightType[2] === 1 ? lights.spot.theta : 0
Expand Down

0 comments on commit c17367c

Please sign in to comment.