File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ import * as THREE from 'three' ;
12
3+ class Renderer {
4+ constructor ( ) {
5+ this . canvas = document . getElementById ( 'gameCanvas' ) ;
6+ this . scene = new THREE . Scene ( ) ;
7+
8+ this . camera = new THREE . PerspectiveCamera (
9+ 75 ,
10+ window . innerWidth / window . innerHeight ,
11+ 0.1 ,
12+ 1000
13+ ) ;
14+ this . camera . position . z = 5 ;
15+
16+ this . renderer = new THREE . WebGLRenderer ( { canvas : this . canvas } ) ;
17+ this . resize ( ) ;
18+ window . addEventListener ( 'resize' , ( ) => this . resize ( ) ) ;
19+
20+ // Add a basic cube to the scene
21+ const geometry = new THREE . BoxGeometry ( ) ;
22+ const material = new THREE . MeshBasicMaterial ( { color : 0x00ff00 } ) ;
23+ this . cube = new THREE . Mesh ( geometry , material ) ;
24+ this . scene . add ( this . cube ) ;
25+ }
26+
27+ resize ( ) {
28+ this . renderer . setSize ( window . innerWidth , window . innerHeight ) ;
29+ this . camera . aspect = window . innerWidth / window . innerHeight ;
30+ this . camera . updateProjectionMatrix ( ) ;
31+ }
32+
33+ render ( ) {
34+ this . cube . rotation . x += 0.01 ;
35+ this . cube . rotation . y += 0.01 ;
36+
37+ this . renderer . render ( this . scene , this . camera ) ;
38+ }
39+ }
40+
41+ export default Renderer ;
You can’t perform that action at this time.
0 commit comments