MCPcopy Index your code
hub / github.com/EngoEngine/engo / Center

Method Center

common/collision.go:135–146  ·  view source on GitHub ↗

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)

()

Source from the content-addressed store, hash-verified

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)
135func (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

Callers 3

SetupMethod · 0.80
UpdateMethod · 0.80

Calls 1

SincosFunction · 0.92

Tested by 1