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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
<!DOCTYPE html>
<head>
<meta charset="utf-8"/>
<title>Черната дупка</title>
<script src="webgl-fmi.js"></script>
<script src="shaders.js"></script>
<style>
canvas {
display: block;
position: fixed;
border: 1px solid black;
width: calc(100vw - 18px);
height: calc(100vh - 18px);
}
</style>
<script>
function start()
{
var canvas = document.getElementById("picasso");
canvas.addEventListener('webglcontextlost',function(event){event.preventDefault();},false);
canvas.addEventListener('webglcontextrestored',function(){init();},false);
init();
}
function init()
{
gl = getContext("picasso");
glprog = getProgram(vShader,fShader);
getVariables();
gl.enable(gl.DEPTH_TEST);
gl.clearColor(1,1,1,1);
identity();
perspective(30,gl.canvas.width/gl.canvas.height,1,40000);
gl.uniform1i(uUseNormalMatrix,false);
gl.uniform3f(uAmbientColor,0.3,0.3,0.3);
gl.uniform3f(uDiffuseColor,1,1,1);
gl.uniform3f(uLightDir,0,0,-1);
blackHole = new BlackHole([0,0,0], 1);
planet1 = new Sphere([-5,0,0], 0.5);
planet1.color = [1,0,0];
resizeglcanvas();
}
BlackHole = function(center, size) {
this.sphere = new Sphere(center, size);
}
BlackHole.prototype.draw = function() {
this.sphere.draw();
}
function resizeglcanvas() {
gl.canvas.width = gl.canvas.offsetWidth;
gl.canvas.height = gl.canvas.offsetHeight;
gl.viewport(0,0,gl.canvas.width,gl.canvas.height);
// var proj=orthoMatrix(gl.canvas.width,gl.canvas.height,-1000,1000);
// gl.uniformMatrix4fv(uProjectionMatrix,false,proj);
drawFrame();
}
window.onresize = resizeglcanvas;
function drawFrame()
{
gl.clear(gl.COLOR_BUFFER_BIT+gl.DEPTH_BUFFER_BIT);
lookAt([10, 0, 3], [0,0,0], [0,0,1]);
blackHole.draw();
planet1.draw();
requestAnimationFrame(drawFrame);
}
</script>
</head>
<body onload="start()">
<canvas id="picasso"></canvas>
</body>
|