11import { vec3 , vec4 } from "gl-matrix" ;
2+ import { Plane } from "@silwalanish/geometry" ;
3+ import { GameObject } from "@silwalanish/engine" ;
24import { BasicMaterial } from "@silwalanish/shader" ;
35import { GroundManager } from "@silwalanish/planet" ;
6+ import { PhysicsScene2D } from "@silwalanish/physics" ;
7+ import { Camera , MeshComponent , SceneNode } from "@silwalanish/scene" ;
48import {
59 CanvasSurface ,
610 Orthographic ,
711 Perspective ,
812 Renderer ,
913} from "@silwalanish/renderer" ;
10- import {
11- Camera ,
12- MeshComponent ,
13- SceneGraph ,
14- SceneNode ,
15- } from "@silwalanish/scene" ;
16- import { Plane } from "@silwalanish/geometry" ;
14+
1715import { Player } from "./player" ;
1816import { PlayerAction } from "./playercontrol" ;
1917
@@ -27,12 +25,12 @@ export class App {
2725 private _lastTime : number ;
2826 private _surface : CanvasSurface ;
2927 private _renderer : Renderer ;
30- private _scene : SceneGraph ;
28+ private _scene : PhysicsScene2D ;
3129 private _perspective : Perspective ;
3230 private _orthographic : Orthographic ;
3331 private _groundManager : GroundManager ;
34- private _camera : Camera ;
35- private _sky : SceneNode ;
32+ private _camera : Camera < any > ;
33+ private _sky : GameObject < any > ;
3634 private _player : Player ;
3735 private _domElement : HTMLDivElement ;
3836 private _speedLabel : HTMLLabelElement ;
@@ -46,13 +44,13 @@ export class App {
4644 } ) ;
4745 this . _renderer = new Renderer ( this . _surface ) ;
4846
49- this . _scene = new SceneGraph ( ) ;
47+ this . _scene = new PhysicsScene2D ( ) ;
5048 this . _perspective = new Perspective ( 90 , 1.33 , 0.01 , 1000 ) ;
51- this . _orthographic = new Orthographic ( - 50 , 50 , - 50 , 50 , 0.01 , 1000 ) ;
49+ this . _orthographic = new Orthographic ( - 50 , 50 , 0 , 100 , 0.01 , 1000 ) ;
5250 this . _camera = new Camera ( "activeCamera" ) ;
5351 this . _groundManager = new GroundManager ( this . _camera ) ;
5452 this . _sky = new SceneNode ( "sky" ) ;
55- this . _player = new Player ( this . _camera ) ;
53+ this . _player = new Player ( ) ;
5654
5755 this . _speedLabel = document . createElement ( "label" ) ;
5856
@@ -146,7 +144,7 @@ export class App {
146144 this . _scene . camera = this . _camera ;
147145
148146 this . _sky . mesh = new MeshComponent (
149- new Plane ( 150 , 100 ) ,
147+ new Plane ( 150 , 400 ) ,
150148 new BasicMaterial ( "skyMaterial" , vec4 . fromValues ( 0.5 , 0.7 , 1 , 1 ) )
151149 ) ;
152150 this . _sky . transform . Position = vec3 . fromValues ( 0 , 0 , - 20 ) ;
@@ -173,8 +171,17 @@ export class App {
173171 3 ,
174172 "0"
175173 ) ;
174+ this . _scene . physicsUpdate ( ) ;
175+
176176 this . _scene . update ( deltaTime ) ;
177177 this . _renderer . render ( this . _scene , this . _orthographic ) ;
178+
179+ this . _camera . transform . Position = vec3 . fromValues (
180+ this . _player . transform . getWorldPosition ( ) [ 0 ] ,
181+ this . _camera . transform . Position [ 1 ] ,
182+ this . _camera . transform . Position [ 2 ]
183+ ) ;
184+ this . _camera . lookAt ( vec3 . fromValues ( 0 , 0 , - 1 ) ) ;
178185 }
179186
180187 window . requestAnimationFrame ( ( ) => {
0 commit comments