Skip to content

Commit 5c16a1a

Browse files
committed
Wrote the first section of code, which initialises ThreeJS and draws a sphere.
1 parent 6ce5591 commit 5c16a1a

File tree

4 files changed

+941
-0
lines changed

4 files changed

+941
-0
lines changed

Concept/Space_Concept.svg

+130
Loading

Scripts/game.js

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
var renderer, scene, camera;
2+
3+
function setup()
4+
{
5+
// set the scene size
6+
var WIDTH = 640,
7+
HEIGHT = 360;
8+
9+
// // set some camera attributes
10+
var VIEW_ANGLE = 45,
11+
ASPECT = WIDTH / HEIGHT,
12+
NEAR = 0.1,
13+
FAR = 10000;
14+
15+
var c = document.getElementById("gameCanvas");
16+
17+
// // create a WebGL renderer, camera
18+
// // and a scene
19+
renderer = new THREE.WebGLRenderer();
20+
camera =
21+
new THREE.PerspectiveCamera(
22+
VIEW_ANGLE,
23+
ASPECT,
24+
NEAR,
25+
FAR);
26+
27+
scene = new THREE.Scene();
28+
29+
// // add the camera to the scene
30+
scene.add(camera);
31+
32+
// // the camera starts at 0,0,0
33+
// // so pull it back
34+
camera.position.z = 300;
35+
36+
// // start the renderer
37+
renderer.setSize(WIDTH, HEIGHT);
38+
39+
// // attach the render-supplied DOM element
40+
c.appendChild(renderer.domElement);
41+
42+
// // set up the sphere vars
43+
var radius = 50,
44+
segments = 36,
45+
rings = 36;
46+
47+
// // create the sphere's material
48+
var sphereMaterial =
49+
new THREE.MeshLambertMaterial(
50+
{
51+
color: 0xFF5000
52+
});
53+
54+
// // create a new mesh with
55+
// // sphere geometry - we will cover
56+
// // the sphereMaterial next!
57+
var sphere = new THREE.Mesh(
58+
59+
new THREE.SphereGeometry(
60+
radius,
61+
segments,
62+
rings),
63+
64+
sphereMaterial);
65+
66+
// // add the sphere to the scene
67+
scene.add(sphere);
68+
69+
// // create a point light
70+
var pointLight =
71+
new THREE.PointLight(0xFFFFFF);
72+
73+
// set its position
74+
pointLight.position.x = 10;
75+
pointLight.position.y = 50;
76+
pointLight.position.z = 130;
77+
78+
// add to the scene
79+
scene.add(pointLight);
80+
81+
draw();
82+
}
83+
84+
function draw()
85+
{
86+
renderer.render(scene, camera);
87+
88+
requestAnimationFrame(draw);
89+
}

0 commit comments

Comments
 (0)