Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics Fundamentals / Practicum Homework / a04.html
blob: b6a03c184c0436fe7cb187807c3e6b473fa5c335 (plain) (blame)
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
<html>
	<head>
		<style>
			body { margin: 0; }
			canvas { width: 100%; height: 100% }
		</style>
	</head>
	<body>
		<script src="three.min.js"></script>
		<script>
			var renderer = new THREE.WebGLRenderer();
			renderer.setSize( window.innerWidth, window.innerHeight );
			renderer.setAnimationLoop( drawFrame );
			document.body.appendChild( renderer.domElement );

			var scene = new THREE.Scene();
			
			var aspect = window.innerWidth/window.innerHeight;
			var camera = new THREE.PerspectiveCamera( 30, aspect );
			camera.position.set( 0, 3, 0 );
			camera.lookAt( new THREE.Vector3() );



			var sky = new THREE.Group();

			const skySize = 3;
			var skyPlatform = new THREE.Mesh(new THREE.BoxGeometry(skySize, 0.1, skySize), new THREE.MeshPhongMaterial());
			sky.add(skyPlatform);

			const scale = 0.005;
			const starSizeScale = 0.4;
			const y = 0.058;
			function addStar(x, z, size) {
				x *= scale; z *= scale;
				var star = new THREE.Mesh(
					new THREE.SphereGeometry(size * starSizeScale * scale, 32, 32, 0, Math.PI * 2, 0, Math.PI / 2),
					new THREE.MeshBasicMaterial({color: 0xecceff}));
				star.position.set(x, y, z);

				var light = new THREE.PointLight(0xd520ff);
				light.target = skyPlatform;
				light.shadows = false;

				star.add(light);
				sky.add(star);
			}
			var lineDots = [];
			function pushLineDots(x1, z1, x2, z2) {
				lineDots.push(new THREE.Vector3(x1 * scale, y, z1 * scale));
				lineDots.push(new THREE.Vector3(x2 * scale, y, z2 * scale));
			}
			function addLine(x1, z1, x2, z2) {
				sky.add(new THREE.LineSegments(
					new THREE.BufferGeometry().setFromPoints(lineDots),
					new THREE.LineBasicMaterial({color: 0x613181}))
				);
			}

			addStar(-93, -110, 6);
			pushLineDots(-93, -110, -2, -39); addStar(-2, -39, 7);
			pushLineDots(-93, -110, -76, 13);
			pushLineDots(-2, -39, -76, 13); addStar(-76, 13, 6);
			pushLineDots(-76, 13, -54, 94); addStar(-54, 94, 6);
			pushLineDots(-54, 94, -29, 95); addStar(-29, 95, 9);
			pushLineDots(-29, 95, -32, 109); addStar(-32, 109, 6);
			pushLineDots(-32, 109, 10, 84); addStar(10, 84, 4);
			pushLineDots(10, 84, 33, 37); addStar(33, 37, 8);
			pushLineDots(33, 37, -2, -39);
			pushLineDots(33, 37, 75, 29); addStar(75, 29, 6);
			pushLineDots(75, 29, 87, 9); addStar(87, 9, 3);
			addLine();

			scene.add(sky);


			var light = new THREE.PointLight( );
			light.position.set( 3, 4, 5 );
			light.target = skyPlatform;
			//scene.add( light );
			
			light = new THREE.PointLight( );
			light.position.set( -3, 4, -5 );
			//scene.add( light );

			// въртене на сцената като в микровълнова фурна
			function drawFrame()
			{
				// scene.rotation.y += 0.005;
				renderer.render( scene, camera );
			}
			// КРАЙ
		</script>
	</body>
</html>