Skip to content

Instantly share code, notes, and snippets.

@hclarke
hclarke / recursive_sequences_audio.c
Created Nov 13, 2017
making audio from recursive sequences
View recursive_sequences_audio.c
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#include <string.h>
#include <math.h>
void putu32(FILE* f, uint32_t x) {
for(int i = 0; i < 4; ++i) {
putc(x&0xFF, f);
View VAO with index
#include <iostream>
#include <math.h>
#if ( (defined(__MACH__)) && (defined(__APPLE__)) )
#include <stdlib.h>
#include <OpenGL/gl.h>
#include <GLUT/glut.h>
#include <OpenGL/glext.h>
#else
#include <stdlib.h>
#include <GL/glew.h>
View VAOs sharing VBOs
#include <iostream>
#include <math.h>
#if ( (defined(__MACH__)) && (defined(__APPLE__)) )
#include <stdlib.h>
#include <OpenGL/gl.h>
#include <GLUT/glut.h>
#include <OpenGL/glext.h>
#else
#include <stdlib.h>
#include <GL/glew.h>
View BehaviourTrees.cs
protected delegate State State(bool? prev);
protected readonly State PASS = x => PASS;
protected readonly State FAIL = x => FAIL;
protected readonly State TICK = x => TICK;
Stack<State> stateStack = new Stack<State>();
protected abstract State GetBaseState(); //put your behaviour here
protected void Update() {
bool? prev = null;
if(stateStack.Count == 0) stateStack.Push(GetBaseState());
@hclarke
hclarke / NFA.rs
Created Mar 5, 2017
nondeterministic finite automata implementation
View NFA.rs
#![allow(dead_code)]
use std::collections::{HashMap,HashSet};
struct NFA {
state_count : usize, //0 is start state, -1 is accept
alphabet : HashMap<char, HashMap<i64, HashSet<i64>>>,
empty_transitions : HashMap<i64, HashSet<i64>>,
}
@hclarke
hclarke / Swizzle.cs
Created Sep 8, 2016
Swizzle extension methods for Unity
View Swizzle.cs
/*
Copyright (c) 2016 Harrison Clarke
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE U
@hclarke
hclarke / RandomThings.cs
Created Oct 28, 2015
random points on meshes
View RandomThings.cs
public class RandomThings {
public void CalculateRandomPointsOnMeshes(MeshFilter[] meshFilters, Vector3[] dst, Vector3? direction) {
//find all the meshes
float weight = 0;
foreach (var filter in meshFilters) {
var mesh = filter.sharedMesh;
var vs = mesh.vertices;
for(int i = 0; i < vs.Length; ++i) {
vs[i] = filter.transform.TransformPoint(vs[i]);
View alignmentof
#include <cstdio>
template<typename T>
size_t __alignmentof() {
struct padded { char padding; T value; };
return (size_t)(&(((padded*)0)->value)); //offsetof
}
#define alignmentof(T) __alignmentof<T>()
#define p(T) printf("for %s: size=%d, alignment=%d\n", #T, (int)sizeof(T), (int)alignmentof(T))
@hclarke
hclarke / Swizzle.cs
Last active Dec 19, 2019
swizzle operators for unity
View Swizzle.cs
using UnityEngine;
public static class Swizzle {
public static Vector2 xx(this Vector2 v) {
return new Vector2(v.x, v.x);
}
public static Vector2 xy(this Vector2 v) {
return new Vector2(v.x, v.y);
}
public static Vector2 yx(this Vector2 v) {
View .gitignore
*.suo
*.sln
*.unityproj
*.csproj
/Library
/obj
/Temp
You can’t perform that action at this time.