-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
93 lines (80 loc) · 3.34 KB
/
main.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
require([
'goo/entities/EntityUtils',
'goo/entities/GooRunner',
'goo/renderer/Camera',
'goo/renderer/Material',
'goo/renderer/TextureCreator',
'goo/renderer/light/PointLight',
'goo/renderer/shaders/ShaderLib',
'goo/scripts/OrbitCamControlScript',
'goo/shapes/ShapeCreator'
], function (
EntityUtils,
GooRunner,
Camera,
Material,
TextureCreator,
PointLight,
ShaderLib,
OrbitCamControlScript,
ShapeCreator
) {
"use strict";
var goo = new GooRunner();
document.getElementById("game-frame").appendChild(goo.renderer.domElement);
var tc = new TextureCreator()
var sunTex = tc.loadTexture2D('sun.png');
var earthTex = tc.loadTexture2D('earth.jpg');
var moonTex = tc.loadTexture2D('moon.jpg');
var borgTex = tc.loadTexture2D('borg.jpg');
function createAstronomicalObject(radius, texture) {
var meshData = ShapeCreator.createSphere(24, 24, radius);
var material = Material.createMaterial(ShaderLib.uber);
material.setTexture('DIFFUSE_MAP', texture);
var entity = EntityUtils.createTypicalEntity(goo.world, meshData, material, {
run: function (entity) {
entity.transformComponent.setRotation( 0, goo.world.time * 0.5, 0);
}
});
entity.addToWorld();
return entity;
}
function createHostileObject(width, height, length, texture) {
var meshData = ShapeCreator.createBox(width, height, length, 1, 1);
var material = Material.createMaterial(ShaderLib.uber);
material.setTexture('DIFFUSE_MAP', texture);
var entityBox = EntityUtils.createTypicalEntity(goo.world, meshData, material, {
run: function (entityBox) {
entityBox.transformComponent.setRotation( 0, goo.world.time * 0.8, 0);
}
});
entityBox.addToWorld();
return entityBox;
}
var sun = createAstronomicalObject(1, sunTex);
sun.meshRendererComponent.materials[0].uniforms.materialAmbient = [1,1,0.3,1];
var earth = createAstronomicalObject(0.5, earthTex);
earth.transformComponent.setTranslation( 5, 0, 0);
earth.meshRendererComponent.materials[0].uniforms.materialAmbient = [1,1,1,1];
sun.transformComponent.attachChild( earth.transformComponent);
var moon = createAstronomicalObject(0.15, moonTex);
moon.transformComponent.setTranslation( 1.4, 0, 0);
moon.meshRendererComponent.materials[0].uniforms.materialAmbient = [1,1,1,1];
earth.transformComponent.attachChild( moon.transformComponent);
/* Saturn should be added here*/
var saturn = createAstronomicalObject(0.7, sunTex);
saturn.transformComponent.setTranslation( 2.4, 2.4, 0);
saturn.meshRendererComponent.materials[0].uniforms.materialAmbient = [1,1,1,1];
sun.transformComponent.attachChild( saturn.transformComponent);
var borg = createHostileObject(0.4, 0.4, 0.4, borgTex);
borg.transformComponent.setTranslation( 2, 0, 0);
borg.meshRendererComponent.materials[0].uniforms.materialAmbient = [1,1,1,1];
moon.transformComponent.attachChild( borg.transformComponent);
var light = new PointLight();
light.color.set( 1,1,0);
var lightEntity = EntityUtils.createTypicalEntity( goo.world, light);
lightEntity.addToWorld();
var camera = new Camera(20, 1, 0.1, 1000);
var cameraEntity = EntityUtils.createTypicalEntity(goo.world, camera, new OrbitCamControlScript(), [0,0,5]);
cameraEntity.addToWorld();
});