-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathray.pde
More file actions
56 lines (47 loc) · 1.15 KB
/
Copy pathray.pde
File metadata and controls
56 lines (47 loc) · 1.15 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
class ray {
PVector pos = new PVector (0, 0);
PVector dir;
float mag = 10;
ray(float x, float y, float a) {
pos.x = x;
pos.y = y;
dir = PVector.fromAngle(a);
dir.setMag(mag);
}
void update(float x, float y) {
pos.set(x, y);
}
void show() {
push();
stroke(255);
//translate(pos.x, pos.y);
ellipse(pos.x, pos.y, 16,16);
pop();
}
void collideWall() {
PVector intPoint = null;
float intPointx;
float intPointy;
float x1 = b.a.x;
float y1 = b.a.y;
float x2 = b.b.x;
float y2 = b.b.y;
float x3 = pos.x;
float y3 = pos.y;
float x4 = pos.x + dir.x;
float y4 = pos.y + dir.y;
float den = ((x1 - x2) * (y3 - y4)) - ((y1 - y2) * (x3 - x4));
float t = (((x1 -x3) * (y3-y4)) - ((y1 - y3) * (x3 - x4)))/den;
float u = -(((x1-x2) * (y1-y3)) - ((y1 - y2) * (x1 - x3)))/den;
if (t >= 0 && t <= 1 && u <= 1) {
intPointx = x1 + t * (x2 - x1);
intPointy = y1 + t * (y2 - y1);
intPoint = new PVector (intPointx, intPointy);
}
if (intPoint != null) {
stroke(255);
line(pos.x,pos.y,intPoint.x,intPoint.y);
} else {
}
}
}