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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
<!DOCTYPE html>
<head>
<meta charset="utf-8"/>
<title>Черната дупка</title>
<script src="webgl-fmi.js"></script>
<script src="shaders.js"></script>
<style>
body {
padding: 0;
margin: 0;
font: 18px sans-serif;
}
canvas {
display: block;
pos: fixed;
left: 0;
top: 0;
width: 100vw;
height: 100vh;
/* cursor: none; */
}
.hide {
display: none;
}
h2 {
border-bottom: 2px solid gray;
}
#menu {
position: absolute;
height: 100vh;
width: 100vw;
left: 0;
top: 0;
color: white;
}
#menu > * {
position: absolute;
margin: 0.5em;
padding: 0.2em;
border: 2px solid white;
width: auto;
background-color: black;
}
#paused {
left: 0;
top: 0;
font-size: 25px;
cursor: pointer;
}
#settings {
right: 0;
top: 0;
padding: 0.5em;
max-width: 24em;
max-height: calc(100vh - 0.5em);
}
</style>
<script src="spaceship.js"></script>
<script src="skybox.js"></script>
<script src="star.js"></script>
<script src="blackhole.js"></script>
<script src="level.js"></script>
<script>
/*
* WebGL
*/
function start()
{
canvas = document.getElementById('picasso');
canvas.addEventListener('webglcontextlost',function(event){event.preventDefault();},false);
canvas.addEventListener('webglcontextrestored',function(){init();},false);
mouseInit();
init();
}
const PERSPECTIVE_ANGLE = 30;
const PERSPECTIVE_NEAR = 1;
function init()
{
gl = getContext('picasso');
glprog = getProgram(vShader,fShader);
getVariables();
gl.enable(gl.DEPTH_TEST);
gl.clearColor(1,1,1,1);
// For proper transparency
gl.enable(gl.BLEND);
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
identity();
perspective(PERSPECTIVE_ANGLE,gl.canvas.width/gl.canvas.height,PERSPECTIVE_NEAR,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);
gl.uniform4f(uBlack, 0,0,0,1);
gl.uniform4f(uBHBlack, 0,0,0,1);
skybox = new Skybox(10000, [0,0,0], undefined);
createLevels();
initMenu();
resizeglcanvas();
}
function resizeglcanvas() {
gl.canvas.width = gl.canvas.offsetWidth;
gl.canvas.height = gl.canvas.offsetHeight;
gl.viewport(0,0,gl.canvas.width,gl.canvas.height);
drawFrame();
}
window.onresize = resizeglcanvas;
var pauseAnimations = false;
var startT = -1;
function drawFrame()
{
if (startT == -1) startT = Date.now();
var t = Math.floor(Date.now() - startT) / 10; // tenths of a second
gl.clear(gl.COLOR_BUFFER_BIT+gl.DEPTH_BUFFER_BIT);
updateCamera();
gl.uniform3fv(uEye, pos);
skybox.draw();
if (!pauseAnimations) animations.forEach((a) => a(t));
stars.forEach((s) => s.draw());
requestAnimationFrame(drawFrame);
}
</script>
</head>
<body onload="start()">
<canvas id="picasso"></canvas>
<div id="menu">
<div id="paused">Click here to start moving</div>
<div id="settings">
<h2>About</h2>
<p>
Simulation of the light-bending effects of black holes.<br>
WASD to move around, space and shift for up and down, mouse cursor to look around.<br>
Escape will remove your controls and bring you back here.
</p>
<h2>Level</h2>
<p>
<select id="level-select"></select>
<p id="level-description"></p>
<p>
Pause movement: <input type="checkbox" id="pause-movement">
</p>
</p>
<h2>Settings</h2>
<p>
Debug mode: <input type="checkbox" id="debug-mode"><br>
Only horizontal mouse movement: <input type="checkbox" id="only-horizontal"><br>
Only vertical mouse movement: <input type="checkbox" id="only-vertical">
</p>
</div>
</div>
<script src="menu.js"></script>
</body>
|