-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
94 lines (72 loc) · 2.74 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
import Game from './game.js'
import Cube from './cube.js'
import * as util from './utils.js';
import { Vector4, Vector3, Vector2 } from './math3d.js';
import Entity from './entity.js';
import Colors from './colors.js'
import Light from './light.js'
import { Camera } from './camera.js'
// init resizing canvas
window.onload = function (){
main();
};
function main()
{
const camera = new Camera(new Vector3(-15.5, 8, 17), 0, -45)
const game = new Game('my-canvas', camera);
window.game = game
const test = new Entity('monkey.obj', new Vector3(0, 5, 0), Colors.WHITE);
const cube = new Entity('cube.obj', new Vector3(0, 1, 0), Colors.RED);
const obj = new Entity('exampleOBJ.obj', new Vector3(0, 0, -10), Colors.PURPLE);
const obj2 = new Entity('lamp.obj', new Vector3(-2, 0, -5), Colors.YELLOW);
const obj3 = new Entity('lowPolyTree.obj', new Vector3(6, 0, -7), Colors.GREEN);
const obj4 = new Entity('pine.obj', new Vector3(-7, 0, -7), Colors.GREEN);
const obj5 = new Entity('stall.obj', new Vector3(10, 0, 0), Colors.BLUE);
const plane = new Entity('plane4.obj', new Vector3(1, 0, 1), Colors.BLUE);
const obj6 = new Entity('box.obj', new Vector3(3, 1, 5), Colors.WHITE);
const light = new Light(new Vector3(1, -1, 0), new Vector3(1, 2, 1), Colors.ORANGE)
game.world.setLight(light);
//game.world.drawable.push(light);
//game.world.updateable.push(light);
game.world.drawable.push(cube);
game.world.updateable.push(cube);
game.world.drawable.push(plane)
game.world.updateable.push(plane)
obj.rotate(-130, new Vector3(0, 1, 0))
game.world.drawable.push(obj);
game.world.updateable.push(obj);
game.world.drawable.push(obj2);
game.world.updateable.push(obj2);
game.world.drawable.push(obj3);
game.world.updateable.push(obj3);
game.world.drawable.push(obj4);
game.world.updateable.push(obj4);
game.world.drawable.push(obj6);
game.world.updateable.push(obj6);
//test.setScale(0.2)
//test.rotate(-90, new Vector3(1, 0, 0))
game.world.drawable.push(test);
game.world.updateable.push(test);
obj5.rotate(90, new Vector3(0, 1, 0))
game.world.drawable.push(obj5);
game.world.updateable.push(obj5);
let angleSpeed = 15; // 30 degrees per second
let totalAngle = 10;
game.loop(function (){
this.update();
totalAngle = (angleSpeed * this.timestamp);
//test.rotate(totalAngle, new Vector3(0, 0, 1));
test.rotate(totalAngle, new Vector3(0, 1, 0));
//cube.rotate(totalAngle, new Vector3(0, 1, 0));
light.rotate(totalAngle, new Vector3(0, 1, 0));
this.draw();
//this.stop();
});
/* function init()
{
let center = new Vertex(canvas.width / 2, canvas.height / 2);
ctx.translate(canvas.width / 2, canvas.height / 2);
canvas.width = document.documentElement.clientWidth;
canvas.height = document.documentElement.clientHeight;
} */
}