-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsurface.java
More file actions
41 lines (40 loc) · 1.27 KB
/
Copy pathsurface.java
File metadata and controls
41 lines (40 loc) · 1.27 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
public class surface extends immovableObj{
line l1;
public surface(double a, double b, double c)
{
super();
l1 = new line(a,b,c);
}
public surface(point p1, point p2)
{
super();
l1 = new line(p1,p2);
}
public void interactWith(sphere obj1)
{
if(this.l1.intersects(obj1.c))
{
double angle = this.l1.getAngle();
vector newVel = obj1.velocity.rotateBy(angle);
vector pos = new vector(obj1.c.center);
newVel.y = -1 * newVel.y;
if(this.l1.distanceToCircle(obj1.c) < obj1.c.radius && (Math.abs(obj1.velocity.x) < 1 || Math.abs(obj1.velocity.y) < 1))
{
pos.rotateBy(angle);
if(l1.a * obj1.c.center.x + l1.b * obj1.c.center.y + l1.c > 0)
{
pos.y += this.l1.distanceToCircle(obj1.c);
}
else{
pos.y -= this.l1.distanceToCircle(obj1.c);
}
pos.rotateBy(-1*angle);
}
obj1.velocity = newVel.rotateBy(-1 * angle);
obj1.c.center.set(pos);
}
else{
//System.out.println("--no collision");
}
}
}