AABB returns the minimum and maximum point for the given SpaceComponent. It hereby takes into account the rotation of the Component - it may very well be that the Minimum as given by engo.AABB, is smaller than the Position of the object (i.e. when rotated). This basically returns the "outer rectang
()
| 153 | // points, a minimum and a maximum, the "rectangle" resulting from this `AABB`, is not rotated in any way. However, |
| 154 | // depending on the rotation of the `SpaceComponent`, this `AABB` may be larger than the original `SpaceComponent`. |
| 155 | func (sc SpaceComponent) AABB() engo.AABB { |
| 156 | if sc.Rotation == 0 { |
| 157 | return engo.AABB{ |
| 158 | Min: sc.Position, |
| 159 | Max: engo.Point{X: sc.Position.X + sc.Width, Y: sc.Position.Y + sc.Height}, |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | corners := sc.Corners() |
| 164 | |
| 165 | var ( |
| 166 | xMin float32 = math.MaxFloat32 |
| 167 | xMax float32 = -math.MaxFloat32 |
| 168 | yMin float32 = math.MaxFloat32 |
| 169 | yMax float32 = -math.MaxFloat32 |
| 170 | ) |
| 171 | |
| 172 | for i := 0; i < 4; i++ { |
| 173 | if corners[i].X < xMin { |
| 174 | xMin = corners[i].X |
| 175 | } else if corners[i].X > xMax { |
| 176 | xMax = corners[i].X |
| 177 | } |
| 178 | if corners[i].Y < yMin { |
| 179 | yMin = corners[i].Y |
| 180 | } |
| 181 | if corners[i].Y > yMax { |
| 182 | yMax = corners[i].Y |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | return engo.AABB{Min: engo.Point{X: xMin, Y: yMin}, Max: engo.Point{X: xMax, Y: yMax}} |
| 187 | } |
| 188 | |
| 189 | // Corners returns the location of the four corners of the rectangular plane defined by the `SpaceComponent`, taking |
| 190 | // into account any possible rotation. |