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

Method RayCast

DynamicsB2World.go:977–1003  ·  view source on GitHub ↗
(callback B2RaycastCallback, point1 B2Vec2, point2 B2Vec2)

Source from the content-addressed store, hash-verified

975}
976
977func (world *B2World) RayCast(callback B2RaycastCallback, point1 B2Vec2, point2 B2Vec2) {
978
979 // B2TreeRayCastCallback
980 wrapper := func(input B2RayCastInput, nodeId int) float64 {
981
982 userData := world.M_contactManager.M_broadPhase.GetUserData(nodeId)
983 proxy := userData.(*B2FixtureProxy)
984 fixture := proxy.Fixture
985 index := proxy.ChildIndex
986 output := MakeB2RayCastOutput()
987 hit := fixture.RayCast(&output, input, index)
988
989 if hit {
990 fraction := output.Fraction
991 point := B2Vec2Add(B2Vec2MulScalar((1.0-fraction), input.P1), B2Vec2MulScalar(fraction, input.P2))
992 return callback(fixture, point, output.Normal, fraction)
993 }
994
995 return input.MaxFraction
996 }
997
998 input := MakeB2RayCastInput()
999 input.MaxFraction = 1.0
1000 input.P1 = point1
1001 input.P2 = point2
1002 world.M_contactManager.M_broadPhase.RayCast(wrapper, input)
1003}
1004
1005// void (world *B2World) DrawShape(b2Fixture* fixture, const b2Transform& xf, const b2Color& color)
1006// {

Callers

nothing calls this directly

Calls 6

MakeB2RayCastOutputFunction · 0.85
B2Vec2AddFunction · 0.85
B2Vec2MulScalarFunction · 0.85
MakeB2RayCastInputFunction · 0.85
GetUserDataMethod · 0.65
RayCastMethod · 0.65

Tested by

no test coverage detected