-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworld.js
60 lines (52 loc) · 1.61 KB
/
world.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
import { Camera } from "./camera.js";
import Vector4, { Vector3 } from "./math3d.js";
import * as util from './utils.js';
import * as Math3d from "./math3d.js";
import Configs from "./configs.js";
export default class World
{
constructor(game, camera)
{
this.updateable = [];
this.drawable = [];
this.game = game;
this.camera = camera;
this.polygonsList = [];
this.projectionMatrix = null
this.lights = []
this.init();
}
init()
{
this.updateable.push(this.camera);
//this.initZbuffer();
}
setLight(light)
{
this.lights.push(light)
this.updateable.push(light)
this.drawable.push(light)
}
update()
{
// convert objs coordinates to the world space.
this.updateable.map(obj => {
obj.update(this.game);
})
}
draw()
{
//this.projectionMatrix = Math3d.perspective(Math3d.radians(this.camera.fov), this.game.canvas.width / this.game.canvas.height, this.game.world.camera.near, this.game.world.camera.far);
// fov in degeis
this.projectionMatrix = Math3d.makeFrustum(this.camera.fov, this.game.canvas.height / this.game.canvas.width, this.game.world.camera.near, this.game.world.camera.far);
this.drawable.map(obj => {
if (obj.mesh.found)
{
obj.draw(this.game);
//this.game.render.renderEntity(obj)
//this.polygonsList = this.polygonsList.concat(obj.getPolygons());
}
});
this.game.render.renderWorld(this.drawable)
}
}