Documentation
¶
Overview ¶
Package common provides a shared framework for QuarkPhysics Go examples. Ported from qexamplescene.h/.cpp.
Index ¶
- func RandomFloat(minVal, maxVal float32) float32
- func RandomRange(minVal, maxVal int) int
- type Renderer
- type Scene
- func (s *Scene) AddBlobBody(x, y float32, radius float32, sideCount int) *physics.SoftBody
- func (s *Scene) AddCircleBody(x, y float32) *physics.RigidBody
- func (s *Scene) AddCircleBodyR(x, y, r float32) *physics.RigidBody
- func (s *Scene) AddPolygonBody(x, y float32, sideCount int) *physics.RigidBody
- func (s *Scene) AddPolygonBodyR(x, y float32, sideCount int, r float32) *physics.RigidBody
- func (s *Scene) AddRectBody(x, y float32) *physics.RigidBody
- func (s *Scene) AddRectBodySized(x, y, w, h float32) *physics.RigidBody
- func (s *Scene) AddStaticRect(x, y, w, h float32) *physics.RigidBody
- func (s *Scene) AddStaticRectRot(x, y, w, h, rot float32) *physics.RigidBody
- func (s *Scene) CreateJointOrSpringBetweenMouseAndBody(pos physics.Vec2)
- func (s *Scene) CreateSceneBorders()
- func (s *Scene) Draw(screen *ebiten.Image)
- func (s *Scene) Layout(outsideW, outsideH int) (int, int)
- func (s *Scene) MousePosition() physics.Vec2
- func (s *Scene) OnMouseMoved(pos physics.Vec2)
- func (s *Scene) OnMousePressed(pos physics.Vec2)
- func (s *Scene) OnMouseReleased(pos physics.Vec2)
- func (s *Scene) RemoveMouseJointOrSpring()
- func (s *Scene) Update() error
- func (s *Scene) UpdateMouseJointOrSpring(pos physics.Vec2)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RandomFloat ¶
RandomFloat returns a random float32 in [min, max).
func RandomRange ¶
RandomRange returns a random int in [min, min+max).
Types ¶
type Renderer ¶
type Renderer struct {
Antialias bool
ShowColliders bool
ShowBoundingBoxes bool
ShowSprings bool
ShowJoints bool
ShowRaycasts bool
ShowVertices bool
// contains filtered or unexported fields
}
Renderer draws physics bodies to an Ebitengine image. Ported from QPhysicsRenderer.
func NewRenderer ¶
func NewRenderer() *Renderer
NewRenderer creates a Renderer with default settings.
type Scene ¶
type Scene struct {
World *physics.World
Size physics.Vec2
Renderer *Renderer
CurrentScene int
SpawnRectSize float32
SpawnCircleR float32
SpawnPolygonR float32
// Callbacks for scene switching
OnSceneSwitch func(int)
// contains filtered or unexported fields
}
Scene is the base structure for all example scenes. Ported from QExampleScene.
func (*Scene) AddBlobBody ¶
AddBlobBody creates a soft body blob with area preserving.
func (*Scene) AddCircleBody ¶
AddCircleBody creates a dynamic circle rigid body at (x,y).
func (*Scene) AddCircleBodyR ¶
AddCircleBodyR creates a dynamic circle rigid body with explicit radius.
func (*Scene) AddPolygonBody ¶
AddPolygonBody creates a dynamic polygon rigid body at (x,y).
func (*Scene) AddPolygonBodyR ¶
AddPolygonBodyR creates a dynamic polygon rigid body with explicit radius.
func (*Scene) AddRectBody ¶
AddRectBody creates a dynamic rect rigid body at (x,y).
func (*Scene) AddRectBodySized ¶
AddRectBodySized creates a dynamic rect rigid body with explicit size.
func (*Scene) AddStaticRect ¶
AddStaticRect creates a static rect body.
func (*Scene) AddStaticRectRot ¶
AddStaticRectRot creates a static rect body with rotation.
func (*Scene) CreateJointOrSpringBetweenMouseAndBody ¶
CreateJointOrSpringBetweenMouseAndBody attaches a joint (rigid body) or spring (soft body particle) at the given position.
func (*Scene) CreateSceneBorders ¶
func (s *Scene) CreateSceneBorders()
CreateSceneBorders creates 4 static walls around the scene. Ported from QExampleScene::CreateSceneBorders.
func (*Scene) MousePosition ¶
MousePosition returns the current mouse position in physics coordinates.
func (*Scene) OnMouseMoved ¶
OnMouseMoved handles mouse movement — updates the drag target.
func (*Scene) OnMousePressed ¶
OnMousePressed handles mouse press — creates a joint or spring to drag bodies.
func (*Scene) OnMouseReleased ¶
OnMouseReleased handles mouse release — removes the drag joint/spring.
func (*Scene) RemoveMouseJointOrSpring ¶
func (s *Scene) RemoveMouseJointOrSpring()
RemoveMouseJointOrSpring removes the current drag joint or spring.
func (*Scene) UpdateMouseJointOrSpring ¶
UpdateMouseJointOrSpring updates the drag target position.