Posts SIMple Mechanics Tutorial
Post
Cancel

SIMple Mechanics Tutorial

SIMple Mechanics is the simulator meant for the kinematics, projectile motions, and collisions sections of high school physics.

Download/Installation

Windows

  1. Download the latest windows release from the Github releases page. It should be called SIMple-Mechanics-windows.zip.
  2. Unzip the folder in a folder of your choosing. Remember this folder, as this is where you’ll find output graphs and sample Lua files.
  3. Run physics-engine-v2.exe

MacOS

SIMple Mechanics is not currently compiled for MacOS because I don’t have a Mac. If you would like to compile it for distribution, contact me at mikail.khan@protonmail.com

Linux

  1. Download the latest windows release from the Github releases page. It should be called SIMple-Mechanics-linux.tar.gz.
  2. Unzip the archive in a folder of your choosing. Remember this folder, as this is where you’ll find output graphs and sample Lua files.
  3. Run physics-engine-v2

Getting Started

When you run SIMple Mechanics for the first time, you should see this: initial setup

You can drag around objects with your mouse. drag objects

There are a few menus on the menu bar. menus

  • Create: adjust the properties of newly created objects
    • Centered: Makes created objects start from the center instead of the bounds
    • Static: Makes created objects completely static, for floors and walls
  • Settings: adjust global simulation settings
    • Timestep: The amount of time, in seconds, passed every physics step. The lower this is, the more accurate the simulation will be. 0.016 is the default because each frame is about 16 milliseconds apart, assuming a frame rate of 60 FPS.
    • Gravity
    • Steps per frame: The number of steps calculated each frame. Higher values will make the simulation faster without sacrificing accuracy but can reduce the frame rate.
  • Save Graphs: Saves graphs of named objects to a CSV file for use in spreadsheet software. The file will be in the folder from which the program was executed.
  • Save World: Exports the world to a lua file. The file will be in the lua/ subfolder of the folder in which the program was executed.
  • Load World: Loads a lua file from the lua/ subfolder
  • Clear: Deletes all objects from the scene
  • Pause: Pauses the simulation

Sidepanel

The sidepanel appears when you right click an object. To deselect an object, right click on an empty spot. The sidepanel lets you see and modify an object’s properties. You can also use it to create graphs or delete the shape. sidepanel

Graphs

You can graph an object’s properties. Move the graph by left clicking and dragging on the bottom right corner. Scale the graph by right clicking on the corner and dragging. Graphs of objects with a name can be exported to CSV with the “Save Graphs” button. Graphs take on the color of their object, and you can tell what property they are graphing by point style:

PropertyPoint Style
SpeedSquare
Rotational VelocityDot
X PositionRing
Y PositionRing
X VelocityDiamond
Y VelocityDiamond
Rotation AngleRing

graphs

Hotkeys

HotkeyAction
BCreate a box
CCreate a circle
SpacePause/Unpause
SCreate object static
ACreate object centered
Shift+DDelete all objects
DDelete object on sidepanel

Lua

You can create scenes using Lua. Lua is a very simple language so you can probably get started by looking at the defaults in the lua/ folder if you know how to code. The pinball.lua example should be a good starting point

There are two important functions:

  • add_shape(shape) adds a shape
  • add_shapes(shape1, shape2, ...) adds many shapes

A shape is a Lua table with the following fields:

NamePossible ValuesDefaultDescription
shape“rect”, “circle”N/AThe shape of the object
status“static”, “dynamic”dynamicStatic objects are unaffected by physics
xAny numberN/AThe x coordinate of the center of the object
yAny numberN/AThe y coordinate of the center of the object
rotationAny numberN/AThe rotation of the object
x_velAny number0The x velocity of the object
y_velAny number0The y velocity of the object
rotvelAny number0The rotational/angular velocity of the object
wAny numberN/AIf the shape is a rectangle, its width
hAny numberN/AIf the shape is a rectangle, its height
rAny numberN/AIf the shape is a circle, its radius
massAny number >= 0N/AThe object’s mass
elasticityA number between 0 and 10.2An object’s elasticity/restitution/bounciness
frictionA number between 0 and 10.5An object’s static and dynamic friction coeficient
nameAny textEmptyAn object’s name, used for graphing
colorA table containing {r, g, b}EmptyThe color of the object, RGB values range from 0 to 255

Values with a default value of N/A are mandatory, except for w, h, and r, which are only mandatory if you are using the corresponding shape.

Additionally, there are a few global variables.

  • GRAVITY can be modified to change the gravity of the scene. Positive values make things go to the bottom of the screen.
  • SCREEN_X is the width of the screen.
  • SCREEN_Y is the height of the screen.

For security, the Lua environment is sandboxed. You can only use the base, table, math, and string modules of the standard library. Additionally, there is a memory limit of 256 MB and an instruction limit of 75,000.

This post is licensed under CC BY 4.0 by the author.