Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
}
}
function normalise(vec) {
const out = [];
vec3.normalize(out, vec);
return out;
}
function normalise(vec) {
var out = [];
vec3.normalize(out, vec);
return out;
}
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])
}
})
}
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))
}
})
}
}
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
}
})
}
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])
}
})
}
)
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)
}
})
}