Skip to content

Instantly share code, notes, and snippets.

@joeld42
joeld42 / gist:3baf9c3a797de83adb22
Created September 29, 2015 21:07
old crufty ear clipping
bool ccwN( sgVec2 dir1, sgVec2 dir2 ) {
return (dir1[0]*dir2[1] - dir2[0]*dir1[1]) > 0;
}
bool ccw( sgVec2 dir1, sgVec2 dir2 ) {
sgNormalizeVec2( dir1 );
sgNormalizeVec2( dir2 );
return ccwN(dir1,dir2);
}
@joeld42
joeld42 / gist:c8dce66eb4b893cac0f1
Created November 3, 2015 20:10
zbuffer vs depth sorting examples for Luxe
import luxe.Input;
import luxe.Color;
import phoenix.geometry.CircleGeometry;
// NOTE: Using depth sort is reccomended, but if you want to use the
// zbuffer in addition (e.g. to mix with custom GL render passes) this
// is how to do it
//
// Add this to the 'build' section of your project.flow file
@joeld42
joeld42 / gist:74f67cde97a789467a2f681961b89c27
Created April 12, 2016 23:42
C Allocator that tracks alloc size
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
typedef struct
{
size_t alloc_size;
} block_header;
@joeld42
joeld42 / TK_FootStepController.cs
Created August 23, 2016 05:34
Simple Footstep controller for mechscale game
using UnityEngine;
using System;
using System.Collections;
// This moves a node to follow "stepGoal" in a foot step like manner. stepGoal is
// typically an empty parented to your model that sits on the ground and is offset (left
// or right) from the center of mass.
// This just moves the foot, a separate IK controller is needed to follow wiht the legs
@joeld42
joeld42 / gist:4a5978c12fcbe26af5dc5d9bab344ab1
Created April 11, 2017 21:10
How to make a console for printfs in windows....
#ifndef NDEBUG
AllocConsole();
SetConsoleTitle( L"console window title" );
freopen("CONOUT$", "w", stdout );
#endif
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/FSEvents.framework/Versions/A/Headers/FSEvents.h
@joeld42
joeld42 / k_means.py
Created November 15, 2017 06:54
Simple brute-force k-means palette quantization
# Slow, bad K-Means image quantization.
# This code is in the public domain.
import os, sys
import random
from PIL import Image, ImageDraw
# Doesn't seem to get much better after this, YMMV...
@joeld42
joeld42 / raygui_mouse.c
Created August 17, 2018 21:14
RayGUI Mouse Events
bool g_isMouseDown;
float g_mouseButtonPrevPressTime;
float g_mouseButtonLastPressTime;
Vector2 g_mouseDownPos;
Vector2 g_mousePos;
bool g_isDragging = false;
// Frame mouse events
bool _isDragStarted = false;
@joeld42
joeld42 / cgincWatcher.py
Created October 26, 2018 19:58
cginclude watcher script for editing unity shaders
#!/usr/bin/env python
# CGInclude Watcher
# Joel Davis (joeld42@gmail.com, @joeld42 on Twitter)
#
# Usage: Run this from a directory where you have shaders.
#
# Use at your own risk (and use an editor that properly handles
# open files being modified by another program).
#
@joeld42
joeld42 / thread.cpp
Created April 8, 2019 17:30
Example threading in c++
// c++ -std=c++11 thread.cpp -o thread && ./thread
#include <iostream>
#include <algorithm>
#include <vector>
#include <thread>
class TraceTile
{
public:
int tileNum = 0;