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

Method CreateLoop

CollisionB2ShapeChain.go:56–81  ·  view source on GitHub ↗
(vertices []B2Vec2, count int)

Source from the content-addressed store, hash-verified

54}
55
56func (chain *B2ChainShape) CreateLoop(vertices []B2Vec2, count int) {
57 B2Assert(chain.M_vertices == nil && chain.M_count == 0)
58 B2Assert(count >= 3)
59 if count < 3 {
60 return
61 }
62
63 for i := 1; i < count; i++ {
64 v1 := vertices[i-1]
65 v2 := vertices[i]
66 // If the code crashes here, it means your vertices are too close together.
67 B2Assert(B2Vec2DistanceSquared(v1, v2) > B2_linearSlop*B2_linearSlop)
68 }
69
70 chain.M_count = count + 1
71 chain.M_vertices = make([]B2Vec2, chain.M_count)
72 for i, vertice := range vertices {
73 chain.M_vertices[i] = vertice
74 }
75
76 chain.M_vertices[count] = chain.M_vertices[0]
77 chain.M_prevVertex = chain.M_vertices[chain.M_count-2]
78 chain.M_nextVertex = chain.M_vertices[1]
79 chain.M_hasPrevVertex = true
80 chain.M_hasNextVertex = true
81}
82
83func (chain *B2ChainShape) CreateChain(vertices []B2Vec2, count int) {
84 B2Assert(chain.M_vertices == nil && chain.M_count == 0)

Callers 1

TestCPPComplianceFunction · 0.80

Calls 2

B2AssertFunction · 0.85
B2Vec2DistanceSquaredFunction · 0.85

Tested by 1

TestCPPComplianceFunction · 0.64