Skip to content

Instantly share code, notes, and snippets.

View mortennobel's full-sized avatar

Morten Nobel-Jørgensen mortennobel

View GitHub Profile
@mortennobel
mortennobel / Event.h
Last active July 3, 2018 14:46
C++11 Observer Version 2
//
// Event.h
//
// Created by Morten Nobel-Jørgensen on 8/18/13.
// Copyright (c) 2013 morten. All rights reserved.
// Open Source under New BSD License (http://opensource.org/licenses/BSD-3-Clause)
#pragma once
#include <iostream>
@mortennobel
mortennobel / plasma.c
Created October 17, 2013 06:57
plasma effect (from Unity's RenderingPluginExample42)
// Simple oldskool "plasma effect", a bunch of combined sine waves
// input x,y (uv-coordinates), t (time)
int vv = int(
(127.0f + (127.0f * sinf(x/7.0f+t))) +
(127.0f + (127.0f * sinf(y/5.0f-t))) +
(127.0f + (127.0f * sinf((x+y)/6.0f-t))) +
(127.0f + (127.0f * sinf(sqrtf(float(x*x + y*y))/4.0f-t)))
) / 4;
@mortennobel
mortennobel / drand48.c
Created January 28, 2014 10:24
drand48() and srand48(long) on windows. (based on Freebsd: http://fxr.watson.org/fxr/ident?v=FREEBSD-LIBC;im=bigexcerpts;i=_dorand48 )
#define RAND48_SEED_0 (0x330e)
#define RAND48_SEED_1 (0xabcd)
#define RAND48_SEED_2 (0x1234)
#define RAND48_MULT_0 (0xe66d)
#define RAND48_MULT_1 (0xdeec)
#define RAND48_MULT_2 (0x0005)
#define RAND48_ADD (0x000b)
unsigned short _rand48_seed[3] = {
@mortennobel
mortennobel / ascii-2d.cpp
Last active August 29, 2015 13:56
ASCII visualization (used for debugging 2d scalar fields)
#include <string>
#include <array>
#include <algorithm>
#include <functional>
using namespace std;
// assumes that values returned by data is normalized between 0.0 and 1.0
string get_grayscale_image(int width, int height, function<float(int,int)> data){
const int size = 10;
@mortennobel
mortennobel / floatingpoint.h
Last active August 29, 2015 14:00
almostEqualFloatingpoint
// from https://code.google.com/p/googletest/source/browse/trunk/include/gtest/internal/gtest-internal.h
#pragma once
#include <ctype.h>
#include <float.h>
#include <string.h>
#include <iomanip>
#include <limits>
#include <set>
@mortennobel
mortennobel / ObjFile.cpp
Last active August 29, 2015 14:01
Simple Obj File Loader
//
// Created by Morten Nobel-Jørgensen on 06/05/14.
// Copyright (c) 2014 Morten Nobel-Joergensen. All rights reserved.
//
#include "ObjFile.h"
#include <fstream>
#include <sstream>
@mortennobel
mortennobel / sdl.cpp
Created May 13, 2014 15:41
OS/X SDL2 Test
#include <stdio.h>
#include <stdlib.h>
/* If using gl3.h */
/* Ensure we are using opengl's core profile only */
#define GL3_PROTOTYPES 1
#include <OpenGL/gl3.h>
#include <iostream>
#include <SDL2/SDL.h>
@mortennobel
mortennobel / MCSpacePartition.cs
Created May 21, 2014 08:58
Simple space partition algorithm which stores two Z planes and swaps between these two planes
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// Simple space partition algorithm which stores two Z planes and swaps between these two planes
/// </summary>
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class TRIANGLE {
public Vector3[] p = {Vector3.zero,Vector3.zero,Vector3.zero};
}
public class GRIDCELL {
public Vector3[] p = {Vector3.zero,Vector3.zero,Vector3.zero,Vector3.zero,Vector3.zero,Vector3.zero,Vector3.zero,Vector3.zero};
@mortennobel
mortennobel / timer.cpp
Last active October 30, 2016 19:52
C++11 timer
#include <iostream>
#include <chrono>
using namespace std;
// Based on http://stackoverflow.com/a/5524138/420250
int main()
{
typedef std::chrono::high_resolution_clock Clock;
using FpMilliseconds = std::chrono::duration<float, std::chrono::milliseconds::period>;