| 155 | } |
| 156 | |
| 157 | void BoundingSphere::Merge(const BoundingSphere& value1, const BoundingSphere& value2, BoundingSphere& result) |
| 158 | { |
| 159 | // Pre-exit if one of the bounding sphere by assuming that a merge with an empty sphere is equivalent at taking the non-empty sphere |
| 160 | if (value1 == Empty) |
| 161 | { |
| 162 | result = value2; |
| 163 | return; |
| 164 | } |
| 165 | if (value2 == Empty) |
| 166 | { |
| 167 | result = value1; |
| 168 | return; |
| 169 | } |
| 170 | |
| 171 | const Vector3 difference = value2.Center - value1.Center; |
| 172 | const Real length = difference.Length(); |
| 173 | const Real radius = value1.Radius; |
| 174 | const Real radius2 = value2.Radius; |
| 175 | |
| 176 | if (radius + radius2 >= length) |
| 177 | { |
| 178 | if (radius - radius2 >= length) |
| 179 | { |
| 180 | result = value1; |
| 181 | return; |
| 182 | } |
| 183 | |
| 184 | if (radius2 - radius >= length) |
| 185 | { |
| 186 | result = value2; |
| 187 | return; |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | const Vector3 vector = difference * (1.0f / length); |
| 192 | const Real min = Math::Min(-radius, length - radius2); |
| 193 | const Real max = (Math::Max(radius, length + radius2) - min) * 0.5f; |
| 194 | |
| 195 | result.Center = value1.Center + vector * (max + min); |
| 196 | result.Radius = max; |
| 197 | } |
| 198 | |
| 199 | void BoundingSphere::Merge(const BoundingSphere& value1, const Vector3& value2, BoundingSphere& result) |
| 200 | { |
no test coverage detected