cbridge

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2026 License: LGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package cbridge wraps Box2D v3 (C) via CGO for the physics2d plugin. All Box2D state lives on the C side; Go interacts through entity IDs.

Index

Constants

View Source
const (
	ContactBegin uint8 = C.BRIDGE_CONTACT_BEGIN
	ContactEnd   uint8 = C.BRIDGE_CONTACT_END
)

Variables

This section is empty.

Functions

func AddBoxShape

func AddBoxShape(
	entityID uint32, shapeIndex int,
	offsetX, offsetY float64,
	halfW, halfH, localRot float64,
	isSensor bool, friction, restitution, density float64,
	cat, mask uint64, group int32,
) bool

func AddCapsuleShape

func AddCapsuleShape(
	entityID uint32, shapeIndex int,
	c1x, c1y, c2x, c2y, radius float64,
	isSensor bool, friction, restitution, density float64,
	cat, mask uint64, group int32,
) bool

func AddChainShape

func AddChainShape(
	entityID uint32, shapeIndex int,
	points []Vec2, isLoop bool,
	friction, restitution float64,
	cat, mask uint64, group int32,
) bool

func AddCircleShape

func AddCircleShape(
	entityID uint32, shapeIndex int,
	offsetX, offsetY, radius float64,
	isSensor bool, friction, restitution, density float64,
	cat, mask uint64, group int32,
) bool

func AddPolygonShape

func AddPolygonShape(
	entityID uint32, shapeIndex int,
	verts []Vec2,
	offsetX, offsetY, localRot float64,
	isSensor bool, friction, restitution, density float64,
	cat, mask uint64, group int32,
) bool

func AddSegmentShape

func AddSegmentShape(
	entityID uint32, shapeIndex int,
	v1x, v1y, v2x, v2y float64,
	isSensor bool, friction, restitution, density float64,
	cat, mask uint64, group int32,
) bool

func CreateBody

func CreateBody(
	entityID uint32, bodyType uint8,
	px, py, angle float64,
	vx, vy, av float64,
	linearDamping, angularDamping, gravityScale float64,
	enabled, awake, sleepEnabled, bullet, fixedRotation bool,
) bool

func CreateWorld

func CreateWorld(gx, gy float64)

func DestroyAllBodies

func DestroyAllBodies()

func DestroyAllShapes

func DestroyAllShapes(entityID uint32)

func DestroyBody

func DestroyBody(entityID uint32)

func DestroyWorld

func DestroyWorld()

func GetWorldID

func GetWorldID() uint32

GetWorldID returns the Box2D world id packed as uint32 (0 = no world).

func ResetMassData

func ResetMassData(entityID uint32)

func SetAngularDamping

func SetAngularDamping(entityID uint32, damping float64)

func SetAngularVelocity

func SetAngularVelocity(entityID uint32, av float64)

func SetAwake

func SetAwake(entityID uint32, awake bool)

func SetBodyEnabled

func SetBodyEnabled(entityID uint32, enabled bool)

func SetBodyType

func SetBodyType(entityID uint32, bodyType uint8)

func SetBullet

func SetBullet(entityID uint32, flag bool)

func SetFixedRotation

func SetFixedRotation(entityID uint32, flag bool)

func SetGravity

func SetGravity(gx, gy float64)

func SetGravityScale

func SetGravityScale(entityID uint32, scale float64)

func SetLinearDamping

func SetLinearDamping(entityID uint32, damping float64)

func SetLinearVelocity

func SetLinearVelocity(entityID uint32, vx, vy float64)

func SetShapeDensity

func SetShapeDensity(entityID uint32, shapeIndex int, density float64)

func SetShapeFilter

func SetShapeFilter(entityID uint32, shapeIndex int, cat, mask uint64, group int32)

func SetShapeFriction

func SetShapeFriction(entityID uint32, shapeIndex int, friction float64)

func SetShapeRestitution

func SetShapeRestitution(entityID uint32, shapeIndex int, restitution float64)

func SetSleepEnabled

func SetSleepEnabled(entityID uint32, enabled bool)

func SetTransform

func SetTransform(entityID uint32, px, py, angle float64)

func Step

func Step(dt float64, subStepCount int) ([]BodyState, []ContactEvent)

Step advances the active C-side world and returns body states and contact events. Not safe to call concurrently — cbridge owns single-world global state (the C-side world itself).

func WorldExists

func WorldExists() bool

Types

type BodyState

type BodyState struct {
	EntityID      uint32
	BodyType      uint8
	PX, PY, Angle float64
	VX, VY, AV    float64
}

type CircleSweepResult

type CircleSweepResult struct {
	Hit        bool
	EntityID   uint32
	ShapeIndex int
	PX, PY     float64
	NX, NY     float64
	Fraction   float64
}

func CircleSweep

func CircleSweep(sx, sy, ex, ey, radius float64, cat, mask uint64, includeSensors bool, maxFraction float64,
) CircleSweepResult

type ContactEvent

type ContactEvent struct {
	Kind               uint8
	EntityA, EntityB   uint32
	ShapeIndexA        int
	ShapeIndexB        int
	IsSensor           bool
	CatA, MaskA        uint64
	GroupA             int32
	CatB, MaskB        uint64
	GroupB             int32
	NormalX, NormalY   float64
	NormalValid        bool
	PointX, PointY     float64
	PointValid         bool
	ManifoldPointCount int
}

func GatherLiveContacts

func GatherLiveContacts() []ContactEvent

type OverlapHit

type OverlapHit struct {
	EntityID   uint32
	ShapeIndex int
}

func OverlapAABB

func OverlapAABB(minX, minY, maxX, maxY float64, cat, mask uint64, includeSensors bool) []OverlapHit

type RaycastResult

type RaycastResult struct {
	Hit        bool
	EntityID   uint32
	ShapeIndex int
	PX, PY     float64
	NX, NY     float64
	Fraction   float64
}

func Raycast

func Raycast(ox, oy, ex, ey float64, cat, mask uint64, includeSensors bool) RaycastResult

type Vec2

type Vec2 struct{ X, Y float64 }

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL