-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproject1Scene.js
112 lines (94 loc) · 7.72 KB
/
project1Scene.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
// like the functions in game.js, this function builds a scene graph, this time for the clone of assignment 1
function buildProject1Scene (SGraph) {
SGraph.lightsManager.addSource (new light (new transform (vec3.fromValues (0.0, 0.0, 0.0), vec3.fromValues(1.0, 1.0, 1.0), quat.create ()),
vec3.fromValues (0.0, 0.0, 0.0),
vec4.fromValues (0.6, 0.6, 0.6, 1.0),
vec4.fromValues (0.6, 0.6, 0.6, 1.0),
vec4.fromValues (0.6, 0.6, 0.6, 1.0)));
SGraph.lightsManager.lightSources[0].tag = "light";
SGraph.lightsManager.lightSources[0].shadows = false;
var cam = new camera ([0,0,0], glMatrix.toRadian (0.0), glMatrix.toRadian (0.0));
var rot = quat.create ();
quat.setAxisAngle (rot, [0,1,0], glMatrix.toRadian (0.0));
var player = new object (new transform (vec3.fromValues (0.0, 0.0, 40.0), vec3.fromValues (1.0, 1.0, 1.0), rot),
null,
null,
null,
new nullCollider (),
null);
player.camera = cam;
player.tag = "player";
SGraph.playerController = new PlayerControllerFly (player);
SGraph.push (player);
generateCubeNormals (cubeVertices);
generateCubeVertices (cubeVertices);
generateCubeTexCoords (texCoords);
var prismGeo = new geometry (pointsArray, normalsArray, textureArray);
var cubes = new object ();
cubes.children.push (new object (new transform (vec3.fromValues (-10.0, -10.0, -10.0), vec3.fromValues (1.0, 1.0, 1.0), quat.create ()),
new material (vec4.fromValues (1.0, 0.0, 0.0, 1.0), vec4.fromValues (1.0, 0.0, 0.0, 1.0), vec4.fromValues (1.0, 0.0, 0.0, 1.0), 40.0),
prismGeo,
new texture (document.getElementById ("whiteTEX"), [ [gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR], [gl.TEXTURE_MAG_FILTER, gl.NEAREST], [gl.TEXTURE_WRAP_S, gl.REPEAT], [gl.TEXTURE_WRAP_T, gl.REPEAT]]),
new nullCollider (),
null
));
cubes.children.push (new object (new transform (vec3.fromValues (-10.0, -10.0, 10.0), vec3.fromValues (1.0, 1.0, 1.0), quat.create ()),
new material (vec4.fromValues (1.0, 1.0, 0.0, 1.0), vec4.fromValues (1.0, 1.0, 0.0, 1.0), vec4.fromValues (1.0, 1.0, 0.0, 1.0), 40.0),
prismGeo,
new texture (document.getElementById ("whiteTEX"), [ [gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR], [gl.TEXTURE_MAG_FILTER, gl.NEAREST], [gl.TEXTURE_WRAP_S, gl.REPEAT], [gl.TEXTURE_WRAP_T, gl.REPEAT]]),
new nullCollider (),
null
));
cubes.children.push (new object (new transform (vec3.fromValues (-10.0, 10.0, -10.0), vec3.fromValues (1.0, 1.0, 1.0), quat.create ()),
new material (vec4.fromValues (1.0, 0.0, 1.0, 1.0), vec4.fromValues (1.0, 0.0, 1.0, 1.0), vec4.fromValues (1.0, 0.0, 1.0, 1.0), 40.0),
prismGeo,
new texture (document.getElementById ("whiteTEX"), [ [gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR], [gl.TEXTURE_MAG_FILTER, gl.NEAREST], [gl.TEXTURE_WRAP_S, gl.REPEAT], [gl.TEXTURE_WRAP_T, gl.REPEAT]]),
new nullCollider (),
null
));
cubes.children.push (new object (new transform (vec3.fromValues (-10.0, 10.0, 10.0), vec3.fromValues (1.0, 1.0, 1.0), quat.create ()),
new material (vec4.fromValues (0.0, 1.0, 0.0, 1.0), vec4.fromValues (0.0, 1.0, 0.0, 1.0), vec4.fromValues (0.0, 1.0, 0.0, 1.0), 40.0),
prismGeo,
new texture (document.getElementById ("whiteTEX"), [ [gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR], [gl.TEXTURE_MAG_FILTER, gl.NEAREST], [gl.TEXTURE_WRAP_S, gl.REPEAT], [gl.TEXTURE_WRAP_T, gl.REPEAT]]),
new nullCollider (),
null
));
cubes.children.push (new object (new transform (vec3.fromValues (10.0, -10.0, -10.0), vec3.fromValues (1.0, 1.0, 1.0), quat.create ()),
new material (vec4.fromValues (0.0, 1.0, 1.0, 1.0), vec4.fromValues (0.0, 1.0, 1.0, 1.0), vec4.fromValues (0.0, 1.0, 1.0, 1.0), 40.0),
prismGeo,
new texture (document.getElementById ("whiteTEX"), [ [gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR], [gl.TEXTURE_MAG_FILTER, gl.NEAREST], [gl.TEXTURE_WRAP_S, gl.REPEAT], [gl.TEXTURE_WRAP_T, gl.REPEAT]]),
new nullCollider (),
null
));
cubes.children.push (new object (new transform (vec3.fromValues (10.0, -10.0, 10.0), vec3.fromValues (1.0, 1.0, 1.0), quat.create ()),
new material (vec4.fromValues (0.0, 0.0, 1.0, 1.0), vec4.fromValues (0.0, 0.0, 1.0, 1.0), vec4.fromValues (0.0, 0.0, 1.0, 1.0), 40.0),
prismGeo,
new texture (document.getElementById ("whiteTEX"), [ [gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR], [gl.TEXTURE_MAG_FILTER, gl.NEAREST], [gl.TEXTURE_WRAP_S, gl.REPEAT], [gl.TEXTURE_WRAP_T, gl.REPEAT]]),
new nullCollider (),
null
));
cubes.children.push (new object (new transform (vec3.fromValues (10.0, 10.0, -10.0), vec3.fromValues (1.0, 1.0, 1.0), quat.create ()),
new material (vec4.fromValues (1.0, 0.5, 0.0, 1.0), vec4.fromValues (1.0, 0.5, 0.0, 1.0), vec4.fromValues (1.0, 0.5, 0.0, 1.0), 40.0),
prismGeo,
new texture (document.getElementById ("whiteTEX"), [ [gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR], [gl.TEXTURE_MAG_FILTER, gl.NEAREST], [gl.TEXTURE_WRAP_S, gl.REPEAT], [gl.TEXTURE_WRAP_T, gl.REPEAT]]),
new nullCollider (),
null
));
cubes.children.push (new object (new transform (vec3.fromValues (10.0, 10.0, 10.0), vec3.fromValues (1.0, 1.0, 1.0), quat.create ()),
new material (vec4.fromValues (0.0, 0.5, 1.0, 1.0), vec4.fromValues (0.0, 0.5, 1.0, 1.0), vec4.fromValues (0.0, 0.5, 1.0, 1.0), 40.0),
prismGeo,
new texture (document.getElementById ("whiteTEX"), [ [gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR], [gl.TEXTURE_MAG_FILTER, gl.NEAREST], [gl.TEXTURE_WRAP_S, gl.REPEAT], [gl.TEXTURE_WRAP_T, gl.REPEAT]]),
new nullCollider (),
null
));
for (var i = 0; i < cubes.children.length; i++) {
var omega = 40 + 10 * i;
var randX = Math.random ();
var randY = Math.random ();
var randZ = Math.random ();
var axis = vec3.fromValues (randX, randY, randZ);
vec3.normalize (axis, axis);
cubes.children[i].addAnimation (new animationRotation (cubes.children[i], omega, axis));
}
SGraph.push (cubes);
}