@@ -14,7 +14,7 @@ export default class Solver {
14
14
return Solver . instance ;
15
15
}
16
16
17
- public solve ( spheres : THREE . Mesh [ ] , simulationArea : number , e : number ) : void {
17
+ public solve ( spheres : THREE . Mesh [ ] , bouns : 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,29 @@ export default class Solver {
36
36
37
37
sphere . position . add ( sphere . userData . velocity . clone ( ) . multiplyScalar ( this . deltaT ) ) ;
38
38
39
- if ( sphere . position . x + sphere . userData . radius > simulationArea ) {
40
- sphere . position . x = simulationArea - sphere . userData . radius ;
41
- sphere . userData . velocity . x *= 0.8 ;
42
- } else if ( sphere . position . x - sphere . userData . radius < - simulationArea ) {
43
- sphere . position . x = - simulationArea + sphere . userData . radius ;
44
- sphere . userData . velocity . x *= 0.8 ;
39
+ let wallBounceE : number = 0.8 ;
40
+ if ( sphere . position . x + sphere . userData . radius > bouns ) {
41
+ sphere . position . x = bouns - sphere . userData . radius ;
42
+ sphere . userData . velocity . x *= wallBounceE ;
43
+ } else if ( sphere . position . x - sphere . userData . radius < - bouns ) {
44
+ sphere . position . x = - bouns + sphere . userData . radius ;
45
+ sphere . userData . velocity . x *= wallBounceE ;
45
46
}
46
47
47
- if ( sphere . position . y + sphere . userData . radius > simulationArea ) {
48
- sphere . position . y = simulationArea - sphere . userData . radius ;
49
- sphere . userData . velocity . y *= 0.8 ;
50
- } else if ( sphere . position . y - sphere . userData . radius < - simulationArea ) {
51
- sphere . position . y = - simulationArea + sphere . userData . radius ;
52
- sphere . userData . velocity . y *= 0.8 ;
48
+ if ( sphere . position . y + sphere . userData . radius > bouns ) {
49
+ sphere . position . y = bouns - sphere . userData . radius ;
50
+ sphere . userData . velocity . y *= wallBounceE ;
51
+ } else if ( sphere . position . y - sphere . userData . radius < - bouns ) {
52
+ sphere . position . y = - bouns + sphere . userData . radius ;
53
+ sphere . userData . velocity . y *= wallBounceE ;
53
54
}
54
55
55
- if ( sphere . position . z + sphere . userData . radius > simulationArea ) {
56
- sphere . position . z = simulationArea - sphere . userData . radius ;
57
- sphere . userData . velocity . z *= 0.8 ;
58
- } else if ( sphere . position . z - sphere . userData . radius < - simulationArea ) {
59
- sphere . position . z = - simulationArea + sphere . userData . radius ;
60
- sphere . userData . velocity . z *= 0.8 ;
56
+ if ( sphere . position . z + sphere . userData . radius > bouns ) {
57
+ sphere . position . z = bouns - sphere . userData . radius ;
58
+ sphere . userData . velocity . z *= wallBounceE ;
59
+ } else if ( sphere . position . z - sphere . userData . radius < - bouns ) {
60
+ sphere . position . z = - bouns + sphere . userData . radius ;
61
+ sphere . userData . velocity . z *= wallBounceE ;
61
62
}
62
63
63
64
let maxVel = 2.5 ;
0 commit comments