Skip to content

Instantly share code, notes, and snippets.

@erincatto
erincatto / static_shapes.md
Last active March 25, 2024 19:47
Static Shapes

Option 1: static bodies

typedef struct b2StaticBodyDef
{
	/// The world position of the body. Avoid creating bodies at the origin
	/// since this can lead to many overlapping shapes.
	b2Vec2 position;

	/// The world angle of the body in radians.
	float angle;
@erincatto
erincatto / soft_constraint_test.m
Last active January 24, 2024 05:29
Soft Constraint Octave Script
% This tests a two particle mass-spring-damper system with particle 1 connect to ground and
% particle 2 connected to particle 1. Particle 2 is much heavier than particle 1 and the
% simulation can go unstable if the soft constraint is made too stiff.
% Stability is improved by adding a relaxation step that applies the rigid constraint after
% the position update.
% no relax stable up to 13.5 Hz
% with relax stable up to 20.5 Hz
relax = 1;
hertz = 20.5;
@erincatto
erincatto / choice.c
Last active January 28, 2023 05:47
Data layout choices
struct b2CircleShape
{
// circle stuff
};
struct b2PolygonShape
{
// polygon stuff
};
@erincatto
erincatto / test_macros.h
Created January 8, 2023 17:40
Simple Unit Testing
// SPDX-FileCopyrightText: 2022 Erin Catto
// SPDX-License-Identifier: MIT
#include <stdbool.h>
#include <stdio.h>
#include <assert.h>
#define RUN_TEST(T) \
do { \
int result = T(); \
@erincatto
erincatto / const_correctness.md
Last active July 26, 2022 23:53
const correctness
struct Foo
{
   int* data;
};

void DoStuff(const Foo& f)
{
   f.data[3] = 10;
}
Given J*JT * x = b, solve for x in linear time and space.
J is m by n
x is m by 1
b is m by 1
m < n
J is a rectangular matrix that represents a tree with equal and opposite entries.
For example: