-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
134 lines (106 loc) · 2.38 KB
/
script.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
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
/**
* Created by 4r3 on 20/04/16.
*/
//GLOBALS
var gl;
var shaderProgram;
var mvMatrix = mat4.create();
var mvMatrixStack = [];
var pMatrix = mat4.create();
//textures
var videoTexture;
//interaction
var drawStyle;
var myCamera = new camera(null);
var lastTime = 0;
var mouseDown = false;
var lastMouseX = null;
var lastMouseY = null;
var currentZoom = 1;
//world
var rootObject;
var tempSkybox;
var planets = [];
//geometry
var pasLat = 3;
var pasLong = 6;
var tetaMax = 360;
var phiMax = 90;
//scale factor
Kt=1;
Ks = 1/2;
Ks2 = 1000;
/**
* function that initialise a webGl context
* @param canvas
*/
function initGL(canvas)
{
try
{
gl = canvas.getContext("experimental-webgl");
gl.viewportWidth = canvas.width;
gl.viewportHeight = canvas.height;
} catch (e) {}
if (!gl)
{
alert("Could not initialise WebGL, sorry :-(");
}
}
//INITGL
/**
* fonction that initialise the draw of the scene from the camera point of view
*/
function drawScene()
{
gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
myCamera.draw();
}
/**
* funtion that compute the quantity of animation to do and which start the animation
* computation for the scene objects
*/
function animate()
{
var timeNow = new Date().getTime();
var elapsed = 0;
if (lastTime != 0)
{
elapsed = timeNow - lastTime;
}
rootObject.animate(elapsed);
lastTime = timeNow;
}
/**
* animation loop, this function call itself to animate and draw the scene
*/
function tick() {
requestAnimFrame(tick);
drawScene();
animate();
updateTexture();
}
/**
* function that is called to initialize the script, it will init the web gl context,
* the shaders, the textures and the objects of the scene and the user action handlers
*/
function webGLStart() {
var canvas = document.getElementById("lesson03-canvas");
//webGL
initGL(canvas);
initShaders();
initTextures();
rootObject = null;
initWorld();
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.enable(gl.DEPTH_TEST);
//interactions
canvas.onmousedown = handleMouseDown;
document.onmouseup = handleMouseUp;
document.onmousemove = handleMouseMove;
canvas.onmousewheel = handleWheel;
window.addEventListener("keydown", handleKeyDown, false);
drawStyle = gl.TRIANGLES;
tick();
}