-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b6aa7f
commit ca65f5b
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,41 @@ | ||
import * as THREE from 'three'; | ||
|
||
class Renderer { | ||
constructor() { | ||
this.canvas = document.getElementById('gameCanvas'); | ||
this.scene = new THREE.Scene(); | ||
|
||
this.camera = new THREE.PerspectiveCamera( | ||
75, | ||
window.innerWidth / window.innerHeight, | ||
0.1, | ||
1000 | ||
); | ||
this.camera.position.z = 5; | ||
|
||
this.renderer = new THREE.WebGLRenderer({ canvas: this.canvas }); | ||
this.resize(); | ||
window.addEventListener('resize', () => this.resize()); | ||
|
||
// Add a basic cube to the scene | ||
const geometry = new THREE.BoxGeometry(); | ||
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 }); | ||
this.cube = new THREE.Mesh(geometry, material); | ||
this.scene.add(this.cube); | ||
} | ||
|
||
resize() { | ||
this.renderer.setSize(window.innerWidth, window.innerHeight); | ||
this.camera.aspect = window.innerWidth / window.innerHeight; | ||
this.camera.updateProjectionMatrix(); | ||
} | ||
|
||
render() { | ||
this.cube.rotation.x += 0.01; | ||
this.cube.rotation.y += 0.01; | ||
|
||
this.renderer.render(this.scene, this.camera); | ||
} | ||
} | ||
|
||
export default Renderer; |