-
Notifications
You must be signed in to change notification settings - Fork 44
/
zooming-ball.js
34 lines (29 loc) · 1.09 KB
/
zooming-ball.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* eslint-env browser */
import { Beam, ResourceTypes } from '../../../src/index.js'
import { NormalColor } from '../../shaders/basic-graphics-shaders.js'
import { createBall } from '../../utils/graphics-utils.js'
import { createCamera } from '../../utils/camera.js'
const { VertexBuffers, IndexBuffer, Uniforms } = ResourceTypes
const canvas = document.querySelector('canvas')
const beam = new Beam(canvas)
const shader = beam.shader(NormalColor)
const ball = createBall()
const buffers = [
beam.resource(VertexBuffers, ball.vertex),
beam.resource(IndexBuffer, ball.index)
]
let i = 0; let d = 10
const cameraMats = createCamera({ eye: [0, d, d] })
const camera = beam.resource(Uniforms, cameraMats)
const tick = () => {
i += 0.02; d = 10 + Math.sin(i) * 5
const { viewMat } = createCamera({ eye: [0, d, d] })
// Update uniform resource
camera.set('viewMat', viewMat)
// Or perform update with new resourse:
// cameraMats.viewMat = viewMat
// camera = beam.resource(Uniforms, cameraMats)
beam.clear().draw(shader, ...buffers, camera)
requestAnimationFrame(tick)
}
tick() // Begin render loop