Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
70 lines (59 loc) · 1.68 KB
/
Copy pathscript.js
File metadata and controls
70 lines (59 loc) · 1.68 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import * as Bmo from "./lib/bmo.js"
// let dx = 0
// let dy = 0
// let dz = 1
let angle = 0
const models = [
{
model: Bmo.shape,
angles: {
x: 90,
y: 30,
z: 60
},
location: {
x: -0.33,
y: 0,
z: 1
},
pointsSize: 6,
linesThinkness: 4,
surfacesColor: "#00ff00"
},
{
model: Bmo.cube,
angles: {
x: 90,
y: 30,
z: 60
},
location: {
x: 1,
y: 0,
z: 3
},
pointsSize: 6,
linesThinkness: 4,
surfacesColor: "#00ff00"
}
]
function frame(models) {
const dt = 1 / Bmo.FPS
angle += 2 * Math.PI * dt / 12
Bmo.clear()
for (let i = 0; i < models.length; ++i) {
const m = models[i]
const pointsSize = m.pointsSize * (Bmo.WIDTH + Bmo.HEIGHT) / 1600 / m.location.z
const linesThinkness = m.linesThinkness * (Bmo.WIDTH + Bmo.HEIGHT) / 1600 / m.location.z
const angle_x = (Math.PI / 180) * m.angles.x
const angle_y = (Math.PI / 180) * m.angles.y
const angle_z = (Math.PI / 180) * m.angles.z
const rotated = Bmo.rotate_xz(Bmo.rotate_yz(Bmo.rotate_xy(m.model, angle_x + angle), angle_y + angle), angle_z + angle)
const moved = Bmo.move_z(Bmo.move_y(Bmo.move_x(rotated, m.location.x), m.location.y), m.location.z)
Bmo.drawSurfaces(moved, { color: m.surfacesColor})
Bmo.drawEdges(moved, {thinkness: linesThinkness, color: "#ff0000"})
Bmo.drawVertices(moved, { size: pointsSize, color: "#7f7f7f" })
}
setTimeout(frame, 1000 / Bmo.FPS, models)
}
setTimeout(frame, 1000 / Bmo.FPS, models)