actor

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AABB

type AABB struct {
	Min mgl64.Vec3
	Max mgl64.Vec3
}

AABB represents an axis-aligned bounding box

func (AABB) ContainsPoint

func (a AABB) ContainsPoint(point mgl64.Vec3) bool

ContainsPoint checks if a point is inside the AABB

func (AABB) Overlaps

func (a AABB) Overlaps(other AABB) bool

Overlaps checks if two AABBs overlap

type BodyType

type BodyType int

BodyType represents the type of rigid body

const (
	// BodyTypeDynamic bodies are affected by forces, gravity, and collisions
	// They have finite mass and can move freely
	BodyTypeDynamic BodyType = iota

	// BodyTypeStatic bodies are immovable and have infinite mass
	// They are not affected by forces or gravity (e.g., ground, walls)
	BodyTypeStatic
)

type Box

type Box struct {
	HalfExtents mgl64.Vec3
	// contains filtered or unexported fields
}

Box represents an oriented box collision shape The box is defined by its half-extents (half-width, half-height, half-depth)

func (*Box) CollideWithPlane

func (b *Box) CollideWithPlane(planeNormal mgl64.Vec3, planeDistance float64, myTransform Transform) (bool, PlaneContact)

CollideWithPlane - Collision Box/Plane

func (*Box) ComputeAABB

func (b *Box) ComputeAABB(transform Transform)

func (*Box) ComputeInertia

func (b *Box) ComputeInertia(mass float64) mgl64.Mat3

func (*Box) ComputeMass

func (b *Box) ComputeMass(density float64) float64

ComputeMass calculates mass data for the box

func (*Box) GetAABB

func (b *Box) GetAABB() AABB

func (*Box) GetContactFeature

func (b *Box) GetContactFeature(direction mgl64.Vec3, output *[8]mgl64.Vec3, count *int)

func (*Box) Support

func (b *Box) Support(direction mgl64.Vec3) mgl64.Vec3

type ContactPoint

type ContactPoint struct {
	Position    mgl64.Vec3
	Penetration float64
}

type Material

type Material struct {
	Density float64

	Restitution float64 // 0= no rebound, 1= perfect restitution

	StaticFriction  float64
	DynamicFriction float64
	LinearDamping   float64 // 0.0 - 1.0, typique : 0.01
	AngularDamping  float64 // 0.0 - 1.0, typique : 0.05
	// contains filtered or unexported fields
}

func (Material) GetMass

func (material Material) GetMass() float64

type Plane

type Plane struct {
	Normal   mgl64.Vec3 // Plane normal (must be normalized)
	Distance float64    // Plane constant (signed distance from origin)
	// contains filtered or unexported fields
}

Plane represents an infinite plane collision shape The plane is defined by the equation: Normal · p + Distance = 0 where Normal is the plane's normal vector (must be normalized) and Distance is the signed distance from the origin along the normal

func (*Plane) CollideWithPlane

func (p *Plane) CollideWithPlane(planeNormal mgl64.Vec3, planeDistance float64, myTransform Transform) (bool, PlaneContact)

CollideWithPlane - Plane/Plane collision (not supported)

func (*Plane) ComputeAABB

func (p *Plane) ComputeAABB(transform Transform)

This method is bypassed, because planes are automatically included from the broad phase to the narrow phase We use specific functions for plane / convex shapes collision

func (*Plane) ComputeInertia

func (p *Plane) ComputeInertia(mass float64) mgl64.Mat3

func (*Plane) ComputeMass

func (p *Plane) ComputeMass(density float64) float64

ComputeMass calculates mass data for the plane Planes are always static with infinite mass

func (*Plane) GetAABB

func (p *Plane) GetAABB() AABB

func (*Plane) GetContactFeature

func (p *Plane) GetContactFeature(direction mgl64.Vec3, output *[8]mgl64.Vec3, count *int)

The narrow phase has specific code path for planes, this should not be called

func (*Plane) Support

func (p *Plane) Support(direction mgl64.Vec3) mgl64.Vec3

For simplicity, we use a 10000 width/height box. Can obviously break for bigger planes

type PlaneContact

type PlaneContact []ContactPoint

type RigidBody

type RigidBody struct {
	// Useful to map to user data (e.g. entity id)
	Id any

	// Spatial properties
	PreviousTransform Transform
	Transform         Transform

	// Linear motion
	PresolveVelocity mgl64.Vec3
	Velocity         mgl64.Vec3 // Linear velocity (m/s)

	// Angular motion (NOUVEAU)
	PresolveAngularVelocity mgl64.Vec3
	AngularVelocity         mgl64.Vec3 // Vitesse de rotation (rad/s)
	// Inertia (NOUVEAU)
	InertiaLocal        mgl64.Mat3 // Tenseur d'inertie en espace local
	InverseInertiaLocal mgl64.Mat3

	IsTrigger  bool
	IsSleeping bool
	SleepTimer float64

	// Physical properties
	Material Material
	BodyType BodyType // Dynamic or Static

	// Collision shape
	Shape ShapeInterface // The collision shape

	Mutex sync.Mutex
	// contains filtered or unexported fields
}

RigidBody represents a rigid body in the physics simulation

func NewRigidBody

func NewRigidBody(transform Transform, shape ShapeInterface, bodyType BodyType, density float64) *RigidBody

NewRigidBody creates a new rigid body with the given properties density is used to calculate mass for dynamic bodies (ignored for static)

func (*RigidBody) AddForce

func (rb *RigidBody) AddForce(force mgl64.Vec3)

AddForce in 1000N (1000 * kg⋅m/s²)

func (*RigidBody) AddTorque

func (rb *RigidBody) AddTorque(torque mgl64.Vec3)

AddTorque in 1000N⋅m

func (*RigidBody) ClearForces

func (rb *RigidBody) ClearForces()

Méthodes optionnelles pour reset

func (*RigidBody) GetInertiaWorld

func (rb *RigidBody) GetInertiaWorld() mgl64.Mat3

Inertie en espace monde

func (*RigidBody) GetInverseInertiaWorld

func (rb *RigidBody) GetInverseInertiaWorld() mgl64.Mat3

Inverse de l'inertie en espace monde

func (*RigidBody) Integrate

func (rb *RigidBody) Integrate(dt float64, gravity mgl64.Vec3)

func (*RigidBody) Sleep

func (rb *RigidBody) Sleep()

func (*RigidBody) SupportWorld

func (rb *RigidBody) SupportWorld(direction mgl64.Vec3) mgl64.Vec3

func (*RigidBody) TrySleep

func (rb *RigidBody) TrySleep(dt float64, timethreshold float64, velocityThreshold float64) uint8

TrySleep check if a body can be set to sleep. returns 0 if no changes, 1 if set to sleep, 2 if waken

func (*RigidBody) Update

func (rb *RigidBody) Update(dt float64)

func (*RigidBody) WakeUp

func (rb *RigidBody) WakeUp()

type ShapeInterface

type ShapeInterface interface {
	// ComputeAABB calculates the axis-aligned bounding box for the shape
	// at the given transform
	ComputeAABB(transform Transform)
	GetAABB() AABB
	// ComputeMass calculates mass data for the shape given a density
	ComputeMass(density float64) float64
	ComputeInertia(mass float64) mgl64.Mat3
	Support(direction mgl64.Vec3) mgl64.Vec3
	GetContactFeature(direction mgl64.Vec3, output *[8]mgl64.Vec3, count *int)
	CollideWithPlane(planeNormal mgl64.Vec3, planeDistance float64, myTransform Transform) (bool, PlaneContact)
}

ShapeInterface is the interface that all collision shapes must implement

type ShapeType

type ShapeType int

ShapeType represents the type of collision shape

const (
	ShapeTypeSphere ShapeType = iota
	ShapeTypeBox
	ShapeTypePlane
)

type Sphere

type Sphere struct {
	Radius float64
	// contains filtered or unexported fields
}

Sphere represents a spherical collision shape

func (*Sphere) CollideWithPlane

func (s *Sphere) CollideWithPlane(planeNormal mgl64.Vec3, planeDistance float64, myTransform Transform) (bool, PlaneContact)

func (*Sphere) ComputeAABB

func (s *Sphere) ComputeAABB(transform Transform)

ComputeAABB calculates the axis-aligned bounding box for the sphere

func (*Sphere) ComputeInertia

func (s *Sphere) ComputeInertia(mass float64) mgl64.Mat3

func (*Sphere) ComputeMass

func (s *Sphere) ComputeMass(density float64) float64

ComputeMass calculates mass data for the sphere

func (*Sphere) GetAABB

func (s *Sphere) GetAABB() AABB

func (*Sphere) GetContactFeature

func (s *Sphere) GetContactFeature(direction mgl64.Vec3, output *[8]mgl64.Vec3, count *int)

func (*Sphere) Support

func (s *Sphere) Support(direction mgl64.Vec3) mgl64.Vec3

type Transform

type Transform struct {
	Position        mgl64.Vec3
	Rotation        mgl64.Quat
	InverseRotation mgl64.Quat
}

Transform represents a position in 3D space

func NewTransform

func NewTransform() Transform

NewTransform creates an identity transform

Jump to

Keyboard shortcuts

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