1
1
import * as THREE from 'three' ;
2
2
3
+
3
4
export let renderer : THREE . WebGLRenderer ,
4
5
scene : THREE . Scene ,
5
6
camera : THREE . PerspectiveCamera ,
@@ -16,6 +17,9 @@ let graphicCanvas,
16
17
windowHalfHeight : number ,
17
18
cameraLookAt = new THREE . Vector3 ( 0 , 0 , 0 ) ;
18
19
20
+ const mouseSensitivity = 0.1 ;
21
+ const cameraTilt = 35 ;
22
+
19
23
//-----------------------------------------------------------------------
20
24
21
25
export const initStage = ( ) => {
@@ -27,6 +31,8 @@ export const initStage = () => {
27
31
28
32
export const initScene = ( ) => {
29
33
scene = new THREE . Scene ( ) ;
34
+ scene . fog = new THREE . Fog ( 0x010102 , 1 , 3000 ) ;
35
+
30
36
31
37
renderer = new THREE . WebGLRenderer ( {
32
38
alpha : true ,
@@ -41,7 +47,7 @@ export const initCamera = () => {
41
47
const fieldOfView = 75 ;
42
48
const aspectRatio = windowWidth / windowHeight ;
43
49
const nearPlane = 1 ;
44
- const farPlane = 3000 ;
50
+ const farPlane = 30000 ;
45
51
camera = new THREE . PerspectiveCamera (
46
52
fieldOfView ,
47
53
aspectRatio ,
@@ -67,6 +73,7 @@ export const animate = () => {
67
73
requestAnimationFrame ( animate ) ;
68
74
camera . position . lerp ( cameraTarget , 0.2 ) ;
69
75
camera . lookAt ( cameraLookAt ) ;
76
+
70
77
render ( ) ;
71
78
}
72
79
@@ -75,8 +82,13 @@ export const animate = () => {
75
82
const onMouseMove = ( event : MouseEvent ) => {
76
83
mouseX = ( event . clientX - windowHalfWidth ) ;
77
84
mouseY = ( event . clientY - windowHalfHeight ) ;
78
- cameraTarget . x = ( mouseX * - 1 ) / 2 ;
79
- cameraTarget . y = mouseY / 2 ;
85
+ cameraTarget . x = ( mouseX * - 1 ) * mouseSensitivity ;
86
+ cameraTarget . y = mouseY * mouseSensitivity ;
87
+
88
+ cameraTarget . clamp (
89
+ new THREE . Vector3 ( - cameraTilt , - cameraTilt , 800 ) ,
90
+ new THREE . Vector3 ( cameraTilt , cameraTilt , 800 )
91
+ ) ;
80
92
}
81
93
82
94
const onWindowResize = ( ) => {
@@ -87,6 +99,7 @@ const onWindowResize = () => {
87
99
renderer . setSize ( windowWidth , windowHeight ) ;
88
100
}
89
101
102
+
90
103
const render = ( ) => {
91
104
renderer . render ( scene , camera ) ;
92
105
}
0 commit comments