Documentation ¶
Index ¶
- Variables
- func B2Vec2ToVec2(vec box2d.B2Vec2) mgl32.Vec2
- func ScalarToBox2D(v float32) float64
- func ScalarToPixel(v float64) float32
- func ToBox2DAngle(angle float32) float64
- func ToBox2DCoordinates(vec mgl32.Vec2) box2d.B2Vec2
- func ToBox2DDirection(vec mgl32.Vec2) box2d.B2Vec2
- func ToPixelAngle(angle float64) float32
- func ToPixelCoordinates(vec box2d.B2Vec2) mgl32.Vec2
- func ToPixelDirection(vec box2d.B2Vec2) mgl32.Vec2
- func Vec2ToB2Vec2(vec mgl32.Vec2) box2d.B2Vec2
- type PhysicsConnector2D
- type PhysicsDebugDraw2D
- func (this *PhysicsDebugDraw2D) DrawChain(f *box2d.B2Fixture, xf *box2d.B2Transform)
- func (this *PhysicsDebugDraw2D) DrawCircle(f *box2d.B2Fixture, xf *box2d.B2Transform)
- func (this *PhysicsDebugDraw2D) DrawEdge(f *box2d.B2Fixture, xf *box2d.B2Transform)
- func (this *PhysicsDebugDraw2D) DrawFixture(f *box2d.B2Fixture, xf *box2d.B2Transform, awake bool)
- func (this *PhysicsDebugDraw2D) DrawJoint(j box2d.B2JointInterface)
- func (this *PhysicsDebugDraw2D) DrawPolygon(f *box2d.B2Fixture, xf *box2d.B2Transform)
- func (this *PhysicsDebugDraw2D) GetType() gohome.RenderType
- func (this *PhysicsDebugDraw2D) IsVisible() bool
- func (this *PhysicsDebugDraw2D) Render()
- func (this *PhysicsDebugDraw2D) RendersLast() bool
- type PhysicsManager2D
- func (this *PhysicsManager2D) CreateDynamicBox(pos mgl32.Vec2, size mgl32.Vec2) *box2d.B2Body
- func (this *PhysicsManager2D) CreateDynamicCircle(pos mgl32.Vec2, radius float32) *box2d.B2Body
- func (this *PhysicsManager2D) CreateEllipse(X, Y, Width, Height float64) *box2d.B2Body
- func (this *PhysicsManager2D) CreatePolygon(X, Y float64, poly *tmx.Polygon) *box2d.B2Body
- func (this *PhysicsManager2D) CreatePolyline(X, Y float64, line *tmx.Polyline) *box2d.B2Body
- func (this *PhysicsManager2D) CreateRectangle(X, Y, Width, Height float64) *box2d.B2Body
- func (this *PhysicsManager2D) CreateStaticBox(pos mgl32.Vec2, size mgl32.Vec2) *box2d.B2Body
- func (this *PhysicsManager2D) CreateStaticCircle(pos mgl32.Vec2, radius float32) *box2d.B2Body
- func (this *PhysicsManager2D) GetDebugDraw() PhysicsDebugDraw2D
- func (this *PhysicsManager2D) Init(gravity mgl32.Vec2)
- func (this *PhysicsManager2D) LayerToCollision(tiledmap *gohome.TiledMap, layerName string) (bodies []*box2d.B2Body)
- func (this *PhysicsManager2D) Terminate()
- func (this *PhysicsManager2D) Update(delta_time float32)
Constants ¶
This section is empty.
Variables ¶
var ( // Defines how big one meter is PIXEL_PER_METER float32 = 100.0 // Defines the size of the world (can be used to remove everything outside of the world) WORLD_SIZE mgl32.Vec2 // The number of velocity iterations of Box2D VELOCITY_ITERATIONS = 6 // The number of position iterations of Box2D POSITION_ITERATIONS = 2 )
Functions ¶
func B2Vec2ToVec2 ¶
Converts a physics Vec2 to a pixel Vec2
func ScalarToBox2D ¶
Converts a pixel scalar value to a physics value
func ScalarToPixel ¶
Converts a physics scalar value to a pixel value
func ToBox2DAngle ¶
Converts a pixel angel to physics angle
func ToBox2DCoordinates ¶
Converts pixel coordinates to physics coordinates
func ToBox2DDirection ¶
Converts a pixel direction into a physics direction
func ToPixelAngle ¶
Converts a physics angle to pixel angle
func ToPixelCoordinates ¶
Converts physics coordinates to pixel coordinates
func ToPixelDirection ¶
Converts a physics direction into a pixel direction
Types ¶
type PhysicsConnector2D ¶
type PhysicsConnector2D struct { // The transform to which this object is connected to Transform *gohome.TransformableObject2D // The body to which this object is connected to Body *box2d.B2Body // The offset from the body Offset mgl32.Vec2 // contains filtered or unexported fields }
Connects a transformable object with a body and updates the position and rotation
func (*PhysicsConnector2D) Init ¶
func (this *PhysicsConnector2D) Init(tobj *gohome.TransformableObject2D, body *box2d.B2Body, pmgr *PhysicsManager2D)
Initialises the values
func (*PhysicsConnector2D) Terminate ¶
func (this *PhysicsConnector2D) Terminate()
Removes this connector from the manager
func (*PhysicsConnector2D) Update ¶
func (this *PhysicsConnector2D) Update()
Gets called by the physics manager
type PhysicsDebugDraw2D ¶
type PhysicsDebugDraw2D struct { gohome.NilRenderObject // Wether bodies should be drawn DrawBodies bool // Wether joints shoul be drawn DrawJoints bool // Wether bounding boxes should be drawn DrawAABBs bool // Wether only static bodies should be drawn OnlyDrawStatic bool // Wether only dynamic bodies should be drawn OnlyDrawDynamic bool // Wether anything should be drawn Visible bool // contains filtered or unexported fields }
This struct renders all physics objects to the screen
func (*PhysicsDebugDraw2D) DrawChain ¶
func (this *PhysicsDebugDraw2D) DrawChain(f *box2d.B2Fixture, xf *box2d.B2Transform)
Loads the data used to render a chain
func (*PhysicsDebugDraw2D) DrawCircle ¶
func (this *PhysicsDebugDraw2D) DrawCircle(f *box2d.B2Fixture, xf *box2d.B2Transform)
Loads the data used to render a circle
func (*PhysicsDebugDraw2D) DrawEdge ¶
func (this *PhysicsDebugDraw2D) DrawEdge(f *box2d.B2Fixture, xf *box2d.B2Transform)
Loads the data used to render an edge
func (*PhysicsDebugDraw2D) DrawFixture ¶
func (this *PhysicsDebugDraw2D) DrawFixture(f *box2d.B2Fixture, xf *box2d.B2Transform, awake bool)
Loads the data used to render a Fixture
func (*PhysicsDebugDraw2D) DrawJoint ¶
func (this *PhysicsDebugDraw2D) DrawJoint(j box2d.B2JointInterface)
Loads the data used to render a joint
func (*PhysicsDebugDraw2D) DrawPolygon ¶
func (this *PhysicsDebugDraw2D) DrawPolygon(f *box2d.B2Fixture, xf *box2d.B2Transform)
Loads the data used to render a polygon
func (*PhysicsDebugDraw2D) GetType ¶
func (this *PhysicsDebugDraw2D) GetType() gohome.RenderType
Returns TYPE_2D_NORMAL
func (*PhysicsDebugDraw2D) IsVisible ¶
func (this *PhysicsDebugDraw2D) IsVisible() bool
Returns wether anything should be drawn
func (*PhysicsDebugDraw2D) Render ¶
func (this *PhysicsDebugDraw2D) Render()
Creates all shapes and renders them
func (*PhysicsDebugDraw2D) RendersLast ¶
func (this *PhysicsDebugDraw2D) RendersLast() bool
Returns true
type PhysicsManager2D ¶
type PhysicsManager2D struct { // The Box2D world World box2d.B2World // Wether the world is paused (no movement) Paused bool // contains filtered or unexported fields }
The manager that handles all 2D physics
func (*PhysicsManager2D) CreateDynamicBox ¶
Creates a box that can move around
func (*PhysicsManager2D) CreateDynamicCircle ¶
Creates a circle that can move around
func (*PhysicsManager2D) CreateEllipse ¶
func (this *PhysicsManager2D) CreateEllipse(X, Y, Width, Height float64) *box2d.B2Body
Creates an ellipse
func (*PhysicsManager2D) CreatePolygon ¶
Creates a polygon from a tmx polygon
func (*PhysicsManager2D) CreatePolyline ¶
Creates a polyline from a tmx polyline
func (*PhysicsManager2D) CreateRectangle ¶
func (this *PhysicsManager2D) CreateRectangle(X, Y, Width, Height float64) *box2d.B2Body
Creates a rectangle
func (*PhysicsManager2D) CreateStaticBox ¶
Creates a box that sticks to a position
func (*PhysicsManager2D) CreateStaticCircle ¶
Creates a circle that sticks to a position
func (*PhysicsManager2D) GetDebugDraw ¶
func (this *PhysicsManager2D) GetDebugDraw() PhysicsDebugDraw2D
Returns a new debug drawer
func (*PhysicsManager2D) Init ¶
func (this *PhysicsManager2D) Init(gravity mgl32.Vec2)
Initialises the world and everything using a gravity value
func (*PhysicsManager2D) LayerToCollision ¶
func (this *PhysicsManager2D) LayerToCollision(tiledmap *gohome.TiledMap, layerName string) (bodies []*box2d.B2Body)
Converts the objects of a tmx map layer to static collision objects
func (*PhysicsManager2D) Terminate ¶
func (this *PhysicsManager2D) Terminate()
Destroys all bodies and the world
func (*PhysicsManager2D) Update ¶
func (this *PhysicsManager2D) Update(delta_time float32)
Gets called every frame and updates the physics