...
This commit is contained in:
parent
3807fc4bc2
commit
506e2772f7
6 changed files with 62 additions and 25 deletions
|
@ -53,13 +53,14 @@ func NewRect() *Rect {
|
|||
}
|
||||
|
||||
func (r *Rect) Update(e *gx.Engine) error {
|
||||
r.R += 0.3 * e.DT()
|
||||
//r.R += 0.3 * e.DT()
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
playerImg *gx.Image
|
||||
player *Player
|
||||
rectMove gx.Rectangle
|
||||
rect *Rect
|
||||
)
|
||||
|
||||
|
@ -90,10 +91,11 @@ func (p *Player) Draw(e *gx.Engine, i *gx.Image) {
|
|||
t := p.Transform
|
||||
t.S.X *= 4.
|
||||
t.S.Y *= 4.
|
||||
rectMove = gx.Rectangle{
|
||||
Transform: t,
|
||||
}
|
||||
r := &gx.DrawableRectangle{
|
||||
Rectangle: gx.Rectangle{
|
||||
Transform: t,
|
||||
},
|
||||
Rectangle: rectMove,
|
||||
Color: gx.Color{0, 0, gx.MaxColorV, gx.MaxColorV},
|
||||
}
|
||||
r.Draw(e, i)
|
||||
|
@ -184,7 +186,7 @@ func (d *Debug) Draw(
|
|||
keyStrs = append(keyStrs, k.String())
|
||||
}
|
||||
|
||||
if rect.ContainsPoint(player.P) {
|
||||
if rectMove.Vertices().Contained(rect).Len() > 0 {
|
||||
keyStrs = append(keyStrs, "THIS IS SHIT")
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
package gx
|
||||
|
||||
// The structure represents any circles.
|
||||
type Circle struct {
|
||||
Transform
|
||||
}
|
||||
|
||||
|
13
src/gx/elipse.go
Normal file
13
src/gx/elipse.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
package gx
|
||||
|
||||
// The structure represents elipses.
|
||||
type Elipse struct {
|
||||
// In transform S.X and S.Y represent
|
||||
// coefficents for the corresponding axises.
|
||||
Transform
|
||||
}
|
||||
|
||||
func (e Elipse) ContainsPoint(p Point) bool {
|
||||
return true
|
||||
}
|
||||
|
|
@ -16,6 +16,9 @@ type Liner interface {
|
|||
// The type represents a line segment.
|
||||
type LineSegment [2]Point
|
||||
|
||||
// The type represents multiple line segments.
|
||||
type LineSegments []LineSegment
|
||||
|
||||
// Check whether the liner is parallel to the line.
|
||||
func (l Line) Parallel(liner Liner) bool {
|
||||
buf := liner.Line()
|
||||
|
|
|
@ -9,9 +9,7 @@ import (
|
|||
|
||||
// The type describes rectangle geometry.
|
||||
type Rectangle struct {
|
||||
// Position of up left corner
|
||||
// and the point to
|
||||
// rotate around(relatively of position, not absolute).
|
||||
// P - position of the rotating center.
|
||||
// Scale represent width and height.
|
||||
Transform
|
||||
}
|
||||
|
@ -30,20 +28,27 @@ type DrawableRectangle struct {
|
|||
Visible bool
|
||||
}
|
||||
|
||||
// Return points of corners of the rectangle.
|
||||
func (r Rectangle) Corners() []Point {
|
||||
return []Point{}
|
||||
}
|
||||
|
||||
// Get 2 triangles that the rectangle consists of.
|
||||
func (r Rectangle) Triangles() Triangles {
|
||||
// Return points of vertices of the rectangle.
|
||||
func (r Rectangle) Vertices() Points {
|
||||
m := r.Matrix()
|
||||
|
||||
p1 := V(0, 0).Apply(&m)
|
||||
p2 := V(1, 0).Apply(&m)
|
||||
p3 := V(1, 1).Apply(&m)
|
||||
p4 := V(0, 1).Apply(&m)
|
||||
return Points{p1, p2, p3, p4}
|
||||
}
|
||||
|
||||
func (r Rectangle) Edges() LineSegments {
|
||||
return LineSegments{}
|
||||
}
|
||||
|
||||
// Get 2 triangles that the rectangle consists of.
|
||||
func (r Rectangle) Triangles() Triangles {
|
||||
pts := r.Vertices()
|
||||
p1 := pts[0]
|
||||
p2 := pts[1]
|
||||
p3 := pts[2]
|
||||
p4 := pts[3]
|
||||
//fmt.Println("in:", p1, p2, p3, p4)
|
||||
|
||||
return Triangles{
|
||||
|
|
|
@ -11,6 +11,11 @@ type Vector struct {
|
|||
type Point = Vector
|
||||
|
||||
type Vectors []Vector
|
||||
type Points []Point
|
||||
|
||||
type PointContainer interface {
|
||||
ContainsPoint(Point) bool
|
||||
}
|
||||
|
||||
func V(x, y Float) Vector {
|
||||
return Vector{x, y}
|
||||
|
@ -62,3 +67,20 @@ func (v Vector) Norm() Vector {
|
|||
l := math.Sqrt(v.X*v.X + v.Y*v.Y)
|
||||
return V(v.X / l, v.Y / l)
|
||||
}
|
||||
|
||||
func (pts Points) Contained(c PointContainer) Points {
|
||||
ret := Points{}
|
||||
|
||||
for _, pt := range pts {
|
||||
if c.ContainsPoint(pt) {
|
||||
ret = append(ret, pt)
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (pts Points) Len() int {
|
||||
return len(pts)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue