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 ¶
- func Simulate(bods []Body, timestep float64)
- type Body
- func (body *Body) Activate()
- func (body *Body) AddForce(position lin.V3, newtons lin.V3, local_coords bool)
- func (body *Body) Position() (world_position *lin.V3)
- func (body *Body) Push(x, y, z float64)
- func (body *Body) Rotation() (world_rotation *lin.Q)
- func (body *Body) SetPosition(world_position lin.V3)
- func (body *Body) SetRotation(world_rotation lin.Q)
- func (body *Body) SetScale(world_scale lin.V3)
- func (body *Body) Velocity() (velocity *lin.V3)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Simulate ¶ added in v0.20.0
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 ¶
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 ¶
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
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) SetPosition ¶ added in v0.20.0
SetPosition sets the bodies world position.
func (*Body) SetRotation ¶ added in v0.20.0
SetRotation sets the bodies rotation.