Skip to content

Instantly share code, notes, and snippets.

View bit-hack's full-sized avatar

Aidan Dodds bit-hack

View GitHub Profile
@bit-hack
bit-hack / raster.cpp
Last active May 10, 2018 23:55
very simple rasterizer
#pragma once
#include <cstdint>
#include <algorithm>
struct float2 {
float x, y;
};
struct float3 {
@bit-hack
bit-hack / glmatrix.h
Last active May 5, 2018 22:41
An implementation of the old OpenGL matrix stack.
#pragma once
#include <cassert>
#include <array>
#include <cmath>
#include <intrin.h>
#include "GL.h"
#include "math.h"
@bit-hack
bit-hack / sdl_app.cpp
Created April 30, 2018 16:49
A very simple SDL app framework
#include <cassert>
#include <cstdint>
#define _SDL_main_h
#include <SDL/SDL.h>
struct app_t {
app_t() : _screen(nullptr), _active(false) {}
@bit-hack
bit-hack / tri_rect.cpp
Created April 25, 2018 22:30
triangle rect overlap test
#define _SDL_main_h
#include <SDL/SDL.h>
#include <assert.h>
#include <stdint.h>
#include <array>
struct coord_t {
float x, y;
@bit-hack
bit-hack / fixed.cpp
Created April 23, 2018 23:15
float to fixed point 16:16
#include <cstdint>
#include <cstring>
// float to int
int32_t float_to_int(float myfloat) {
uint32_t fint = 0;
memcpy(&fint, (void*)&myfloat, 4);
constexpr uint32_t mask_fract = (1u << 23) - 1;
const uint32_t fract = (fint & mask_fract) | (1u << 23);
const uint32_t fexpn = (fint >> 23) & 0xff;
@bit-hack
bit-hack / obj_to_c.py
Created April 19, 2018 23:17
.obj to .c file converter
import sys
class ObjGroup(object):
def __init__(self, name, v_base, vt_base):
self._name = name
self._mtl = ''
self._vertex = []
self._uv = []
@bit-hack
bit-hack / raster.cpp
Created April 9, 2018 12:15
Scanline triangle rasterization experiment
#define _SDL_main_h
#include <SDL/SDL.h>
#include <assert.h>
#include <stdint.h>
#include <array>
struct coord_t {
float x, y;
@bit-hack
bit-hack / pearson.cpp
Created March 16, 2018 14:21
PearsonHash
#include <cstdint>
#include <array>
uint64_t PearsonHash(const uint8_t *x, size_t len)
{
static const std::array<uint8_t, 256> T = {
// 0-255 shuffled in any (random) order suffices
98, 6, 85,150, 36, 23,112,164,135,207,169, 5, 26, 64,165,219,
61, 20, 68, 89,130, 63, 52,102, 24,229,132,245, 80,216,195,115,
90,168,156,203,177,120, 2,190,188, 7,100,185,174,243,162, 10,
@bit-hack
bit-hack / fo1_lz77.c
Created February 8, 2018 10:36
Fallout 1 LZ decompressor
#include <stdint.h>
#include <stddef.h>
size_t lz77_decode(const uint8_t *src, uint8_t *dst) {
// size of ring buffer
static const uint32_t N = 4096;
// upper limit for match_length
static const uint32_t F = 18;
// wrap mask for ring buffer
@bit-hack
bit-hack / iso_xform.c
Created January 15, 2018 00:08
isometric transforms
// convert world to screen
vec2f_t to_screen(const vec3f_t &p) const {
return vec2f_t{
2.f * (p.x - p.y),
p.x + p.y - p.z,
};
}
// convert screen to world