MCPcopy
hub / github.com/EngoEngine/engo / SetCenter

Method SetCenter

common/collision.go:117–131  ·  view source on GitHub ↗

SetCenter positions the space component according to its center instead of its top-left point (this avoids doing the same math each time in your systems)

(p engo.Point)

Source from the content-addressed store, hash-verified

115// SetCenter positions the space component according to its center instead of its
116// top-left point (this avoids doing the same math each time in your systems)
117func (sc *SpaceComponent) SetCenter(p engo.Point) {
118 xDelta := sc.Width / 2
119 yDelta := sc.Height / 2
120 // update position according to point being used as our center
121 if sc.Rotation == 0 {
122 sc.Position.X = p.X - xDelta
123 sc.Position.Y = p.Y - yDelta
124 return
125 }
126 sin, cos := math.Sincos(sc.Rotation * math.Pi / 180)
127 xDelta = (sc.Width*cos - sc.Height*sin) / 2
128 yDelta = (sc.Height*cos + sc.Width*sin) / 2
129 sc.Position.X = p.X - xDelta
130 sc.Position.Y = p.Y - yDelta
131}
132
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)

Callers 2

SetupMethod · 0.80

Calls 1

SincosFunction · 0.92

Tested by 1