How to use the gl-vec3.normalize function in gl-vec3

To help you get started, we’ve selected a few gl-vec3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rolyatmax / sketches / src / ruminative-steven.js View on Github external
function tick () {
    let velocity = vec3.subtract([], curPosition, lastPosition)
    const delta = vec3.subtract([], destination, curPosition)
    const acceleration = vec3.scale([], delta, 0.001)
    velocity = vec3.add(velocity, acceleration, velocity)
    if (vec3.length(velocity) > 0.005) {
      velocity = vec3.normalize(velocity, velocity)
      velocity = vec3.scale(velocity, velocity, 0.005)
    }
    const nextPosition = vec3.add([], velocity, curPosition)
    lastPosition = curPosition
    curPosition = nextPosition
    return curPosition
  }
}
github djalbat / xgl / es6 / maths / vec3.js View on Github external
function normalise(vec) {
  const out = [];

  vec3.normalize(out, vec);

  return out;
}
github djalbat / xgl / lib / maths / vec3.js View on Github external
function normalise(vec) {
  var out = [];

  vec3.normalize(out, vec);

  return out;
}
github gregtatum / sessions / 004 / scene.js View on Github external
controls.update()
        controls.copyInto(camera.position, camera.direction, camera.up)
        camera.viewport[2] = viewportWidth
        camera.viewport[3] = viewportHeight
        camera.update()
        prevTick = tick
      }
      return callback.apply(null, arguments)
    }
  }

  return regl({
    uniforms: {
      projection: update(() => camera.projection),
      view: update(() => camera.view),
      light1: vec3.normalize([], [-1, 0.5, 0.3])
    }
  })
}
github gregtatum / sessions / 009 / scene.js View on Github external
time: ({time}) => time,
      projection: update(() => camera.projection),
      view: (() => {
        const eye = []
        const center = [0, 0, 0]
        const up = [0, 1, 0]
        const tilt = []
        return ({time}) => {
          vec3.rotateY(eye, eyeStart, center, time * 0.1)
          vec3.rotateX(tilt, up, center, simplex.noise2D(100, time * 0.15))
          return mat4.lookAt(view, eye, cameraPositionNoise, tilt)
        }
      })(),
      invView: withArrays(1, ([out]) => mat4.invert(out, view)),
      light0: vec3.normalize([], [0.2, 0.4, -1]),
      light1: vec3.normalize([], [-0.2, 0.5, 1]),
      lightColor0: [1.0, 1.0, 1.0],
      lightColor1: [0.2, 0.3, 0.3],
      viewNormal: withArrays(1, ([out]) => mat3.normalFromMat4(out, camera.view))
    }
  })
}
github gregtatum / sessions / 011 / scene.js View on Github external
}
      return callback.apply(null, arguments)
    }
  }

  return regl({
    uniforms: {
      projection: update(() => camera.projection),
      view: () => camera.view,
      projView: () => camera.projView,
      inverseProjection: () => mat4.invert([], camera.projection),
      inverseView: () => mat4.invert([], camera.view),
      viewNormal: withArrays(1, ([out]) => mat3.normalFromMat4(out, camera.view)),
      projectionViewNormal: withArrays(1, ([out]) => mat3.normalFromMat4(out, camera.projView)),
      light0: vec3.normalize([], [0, 1, 0.1]),
      light1: vec3.normalize([], [0.5, -1, 0.5]),
      light2: vec3.normalize([], [-0.5, 0.2, 0.8]),
      lightColor0: vec3.scale([], [1.0, 0.9, 0.9], 0.6 * 0),
      lightColor1: vec3.scale([], [0.8, 1.0, 1.0], 0.6 * 0),
      lightColor2: vec3.scale([], [0.8, 0.8, 1.0], 0.6 * 0),
      time: ({time}) => time,
      cameraPosition: () => camera.position
    },
    context: {
      fov: FOV
    }
  })
}
github gregtatum / sessions / 007 / scene.js View on Github external
return ({tick, viewportWidth, viewportHeight}) => {
      if (tick !== prevTick) {
        camera.viewport[2] = viewportWidth
        camera.viewport[3] = viewportHeight
        camera.update()
        prevTick = tick
      }
      return callback.apply(null, arguments)
    }
  }

  return regl({
    uniforms: {
      projection: update(() => camera.projection),
      view: update(() => camera.view),
      light1: vec3.normalize([], [-1, 0.5, 0.3])
    }
  })
}
github gregtatum / sessions / 008 / scene.js View on Github external
)

        camera.update()
        prevTick = tick
      }
      return callback.apply(null, arguments)
    }
  }

  return regl({
    uniforms: {
      time: ({time}) => time,
      projection: update(() => camera.projection),
      view: update(() => camera.view),
      light0: vec3.normalize([], [0.2, 0.4, -1]),
      light1: vec3.normalize([], [-0.2, 0.5, 1]),
      lightColor0: [1.0, 1.0, 1.0],
      lightColor1: [0.2, 0.3, 0.3],
      viewNormal: () => mat3.normalFromMat4([], camera.view)
    }
  })
}

gl-vec3

gl-matrix's vec3, split into smaller pieces

Zlib
Latest version published 6 years ago

Package Health Score

54 / 100
Full package analysis