1
1
import * as THREE from 'three' ;
2
2
3
3
export default class Solver {
4
- static instance : Solver ;
4
+ private static instance : Solver ;
5
5
private readonly G : number = 1 ;
6
6
private readonly softening : number = 0.1 ;
7
7
private deltaT : number = 0.1 ;
@@ -14,7 +14,7 @@ export default class Solver {
14
14
return Solver . instance ;
15
15
}
16
16
17
- public solve ( spheres : THREE . Mesh [ ] , bouns : number , e : number ) : void {
17
+ public solve ( spheres : THREE . Mesh [ ] , bounds : number , e : number ) : void {
18
18
spheres . forEach ( ( sphere ) => {
19
19
let objectAcceleration = new THREE . Vector3 ( 0 , 0 , 0 ) ;
20
20
spheres . forEach ( ( other ) => {
@@ -36,28 +36,28 @@ export default class Solver {
36
36
37
37
sphere . position . add ( sphere . userData . velocity . clone ( ) . multiplyScalar ( this . deltaT ) ) ;
38
38
39
- let wallBounceE : number = 0.8 ;
40
- if ( sphere . position . x + sphere . userData . radius > bouns ) {
41
- sphere . position . x = bouns - sphere . userData . radius ;
39
+ let wallBounceE : number = 1.2 ;
40
+ if ( sphere . position . x + sphere . userData . radius > bounds ) {
41
+ sphere . position . x = bounds - sphere . userData . radius ;
42
42
sphere . userData . velocity . x *= wallBounceE ;
43
- } else if ( sphere . position . x - sphere . userData . radius < - bouns ) {
44
- sphere . position . x = - bouns + sphere . userData . radius ;
43
+ } else if ( sphere . position . x - sphere . userData . radius < - bounds ) {
44
+ sphere . position . x = - bounds + sphere . userData . radius ;
45
45
sphere . userData . velocity . x *= wallBounceE ;
46
46
}
47
47
48
- if ( sphere . position . y + sphere . userData . radius > bouns ) {
49
- sphere . position . y = bouns - sphere . userData . radius ;
48
+ if ( sphere . position . y + sphere . userData . radius > bounds ) {
49
+ sphere . position . y = bounds - sphere . userData . radius ;
50
50
sphere . userData . velocity . y *= wallBounceE ;
51
- } else if ( sphere . position . y - sphere . userData . radius < - bouns ) {
52
- sphere . position . y = - bouns + sphere . userData . radius ;
51
+ } else if ( sphere . position . y - sphere . userData . radius < - bounds ) {
52
+ sphere . position . y = - bounds + sphere . userData . radius ;
53
53
sphere . userData . velocity . y *= wallBounceE ;
54
54
}
55
55
56
- if ( sphere . position . z + sphere . userData . radius > bouns ) {
57
- sphere . position . z = bouns - sphere . userData . radius ;
56
+ if ( sphere . position . z + sphere . userData . radius > bounds ) {
57
+ sphere . position . z = bounds - sphere . userData . radius ;
58
58
sphere . userData . velocity . z *= wallBounceE ;
59
- } else if ( sphere . position . z - sphere . userData . radius < - bouns ) {
60
- sphere . position . z = - bouns + sphere . userData . radius ;
59
+ } else if ( sphere . position . z - sphere . userData . radius < - bounds ) {
60
+ sphere . position . z = - bounds + sphere . userData . radius ;
61
61
sphere . userData . velocity . z *= wallBounceE ;
62
62
}
63
63
0 commit comments