Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics Fundamentals / 05-Practice-31.10.2022 / 04.js
blob: b41e1a8d80c102b2c9b9df66c41bf4ec0afeaf0b (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
// Задача: конструирайте ... хипербола


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;
camera = new THREE.PerspectiveCamera( 30, aspect );
camera.position.set( 0, 0, 100 );
camera.lookAt( new THREE.Vector3() );

// За момента имаме само окръжност
var material = new THREE.MeshPhongMaterial();

var circle = new THREE.Mesh(new THREE.CylinderGeometry( 20, 20, 1/2, 80 ), material);

var cone1 = new THREE.Mesh(new THREE.CylinderGeometry(0.1, 10, 10, 64, 16), material);
cone1.rotation.z = Math.PI / 2;
cone1.position.y = -2;
var cone2 = new THREE.Mesh(new THREE.CylinderGeometry(0.1, 10, 10, 64, 16), material);
cone2.position.x = -10;
cone2.position.y = -2;
cone2.rotation.z = -Math.PI / 2;

var csg = new CSG();
csg.union([cone1, cone2]);
csg.intersect([circle]);

var hype = csg.toMesh();
hype.material = material;

scene.add( hype );

// Добавяме светлина
light = new THREE.PointLight( 'lightblue' );
light.position.set( 0, 0, 100 );
scene.add( light );

function drawFrame()
{
	// въртим окръжността
	hype.rotation.x += 0.005;
	hype.rotation.y += 0.004;
	hype.rotation.z += 0.003;
	
	renderer.render( scene, camera );
}