Skip to content

Instantly share code, notes, and snippets.

View dwilliamson's full-sized avatar

Don Williamson dwilliamson

View GitHub Profile
@dwilliamson
dwilliamson / LocalStaticHelpers.cpp
Created November 10, 2014 10:46
Local static helpers
// ===============
namespace
{
void Utility(ns::Struct& s)
{
}
}
void ns::PublicAPIFunction(Struct& s)
{
@dwilliamson
dwilliamson / Normal.cpp
Created January 19, 2015 14:55
HLSL 5 fxc output
if (x > y && x > z)
{
x_axis = up;
y_axis = forward;
}
else if (y > z)
{
x_axis = forward;
y_axis = right;
}
@dwilliamson
dwilliamson / gist:902474af1f5c73018218
Created March 27, 2015 12:01
Just somewhere to keep this around
function CreateCubeMesh(scene, side)
{
// Create vertices in the [-1, 1] domain
var cube_geom = CreateCubeGeometry(2, 16);
var vertices = cube_geom.Vertices;
var indices = cube_geom.Indices;
var thickness = 0.15;
for (i in vertices)
@dwilliamson
dwilliamson / HairyBall.js
Last active August 29, 2015 14:18
Continuous tangent field with "hairy ball" problem
//
// Illustration of the "hairy ball" problem
// http://en.wikipedia.org/wiki/Hairy_ball_theorem
//
// Continuous tangent field over the sphere built by blending two
// perpendicular, cylindrical fields.
//
function smoothstep(edge0, edge1, x)
@dwilliamson
dwilliamson / Barycentric.glsl
Last active August 29, 2015 14:19
Simple modification of barycentric co-ordinate calculation for triangle in 3D (original from Real-Time Collision Detection). Premultiply d00, d11, d01 by inv_denom for multiple wins: 1) 12 floats for triangle description (don't store remaining two triangle positions, just store the edge vectors). 2) Triangle is vector-aligned; great for array lo…
vec3 Barycentric(ProbeTriangle tri, vec3 p)
{
// Unpack for readability
vec3 a = tri.a_d01.xyz;
vec3 v0 = tri.v0_d00.xyz;
vec3 v1 = tri.v1_d11.xyz;
float d00 = tri.v0_d00.w;
float d11 = tri.v1_d11.w;
float d01 = tri.a_d01.w;
import winreg
import os
import string
#
# Big list of known SDK versions and their properties
#
# I wrote some automatic discovery code for building all this (300 lines) but it turns
// TODO: Storage allocation failures!!
#pragma once
#include <clcpp/clcpp.h>
//
@dwilliamson
dwilliamson / Cube.glsl
Created July 6, 2015 16:58
Procedural tristrip cube generation
//
// Procedural tristrip cube generation
//
function CreateTriStripCube()
{
var positions = [
0,0,0,
1,0,0,
// All types in one header file
// Interface and storage specified, only, to keep header file size small and easy to parse by the compiler
// Use of multiple containers in a public header requires only this header file be included
// No proliferation of multiple header includes in public header files
//
// Implementation specified in separate header files per type
// Only included in implementation .cpp files that need to use them
// Interface is member-based for convenient intellisense lookup
@dwilliamson
dwilliamson / GUIDGenerator.cpp
Created September 14, 2015 17:56
GUID Generator
namespace core
{
//
// A globally unique identifier with a generator that should allow multiple machines/users
// to never generate the same ID.
//
struct clcpp_attr(reflect) Guid
{
Guid()
: mac_address_hash(0)