Skip to content

Instantly share code, notes, and snippets.

View slembcke's full-sized avatar
👣
Gruntled

Scott Lembcke slembcke

👣
Gruntled
View GitHub Profile
@slembcke
slembcke / sliding
Last active February 12, 2018 18:48
Falling down a hill.
// Gravity pulls the player down,
// but the slope of the hill pushes them in another direction.
static const float G = ...; // Acceleration due to gravity.
// First find what percentage of gravity is wasted opposing the ground normal:
float dotN = Vector3.Dot(groundNormal, -Vector3.up);
// Or simplified, just -groundNormal.y
// Subtract that from the down vector to get the percent
@slembcke
slembcke / ChipmunkFuture.txt
Created August 28, 2017 19:17
Future of Chipmunk2D.
So I haven't worked on Chipmunk heavily for several years. Why? I used to make games for myself in the past, but other than game jams I haven't in a few years. We also used to make part of our living working on Chipmunk, but now have to focus on a lot of other projects. I've gotten to work on some really neat projects lately, like a PS4/Xbox game and drone mapping software. Nothing that has needed 2D physics simulation though.
At the same time, Chipmunk will be 11 years old in September of 2017. On the one hand, I feel like it has become very mature. It does what it's supposed to do very well at this point. On the other hand there are changes that I'd like to make, but it's very hard to make them at this point. For example:
* Supporting C code on MSVC is a giant pain. They've made it clear that they will never, ever support anything newer than C89. I could save myself a lot of trouble by switching the implementation to C++11, and leaving the API as plain old C.
* Speculative contacts would be a very intere
@slembcke
slembcke / CustomProjection.cs
Last active February 7, 2024 11:03
Custom projections for Unity2D games.
using UnityEngine;
using System.Collections;
// This script is meant to be attached to your main camera.
// If you want to use it on more than one camera at a time, it will require
// modifcations due to the Camera.on* delegates in OnEnable()/OnDisable().
[ExecuteInEditMode]
public class CustomProjection : MonoBehaviour {
private void OnEnable(){
@slembcke
slembcke / Projection.cs
Created January 9, 2017 20:24
Custom projection support for Unity.
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class TreesCamera : MonoBehaviour {
private void OnEnable(){
// Optional, only enable the callbacks when in the editor.
if(Application.isEditor){
// These callbacks are invoked for all cameras including the scene view and camera previews.
Camera.onPreCull += ScenePreCull;
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class TreesCamera : MonoBehaviour {
private void OnEnable(){
Camera.onPreRender += PreRender;
Camera.onPostRender += PostRender;
}

96D07E7E-68E6-44EE-97C8-A05F2883C472

FE4D5C14-1CC9-4721-83EF-DBCA2FE452FC

FA85A580-8395-46D7-A5E1-8A1F8282888C

E6B61468-6148-45ED-8496-DBD61F6A5ABB

BF4E00AD-BA79-4EC7-9FA9-38AFE2AEFE55

@slembcke
slembcke / NearlyNearestNeighborFiltering.glsl
Last active December 27, 2020 21:19
Anti-aliased Nearest Neighbor Filtering.
uniform sampler2D texture;
varying vec2 uv;
void main(){
vec2 size = textureSize(texture);
vec2 puv = uv*size;
vec2 hfw = 0.5*fwidth(puv);
vec2 fl = floor(puv - 0.5) + 0.5;
// in the .h file
@interface Foo : Bar {
@public
int _ivar1;
@protected
int _ivar2;
int _property2;
@private
int _ivar3;
@slembcke
slembcke / constraint.rb
Created February 24, 2014 21:12
Custom constraint solver
require 'matrix'
Constraints = Matrix[
[ 1.0, -1.0, 0.0, 1.0, -1.0],
[ 1.0, 1.0, -1.0, 0.0, 0.0],
[ 1.0, -1.0, 0.0, -1.0, 1.0],
]
puts "Constraints: #{Constraints}"
#include <stdlib.h>
#include <stdio.h>
#include <setjmp.h>
#include "jpeglib.h"
extern long image_memory(int numbytes, void *data_ptr);
extern void throw_error(char *filename, char *error);
struct my_error_mgr {