summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulie Lala <jules@okfoc.us>2014-11-03 01:20:37 -0500
committerJulie Lala <jules@okfoc.us>2014-11-03 01:20:37 -0500
commitb5c6adb5fbc7225e7b655f02123d7f0995ae3b46 (patch)
tree7642584c76fc858f3ed02b64799e43cc53122f29
parent17ed9ecb646ea063b1484c484877e11c42ebabb6 (diff)
extend vec in both directions
-rw-r--r--public/assets/javascripts/rectangles/models/wall.js28
-rw-r--r--public/assets/test/intersect3.html53
2 files changed, 48 insertions, 33 deletions
diff --git a/public/assets/javascripts/rectangles/models/wall.js b/public/assets/javascripts/rectangles/models/wall.js
index 8590de7..a026c3c 100644
--- a/public/assets/javascripts/rectangles/models/wall.js
+++ b/public/assets/javascripts/rectangles/models/wall.js
@@ -25,6 +25,34 @@
Wall.prototype.toString = function(){
return this.vec.toString()
}
+ Wall.prototype.get_points = function(wall_vec){
+ wall_vec = wall_vec || new Rect ()
+ if (this.side & LEFT) {
+ wall_vec.x.a = this.edge
+ wall_vec.x.b = this.vec.b
+ wall_vec.y.a = this.edge
+ wall_vec.y.b = this.vec.a
+ }
+ else if (this.side & RIGHT) {
+ wall_vec.x.a = this.edge
+ wall_vec.x.b = this.vec.a
+ wall_vec.y.a = this.edge
+ wall_vec.y.b = this.vec.b
+ }
+ else if (this.side & FRONT) {
+ wall_vec.x.a = this.vec.a
+ wall_vec.x.b = this.edge
+ wall_vec.y.a = this.vec.b
+ wall_vec.y.b = this.edge
+ }
+ else if (this.side & BACK) {
+ wall_vec.x.a = this.vec.b
+ wall_vec.x.b = this.edge
+ wall_vec.y.a = this.vec.a
+ wall_vec.y.b = this.edge
+ }
+ return wall_vec
+ }
Wall.prototype.reset = function(){
}
diff --git a/public/assets/test/intersect3.html b/public/assets/test/intersect3.html
index 040dca4..13a8024 100644
--- a/public/assets/test/intersect3.html
+++ b/public/assets/test/intersect3.html
@@ -101,7 +101,7 @@ var mymouse = new mouse({
},
})
-function draw () {
+function draw (time) {
ctx.fillStyle = "#fff"
ctx.fillRect(0,0,w,h)
@@ -115,36 +115,16 @@ function draw () {
drawLine(cursor.x, cursor.y, "#f00")
// hud.innerHTML = ""
- var closest_intersect, cursor_copy = new Rect(0,0,0,0), t, min_t = 1
- var cursor_copy = cursor.plus(scene.camera.radius)
+ var closest_intersect, t, min_t = 1
+ var cursor_copy = cursor.extend_ends(scene.camera.radius)
+hud.innerHTML = cursor_copy.x
+drawPoint(cursor_copy.x, "#ff0")
Walls.list.forEach(function(wall, i){
- if (wall.side & LEFT) {
- wall_vec.x.a = wall.edge
- wall_vec.x.b = wall.vec.b
- wall_vec.y.a = wall.edge
- wall_vec.y.b = wall.vec.a
- }
- else if (wall.side & RIGHT) {
- wall_vec.x.a = wall.edge
- wall_vec.x.b = wall.vec.a
- wall_vec.y.a = wall.edge
- wall_vec.y.b = wall.vec.b
- }
- else if (wall.side & FRONT) {
- wall_vec.x.a = wall.vec.a
- wall_vec.x.b = wall.edge
- wall_vec.y.a = wall.vec.b
- wall_vec.y.b = wall.edge
- }
- else if (wall.side & BACK) {
- wall_vec.x.a = wall.vec.b
- wall_vec.x.b = wall.edge
- wall_vec.y.a = wall.vec.a
- wall_vec.y.b = wall.edge
- }
+ wall.get_points(wall_vec)
drawLine(wall_vec.x, wall_vec.y, "#088")
+ origins.x = cursor_copy.x
t = perp(origins, wall_vec) / ( perp(cursor_copy, wall_vec) || 0.0000001 )
intersect.a = cursor_copy.x.a + ( cursor_copy.y.a - cursor_copy.x.a ) * t
intersect.b = cursor_copy.x.b + ( cursor_copy.y.b - cursor_copy.x.b ) * t
@@ -196,6 +176,7 @@ function draw () {
drawLine(wall_vec.x, wall_vec.y, "rgba(0,255,255,1.0)")
+ origins.x = cursor.x
var new_t = perp(origins, wall_vec) / ( perp(cursor, wall_vec) || 0.0000001 )
var wall_t = perp(origins, cursor) / ( perp(wall_vec, cursor) || 0.0000001 )
var closest_intersect2 = new vec2()
@@ -222,17 +203,21 @@ function draw () {
len = clamp(len, 0, (1-min_t) * sqrt(dot(cursor, cursor)))
- hud.innerHTML = [ aw ].map(function(n){ return round(deg(n)) })
- hud.innerHTML = "&nbsp;" + (dd > 0 ? "gt": "lt") + " " + round(len) + " " + (1-min_t) + " " + round((1-min_t)*sqrt(dot2(diff(cursor), diff(cursor))))
+// hud.innerHTML = [ aw ].map(function(n){ return round(deg(n)) })
+// hud.innerHTML = "&nbsp;" + (dd > 0 ? "gt": "lt") + " " + round(len) + " " + (1-min_t) + " " + round((1-min_t)*sqrt(dot2(diff(cursor), diff(cursor))))
var end_of_ray = closest_intersect2.clone()
end_of_ray.a += len * cos(aw)
end_of_ray.b += len * sin(aw)
+
+ end_of_ray.a = clamp(end_of_ray.a, wall_vec.x.a, wall_vec.y.a)
+ end_of_ray.b = clamp(end_of_ray.b, wall_vec.x.b, wall_vec.y.b)
+
drawPoint(end_of_ray)
drawLine(closest_intersect2, end_of_ray, "#00f")
}
else {
- hud.innerHTML = [ (angle(cursor) + TWO_PI) % TWO_PI ].map(function(n){ return round(deg(n)) })
+// hud.innerHTML = [ (angle(cursor) + TWO_PI) % TWO_PI ].map(function(n){ return round(deg(n)) })
}
}
@@ -294,17 +279,19 @@ function is_collinear (p, vec) {
return !! (on_x && on_y)
}
-cursor.plus = function(n){
+cursor.extend_ends = function(n){
var a = angle(this)
var clone = this.clone()
+ clone.x.a -= n*cos(a)
+ clone.x.b -= n*sin(a)
clone.y.a += n*cos(a)
clone.y.b += n*sin(a)
return clone
}
-function animate(){
+function animate(time){
requestAnimationFrame(animate)
- draw()
+ draw(time)
}
animate()