-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolarSystem.html
163 lines (147 loc) · 4.82 KB
/
solarSystem.html
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
<!DOCTYPE html>
<html>
<head>
<title>Getting Started with Three.js</title>
<script src="../build/three.min.js"></script>
<script src="js/renderers/Projector.js"></script>
<script src="js/renderers/CanvasRenderer.js"></script>
<script src="js/libs/stats.min.js"></script>
<script>
/* AUTHOR : AK67
DESCRIPTION : EMULATE SOLAR SYSTEM IN THE MOST EFFICIENT WAY
Last MODIFIED : 26/12/2014
*/
window.onload = function() {
var renderer = new THREE.WebGLRenderer();
renderer.setSize( 1400, 700 );
document.body.appendChild( renderer.domElement );
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(
35, // Field of view
800 / 600, // Aspect ratio
0.1, // Near plane
10000 // Far plane
);
camera.position.z = 150;
camera.lookAt( scene.position );
var light = new THREE.PointLight( 0xFFFF00 );
light.position.set( 0, 0, 20 );
scene.add( light );
var geom = new THREE.SphereGeometry(5);
var jupGeom = new THREE.SphereGeometry(3);
var sun = giveMeSphere(geom,0xFFCC00,0xFFCC00);
var jupiter = giveMeSphere(jupGeom,0x990000,0x990000);
var xDirectionForJupiter = 1;
var zDirectionForJupiter = 1;
jupiter.position.x = sun.position.x - 20;
scene.add(camera);
scene.add(sun) ;
scene.add(jupiter) ;
animate();
var radiusOfSunJupiter = getRadius(jupiter,sun);
function animate() {
render();
requestAnimationFrame( animate );
}
function render() {
revolveX(radiusOfSunJupiter, jupiter, sun, .5, 0, xDirectionForJupiter);
sun.rotation.y += .01;
jupiter.rotation.y +=.01;
renderer.render( scene, camera );
}
// AK67 functions -- Start
// ---------------------------------------------------------------------------------------------------------------------------------//
// xSpeedOfRevoltuionOfSource is used to keep the system consistent if the source is itself moving
// startDirection self Explanatory
function revolveX(radius,obj,objToRevolveAround,speedOfRevolution,xSpeedOfRevoltuionOfSource,startDirection)
{
revolveZ(obj,zDirectionForJupiter);
console.log("obj.position.z"+obj.position.z);
console.log("z direction"+zDirectionForJupiter);
//console.log("xDirectionForJupiter" + xDirectionForJupiter);
// if direction is 0 then move in +X axis else move towards -X axis
var distanceBetweenObjcs = objToRevolveAround.position.x - obj.position.x ;
if(xDirectionForJupiter == 0)
{
if(obj.position.x >= (objToRevolveAround.position.x +radius))
{
obj.position.x = obj.position.x - speedOfRevolution;
// after changing x ,if condition is fullfiled then switch direction
if(obj.position.x < objToRevolveAround.position.x + radius)
{
xDirectionForJupiter = 1;
zDirectionForJupiter = directionChanger(zDirectionForJupiter);
}
}
else
{
obj.position.x = obj.position.x + speedOfRevolution;
}
}
else
{
if(obj.position.x <= (objToRevolveAround.position.x - radius))
{
obj.position.x = obj.position.x - speedOfRevolution;
// after changing x , condition is fullfiled then switch direction
if(obj.position.x <= objToRevolveAround.position.x + radius)
{
xDirectionForJupiter = 0;
zDirectionForJupiter = directionChanger(zDirectionForJupiter);
}
}
else
{
obj.position.x = obj.position.x - speedOfRevolution;
}
}
}
function revolveZ(obj,direction)
{
console.log("Zdirection"+direction);
if(direction == 1)
{
obj.position.z += .5;
}
else
{
obj.position.z -= .5;
}
}
function getRadius(objSecondary , objPrimary)
{
var radius = objPrimary.position.x - objSecondary.position.x;
if( radius < 0 )
{
radius = radius * (-1);
}
return radius;
}
// returns a spherical Object
function giveMeSphere(geometry,color,shading)
{
var sphere = new THREE.Mesh(
geometry,
new THREE.MeshPhongMaterial( {
color: color,
})
);
return sphere;
}
function directionChanger(direction)
{
if(direction == 1)
{
direction = 0
}
else
{
direction = 1;
}
return direction;
}
};
</script>
</head>
<body></body>
</html>