feat: FINALLY FUCKING FIXED THE DAMN EDGES INTERESECTION PROBLEM.

This commit is contained in:
Andrey Parhomenko 2024-01-22 20:08:50 +03:00
parent 88c1aa9577
commit 86ae2fbde9
6 changed files with 16 additions and 12 deletions

View file

@ -29,8 +29,8 @@ func NewPlayer() *Player {
ret.Visible = true ret.Visible = true
ret.Layer = PlayerL ret.Layer = PlayerL
ret.Collidable = true //ret.Collidable = true
ret.Resolvable = true //ret.Resolvable = true
return ret return ret

View file

@ -17,7 +17,7 @@ func NewRect() *Rect {
} }
ret.Layer = RectL ret.Layer = RectL
ret.Visible = true ret.Visible = true
ret.Collidable = true //ret.Collidable = true
ret.Width = 100 ret.Width = 100
ret.Height = 200 ret.Height = 200

View file

@ -25,7 +25,7 @@ func NewTri() *Tri {
} }
ret.Color = gg.Rgba(1, 1, 0, 1) ret.Color = gg.Rgba(1, 1, 0, 1)
ret.Visible = true ret.Visible = true
ret.Collidable = true //ret.Collidable = true
ret.Type = gg.CollisionStaticPhysics ret.Type = gg.CollisionStaticPhysics
ret.Layer = TriangleL ret.Layer = TriangleL
//ret.Connect(player) //ret.Connect(player)
@ -43,7 +43,7 @@ func (t *Tri) Update(c *Context) {
//fmt.Println("edges:", tedges) //fmt.Println("edges:", tedges)
} }
col, hasCol := gg.Collide(t, rect) col, hasCol := gg.Collide(t, rect)
if hasCol{ if hasCol && len(col.Crosses) > 0 {
fmt.Println("col:", col) fmt.Println("col:", col)
} }
dt := c.Dt().Seconds() dt := c.Dt().Seconds()

View file

@ -32,8 +32,8 @@ func (l Edge) Line() Line {
k := (p0.Y - p1.Y) / (p0.X - p1.X) k := (p0.Y - p1.Y) / (p0.X - p1.X)
c := p0.Y - p0.X*k c := p0.Y - p0.X*k
if p0.X == p1.X { if p0.X == p1.X {
vertical = true
x = p0.X x = p0.X
vertical = true
} }
return Line{k, c, x, vertical} 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) yMax := Max(l[0].Y, l[1].Y)
yMin := Min(l[0].Y, l[1].Y) yMin := Min(l[0].Y, l[1].Y)
if !(xMin < p.X && p.X < xMax) || if !(xMin <= p.X && p.X <= xMax) ||
!(yMin < p.Y && p.Y < yMax) { !(yMin <= p.Y && p.Y <= yMax) {
return false return false
} }

11
line.go
View file

@ -20,6 +20,7 @@ func (l Line) ContainsPoint(p Point) bool {
return false return false
} }
//Println("points:", l, p, pc)
return Neq(pc.X, p.X) && Neq(pc.Y, p.Y) 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 return Point{}, false
} }
if l1.Vertical { switch {
case l1.Vertical :
x = l1.X x = l1.X
y = l2.K*x + l2.C y = l2.K*x + l2.C
} else if l2.Vertical { //Println("l1-vert:", x, y)
case l2.Vertical :
x = l2.X x = l2.X
y = l1.K*x + l1.C y = l1.K*x + l1.C
} else { //Println("l2-vert:", x, y)
default:
x = (l1.C - l2.C) / (l2.K - l1.K) x = (l1.C - l2.C) / (l2.K - l1.K)
y = l1.K*x + l1.C y = l1.K*x + l1.C
} }
//Println("in:", x, y)
return Point{x, y}, true return Point{x, y}, true
} }

View file

@ -43,7 +43,6 @@ func T() Transform {
scale: Vector{1, 1}, scale: Vector{1, 1},
// Rotate around the center. // Rotate around the center.
around: V(.5, .5), around: V(.5, .5),
rotation: EqualityThreshold,
} }
return ret return ret
} }