physics

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: BSD-2-Clause, MIT Imports: 5 Imported by: 0

Documentation

Overview

Package physics is a real-time simulation of real-world physics. Physics applies simulated forces to virtual 3D objects known as bodies. Physics updates bodies locations and directions based on forces and collisions with other bodies.

Package physics is provided as part of the vu (virtual universe) 3D engine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Simulate added in v0.20.0

func Simulate(bods []Body, timestep float64)

Simulate physics for the given timestep. This is expected to be called regularly from the main engine loop. At the end of a simulation all of the bodies positions and orientations will be updated based on forces acting upon them and/or collision results. Fixed, or unmoved bodies, or bodies with zero mass are not updated.

Types

type Body

type Body struct {
	// contains filtered or unexported fields
}

Body is a one object within a physics simulation. Bodies are added for objects that need to participate in physics. Bodies transforms are set by the physics simulation and not the application.

func NewBox

func NewBox(hx, hy, hz float64, static bool) *Body

Box creates a box shaped physics body located at the origin. The box size is given by the half-extents so that actual size is w=2*hx, h=2*hy, d=2*hz. The box can be static (unmovable) or kinematic (moveable).

func NewSphere

func NewSphere(radius float64, static bool) *Body

Sphere creates a ball shaped physics body located at the origin. The sphere size is defined by the radius. The sphere can be static (unmovable) or kinematic (moveable).

func (*Body) Activate added in v0.20.0

func (body *Body) Activate()

Activate set the body as active in the simulation.

func (*Body) AddForce added in v0.20.0

func (body *Body) AddForce(position lin.V3, newtons lin.V3, local_coords bool)

AddForce to this body. If local_coords is false, then the position and force are represented in world coordinates, assuming that the center of the world is the center of the entity. That is, the coordinate (0, 0, 0) corresponds to the center of the entity in world coords. If local_coords is true, then the position and force are represented in local coords.

func (*Body) Position added in v0.20.0

func (body *Body) Position() (world_position *lin.V3)

Position returns the bodies world position.

func (*Body) Push

func (body *Body) Push(x, y, z float64)

Push adds to the bodies linear velocity.

func (*Body) Rotation added in v0.20.0

func (body *Body) Rotation() (world_rotation *lin.Q)

Rotation gets the bodies world rotation.

func (*Body) SetPosition added in v0.20.0

func (body *Body) SetPosition(world_position lin.V3)

SetPosition sets the bodies world position.

func (*Body) SetRotation added in v0.20.0

func (body *Body) SetRotation(world_rotation lin.Q)

SetRotation sets the bodies rotation.

func (*Body) SetScale added in v0.20.0

func (body *Body) SetScale(world_scale lin.V3)

SetScale sets the bodies scale

func (*Body) Velocity added in v0.20.0

func (body *Body) Velocity() (velocity *lin.V3)

Jump to

Keyboard shortcuts

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