physics

package
v0.0.0-...-ece690c Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BOX = 1
View Source
var CIRCLE = 0
View Source
var DebugRenderer = sk.NewSystem(func(g *sk.Game) error {

	return nil
}, TransformAndBodyQuery)
View Source
var MAX_BODY_SIZE float64 = 64 * 64
View Source
var MAX_DENSITY float64 = 24
View Source
var MIN_BODY_SIZE float64 = 0.01 * 0.01
View Source
var MIN_DENSITY float64 = 0.01
View Source
var PhysicsUpdater = sk.NewSystem(func(g *sk.Game) error {
	objs := TransformAndBodyQuery.Query()

	for i := 0; i < len(objs)-1; i++ {
		for j := i + 1; j < len(objs); j++ {
			a := objs[i]
			b := objs[j]
			ok, normal, depth := collideCircleCircle(a.Transform, b.Transform, a.RigidBody, b.RigidBody)

			if ok {
				hdepth := depth / 2

				a.Transform.MoveBy(normal.X*hdepth, normal.Y*hdepth)
				b.Transform.MoveBy(-normal.X*hdepth, -normal.Y*hdepth)
			}
		}
	}
	return nil
}, TransformAndBodyQuery)
View Source
var RigidBody = sk.NewComponentWithOptions(sk.ComponentOptions[DRigidBody]{
	OnCreated: func(r *DRigidBody) {
		r.Mass = 1
		r.Density = 1
		r.Restitution = 0.5
		r.Shape = CIRCLE
		r.Radius = 1
		r.image = ebiten.NewImage(500, 500)
	},
})
View Source
var TransformAndBodyQuery = sk.NewQuery[struct {
	Transform *core.DTransform
	RigidBody *DRigidBody
}]()

Functions

This section is empty.

Types

type DRigidBody

type DRigidBody struct {
	LinearVelocity  sk.Vec2
	AngularVelocity float64

	Mass        float64
	Density     float64
	Restitution float64
	Area        float64

	Static bool

	// Temp
	Shape  int // 0: Circle, 1: Box
	Radius float64
	Width  float64
	Height float64
	// contains filtered or unexported fields
}

func (*DRigidBody) AsBox

func (r *DRigidBody) AsBox(width, height, density, restitution float64, static bool)

Temp

func (*DRigidBody) AsCircle

func (r *DRigidBody) AsCircle(radius, density, restitution float64, static bool)

Temp

func (*DRigidBody) AsRandom

func (r *DRigidBody) AsRandom()

Temp

func (*DRigidBody) GetBounds

func (r *DRigidBody) GetBounds() sk.Rect

Jump to

Keyboard shortcuts

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