common

package
v0.0.0-...-9691af7 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package common provides a shared framework for QuarkPhysics Go examples. Ported from qexamplescene.h/.cpp.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandomFloat

func RandomFloat(minVal, maxVal float32) float32

RandomFloat returns a random float32 in [min, max).

func RandomRange

func RandomRange(minVal, maxVal int) int

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.

func (*Renderer) Draw

func (r *Renderer) Draw(screen *ebiten.Image, world *physics.World)

Draw renders all bodies in the world to the screen.

func (*Renderer) DrawDragLine

func (r *Renderer) DrawDragLine(screen *ebiten.Image, from, to physics.Vec2)

DrawDragLine draws a line from body to mouse cursor during drag.

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 NewScene

func NewScene(w, h float32) *Scene

NewScene creates a new Scene with default settings.

func (*Scene) AddBlobBody

func (s *Scene) AddBlobBody(x, y float32, radius float32, sideCount int) *physics.SoftBody

AddBlobBody creates a soft body blob with area preserving.

func (*Scene) AddCircleBody

func (s *Scene) AddCircleBody(x, y float32) *physics.RigidBody

AddCircleBody creates a dynamic circle rigid body at (x,y).

func (*Scene) AddCircleBodyR

func (s *Scene) AddCircleBodyR(x, y, r float32) *physics.RigidBody

AddCircleBodyR creates a dynamic circle rigid body with explicit radius.

func (*Scene) AddPolygonBody

func (s *Scene) AddPolygonBody(x, y float32, sideCount int) *physics.RigidBody

AddPolygonBody creates a dynamic polygon rigid body at (x,y).

func (*Scene) AddPolygonBodyR

func (s *Scene) AddPolygonBodyR(x, y float32, sideCount int, r float32) *physics.RigidBody

AddPolygonBodyR creates a dynamic polygon rigid body with explicit radius.

func (*Scene) AddRectBody

func (s *Scene) AddRectBody(x, y float32) *physics.RigidBody

AddRectBody creates a dynamic rect rigid body at (x,y).

func (*Scene) AddRectBodySized

func (s *Scene) AddRectBodySized(x, y, w, h float32) *physics.RigidBody

AddRectBodySized creates a dynamic rect rigid body with explicit size.

func (*Scene) AddStaticRect

func (s *Scene) AddStaticRect(x, y, w, h float32) *physics.RigidBody

AddStaticRect creates a static rect body.

func (*Scene) AddStaticRectRot

func (s *Scene) AddStaticRectRot(x, y, w, h, rot float32) *physics.RigidBody

AddStaticRectRot creates a static rect body with rotation.

func (*Scene) CreateJointOrSpringBetweenMouseAndBody

func (s *Scene) CreateJointOrSpringBetweenMouseAndBody(pos physics.Vec2)

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) Draw

func (s *Scene) Draw(screen *ebiten.Image)

Draw renders the physics state to the screen.

func (*Scene) Layout

func (s *Scene) Layout(outsideW, outsideH int) (int, int)

Layout returns the screen dimensions.

func (*Scene) MousePosition

func (s *Scene) MousePosition() physics.Vec2

MousePosition returns the current mouse position in physics coordinates.

func (*Scene) OnMouseMoved

func (s *Scene) OnMouseMoved(pos physics.Vec2)

OnMouseMoved handles mouse movement — updates the drag target.

func (*Scene) OnMousePressed

func (s *Scene) OnMousePressed(pos physics.Vec2)

OnMousePressed handles mouse press — creates a joint or spring to drag bodies.

func (*Scene) OnMouseReleased

func (s *Scene) OnMouseReleased(pos physics.Vec2)

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) Update

func (s *Scene) Update() error

Update advances the physics simulation by one step.

func (*Scene) UpdateMouseJointOrSpring

func (s *Scene) UpdateMouseJointOrSpring(pos physics.Vec2)

UpdateMouseJointOrSpring updates the drag target position.

Jump to

Keyboard shortcuts

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