-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproportional.html
74 lines (59 loc) · 1.6 KB
/
proportional.html
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
71
72
73
74
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<canvas id="screen" width="500" height="500" style="border:1px solid #ccc"></canvas>
</body>
<script type="text/javascript">
var canvas = document.getElementById('screen');
var ctx = canvas.getContext('2d');
var cube = [
[-1,-1,-1],
[1,-1,-1],
[1,1,-1],
[-1,1,-1],
[-1,-1,1],
[1,-1,1],
[1,1,1],
[-1,1,1]
];
var fov = 45;
var fl = 250;
var angle = 0;
function render(ts) {
ctx.clearRect(0, 0, 500, 500);
cube.forEach(function(coord, i) {
var x = coord[0];
var y = coord[1];
var z = coord[2];
var c = Math.cos(angle);
var s = Math.sin(angle);
// 코마신신코 !
// y axis
var rx = c*x - s*z;
var rz = s*x + c*z;
// z axis
var ry = s*rx + c*y;
rx = c*rx - s*y;
// // s,t
// var mz = z - 5;
// var sx = (x / -mz) * fl;
// var sy = (y / -mz) * fl;
// s,t
var tz = rz - 5;
var sx = (rx / -tz) * fl + canvas.width/2;
var sy = (ry / -tz) * fl + canvas.height/2;
ctx.beginPath();
ctx.arc(sx, sy, tz + 7, 0, 2 * Math.PI, true);
ctx.stroke();
});
angle += 2 * Math.PI / 360;
angle %= 2 * Math.PI;
window.requestAnimationFrame(render);
}
window.requestAnimationFrame(render);
</script>
</html>