-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollision.java
More file actions
59 lines (47 loc) · 1.13 KB
/
Collision.java
File metadata and controls
59 lines (47 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
*
* @author Alex Weeks
*
*/
public class Collision {
public double deltaT;
public final Ball ball1;
public final Ball ball2;
public final boolean isWallCollision;
public final int wallCompIndex;
/**
* Creates a new ball-to-ball collision object
* @param actor1 The first ball
* @param actor2 The second ball
* @param deltaT Time to the collision
*/
public Collision(Ball actor1, Ball actor2, double deltaT) {
this.ball1 = actor1;
this.ball2 = actor2;
this.deltaT = deltaT;
this.isWallCollision = false;
this.wallCompIndex = 0;
}
/**
* Creates a new wall collision object
* @param ball The ball
* @param deltaT Time to the collision
* @param wallCompIndex Direction of collision
*/
public Collision( Ball ball, double deltaT, int wallCompIndex ) {
this.ball1 = ball;
this.ball2 = null;
this.deltaT = deltaT;
this.isWallCollision = true;
this.wallCompIndex = wallCompIndex;
}
/**
* Performs the collision
*/
public void doCollision() {
if( this.isWallCollision ) {
Physics.doWallCollision(ball1, wallCompIndex);
}
else Physics.doElasticCollision( ball1, ball2 );
}
}