From 86ae2fbde9b459b2df1cf4a23b37b6eb586a273e Mon Sep 17 00:00:00 2001 From: surdeus Date: Mon, 22 Jan 2024 20:08:50 +0300 Subject: [PATCH] feat: FINALLY FUCKING FIXED THE DAMN EDGES INTERESECTION PROBLEM. --- cmd/test/player.go | 4 ++-- cmd/test/rect.go | 2 +- cmd/test/trianlge.go | 4 ++-- edge.go | 6 +++--- line.go | 11 ++++++++--- transform.go | 1 - 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/cmd/test/player.go b/cmd/test/player.go index ba72227..ba77486 100644 --- a/cmd/test/player.go +++ b/cmd/test/player.go @@ -29,8 +29,8 @@ func NewPlayer() *Player { ret.Visible = true ret.Layer = PlayerL - ret.Collidable = true - ret.Resolvable = true + //ret.Collidable = true + //ret.Resolvable = true return ret diff --git a/cmd/test/rect.go b/cmd/test/rect.go index 8887222..7847847 100644 --- a/cmd/test/rect.go +++ b/cmd/test/rect.go @@ -17,7 +17,7 @@ func NewRect() *Rect { } ret.Layer = RectL ret.Visible = true - ret.Collidable = true + //ret.Collidable = true ret.Width = 100 ret.Height = 200 diff --git a/cmd/test/trianlge.go b/cmd/test/trianlge.go index 8f57ed8..3cf8cee 100644 --- a/cmd/test/trianlge.go +++ b/cmd/test/trianlge.go @@ -25,7 +25,7 @@ func NewTri() *Tri { } ret.Color = gg.Rgba(1, 1, 0, 1) ret.Visible = true - ret.Collidable = true + //ret.Collidable = true ret.Type = gg.CollisionStaticPhysics ret.Layer = TriangleL //ret.Connect(player) @@ -43,7 +43,7 @@ func (t *Tri) Update(c *Context) { //fmt.Println("edges:", tedges) } col, hasCol := gg.Collide(t, rect) - if hasCol{ + if hasCol && len(col.Crosses) > 0 { fmt.Println("col:", col) } dt := c.Dt().Seconds() diff --git a/edge.go b/edge.go index 253a15e..fafa892 100644 --- a/edge.go +++ b/edge.go @@ -32,8 +32,8 @@ func (l Edge) Line() Line { k := (p0.Y - p1.Y) / (p0.X - p1.X) c := p0.Y - p0.X*k if p0.X == p1.X { - vertical = true x = p0.X + vertical = true } return Line{k, c, x, vertical} @@ -62,8 +62,8 @@ func (l Edge) ContainsPoint(p Point) bool { yMax := Max(l[0].Y, l[1].Y) yMin := Min(l[0].Y, l[1].Y) - if !(xMin < p.X && p.X < xMax) || - !(yMin < p.Y && p.Y < yMax) { + if !(xMin <= p.X && p.X <= xMax) || + !(yMin <= p.Y && p.Y <= yMax) { return false } diff --git a/line.go b/line.go index b2a08ce..81c3acd 100644 --- a/line.go +++ b/line.go @@ -20,6 +20,7 @@ func (l Line) ContainsPoint(p Point) bool { return false } + //Println("points:", l, p, pc) return Neq(pc.X, p.X) && Neq(pc.Y, p.Y) } @@ -29,17 +30,21 @@ func (l1 Line) crossesLine(l2 Line) (Point, bool) { return Point{}, false } - if l1.Vertical { + switch { + case l1.Vertical : x = l1.X y = l2.K*x + l2.C - } else if l2.Vertical { + //Println("l1-vert:", x, y) + case l2.Vertical : x = l2.X y = l1.K*x + l1.C - } else { + //Println("l2-vert:", x, y) + default: x = (l1.C - l2.C) / (l2.K - l1.K) y = l1.K*x + l1.C } + //Println("in:", x, y) return Point{x, y}, true } diff --git a/transform.go b/transform.go index 8b25878..790845d 100644 --- a/transform.go +++ b/transform.go @@ -43,7 +43,6 @@ func T() Transform { scale: Vector{1, 1}, // Rotate around the center. around: V(.5, .5), - rotation: EqualityThreshold, } return ret }