MCPcopy Create free account
hub / github.com/ByteArena/box2d / ReadCache

Method ReadCache

CollisionB2Distance.go:253–295  ·  view source on GitHub ↗
(cache *B2SimplexCache, proxyA *B2DistanceProxy, transformA B2Transform, proxyB *B2DistanceProxy, transformB B2Transform)

Source from the content-addressed store, hash-verified

251}
252
253func (simplex *B2Simplex) ReadCache(cache *B2SimplexCache, proxyA *B2DistanceProxy, transformA B2Transform, proxyB *B2DistanceProxy, transformB B2Transform) {
254 B2Assert(cache.Count <= 3)
255
256 // Copy data from cache.
257 simplex.M_count = cache.Count
258 vertices := &simplex.M_vs
259 for i := 0; i < simplex.M_count; i++ {
260 v := &vertices[i]
261 v.IndexA = cache.IndexA[i]
262 v.IndexB = cache.IndexB[i]
263 wALocal := proxyA.GetVertex(v.IndexA)
264 wBLocal := proxyB.GetVertex(v.IndexB)
265 v.WA = B2TransformVec2Mul(transformA, wALocal)
266 v.WB = B2TransformVec2Mul(transformB, wBLocal)
267 v.W = B2Vec2Sub(v.WB, v.WA)
268 v.A = 0.0
269 }
270
271 // Compute the new simplex metric, if it is substantially different than
272 // old metric then flush the simplex.
273 if simplex.M_count > 1 {
274 metric1 := cache.Metric
275 metric2 := simplex.GetMetric()
276 if metric2 < 0.5*metric1 || 2.0*metric1 < metric2 || metric2 < B2_epsilon {
277 // Reset the simplex.
278 simplex.M_count = 0
279 }
280 }
281
282 // If the cache is empty or invalid ...
283 if simplex.M_count == 0 {
284 v := &vertices[0]
285 v.IndexA = 0
286 v.IndexB = 0
287 wALocal := proxyA.GetVertex(0)
288 wBLocal := proxyB.GetVertex(0)
289 v.WA = B2TransformVec2Mul(transformA, wALocal)
290 v.WB = B2TransformVec2Mul(transformB, wBLocal)
291 v.W = B2Vec2Sub(v.WB, v.WA)
292 v.A = 1.0
293 simplex.M_count = 1
294 }
295}
296
297func (simplex B2Simplex) WriteCache(cache *B2SimplexCache) {
298 cache.Metric = simplex.GetMetric()

Callers 1

B2DistanceFunction · 0.80

Calls 5

GetMetricMethod · 0.95
B2AssertFunction · 0.85
B2TransformVec2MulFunction · 0.85
B2Vec2SubFunction · 0.85
GetVertexMethod · 0.80

Tested by

no test coverage detected