Center gets the center position of the space component instead of its top-left point (this avoids doing the same math each time in your systems)
()
| 133 | // Center gets the center position of the space component instead of its |
| 134 | // top-left point (this avoids doing the same math each time in your systems) |
| 135 | func (sc *SpaceComponent) Center() engo.Point { |
| 136 | xDelta := sc.Width / 2 |
| 137 | yDelta := sc.Height / 2 |
| 138 | p := sc.Position |
| 139 | if sc.Rotation == 0 { |
| 140 | return engo.Point{X: p.X + xDelta, Y: p.Y + yDelta} |
| 141 | } |
| 142 | sin, cos := math.Sincos(sc.Rotation * math.Pi / 180) |
| 143 | xDelta = (sc.Width*cos - sc.Height*sin) / 2 |
| 144 | yDelta = (sc.Height*cos + sc.Width*sin) / 2 |
| 145 | return engo.Point{X: p.X + xDelta, Y: p.Y + yDelta} |
| 146 | } |
| 147 | |
| 148 | // AABB returns the minimum and maximum point for the given SpaceComponent. It hereby takes into account the |
| 149 | // rotation of the Component - it may very well be that the Minimum as given by engo.AABB, is smaller than the Position |