Skip to content

Instantly share code, notes, and snippets.

Avatar
💯
P I X E L S

Tanner Rogalsky TannerRogalsky

💯
P I X E L S
View GitHub Profile
@TannerRogalsky
TannerRogalsky / main.cpp
Created Feb 11, 2018
Emscripten producing invalid JS when unary operator is applied to static const instance property.
View main.cpp
#include <cstdio>
class UnaryTest {
public:
static const UnaryTest STATIC_TEST;
double p;
UnaryTest(double p);
};
@TannerRogalsky
TannerRogalsky / buffer.cpp
Created Apr 7, 2017
Subdivide a polyhedron and buffer it's vertices into a VBO.
View buffer.cpp
template<int32_t N>
void buffer(GLuint *vbos) {
if constexpr(N >= 0) {
const auto vertices = subdivide<N>(indexedVertices, indices);
const auto wireframe = getWireframeGeometry(vertices);
glBindBuffer(GL_ARRAY_BUFFER, vbos[N]);
glBufferData(GL_ARRAY_BUFFER, wireframe.size() * sizeof(Vertex), wireframe.data(), GL_STATIC_DRAW);
buffer<N - 1>(vbos);
}
}
@TannerRogalsky
TannerRogalsky / main.lua
Created Jan 23, 2017
Fast vertex setting in Love using ImageData and the FFI
View main.lua
local num_verts = 100000
local vertices = {}
for i=1,num_verts do
vertices[i] = {0, 0, 0, 0, 255, 255, 255, 255}
end
local ffi = require('ffi')
ffi.cdef[[
typedef struct {
float x, y;
View line.lua
local _PACKAGE = (...):match("^(.+)[%./][^%.]+")
local Line = {}
Line.__index = Line
local Vector = require(_PACKAGE .. ".vector")
function Line.new(x1, y1, x2, y2)
local self = setmetatable({}, Line)
self.origin = Vector(x1, y1)
@TannerRogalsky
TannerRogalsky / generateSphereVertices.lua
Created Jun 24, 2016
Fake 2D Sphere Without A Shader
View generateSphereVertices.lua
local function insertVertices(vertices, vert, ...)
if vert then
table.insert(vertices, vert)
insertVertices(vertices, ...)
end
end
local function createSphereVertex(radius, theta, phi, ox, oy)
local xb = math.cos(phi) * math.cos(theta)
local yb = math.sin(theta)
@TannerRogalsky
TannerRogalsky / genMesh.lua
Created Jun 23, 2016
Generate a circular mesh.
View genMesh.lua
local function genMesh(num_verts, radius)
local verts = {}
local interval = math.pi * 2 / num_verts
for i=1,num_verts do
local phi = i * interval
local x = radius * math.cos(phi)
local y = radius * math.sin(phi)
local u = (x + radius) / (radius * 2)
local v = (y + radius) / (radius * 2)
table.insert(verts, {x, y, u, v})
@TannerRogalsky
TannerRogalsky / map.lua
Created Jan 7, 2016
Load encoded/compressed Tiled data
View map.lua
-- From https://github.com/karai17/Simple-Tiled-Implementation/blob/4ac519dbd5efdc0c6a70c35b9125faebe347772f/map.lua#L217
local ffi = require("ffi")
local function getDecompressedData(data)
local d = {}
local decoded = ffi.cast("uint32_t*", data)
for i=0, data:len() / ffi.sizeof("uint32_t") do
table.insert(d, tonumber(decoded[i]))
end
View stateful_with_proxy.js
Stateful = {
extend: function(klass) {
var currentState = klass.prototype;
var states = {null: currentState};
klass.prototype.gotoState = function(stateName, ...args) {
currentState = states[stateName];
}
klass.addState = function(stateName, state) {
@TannerRogalsky
TannerRogalsky / test1.lua
Created Jan 24, 2015
Action Tracking Format
View test1.lua
-- all timings in bpm
return {
file: 'sounds/music.mp3',
bpm: 100,
players: 2,
actions: [
{
player: 1,
start_time: 1,
View class_test.lua
local Class = setmetatable({
new = function(arg1, arg2, arg3)
local obj = {}
obj.var1 = arg1
obj.var2 = arg2
obj.var3 = arg3
obj.out = function (self, arg)
print(self[arg])
end