Skip to content

Instantly share code, notes, and snippets.

View larsberg's full-sized avatar
💭
Big up to my github brethren

Lars Berg larsberg

💭
Big up to my github brethren
View GitHub Profile
@larsberg
larsberg / getWingedEdges.js
Created March 23, 2016 17:51
returns an edge to face map for a THREE geometry. make sure the vertices are merged before hand
'use strict'
var getWingedEdges = function( g ){
var edgeMap = {};
// find the edges
function getEdgeKey( i0, i1 ){
return Math.min(i0, i1) + '_' + Math.max(i0, i1);
}
@larsberg
larsberg / git-overwrite-branch.sh
Created October 27, 2015 18:59 — forked from brev/git-overwrite-branch.sh
Git overwrite branch with another branch
# overwrite master with contents of seotweaks branch (seotweaks > master)
git checkout seotweaks # source name
git merge -s ours master # target name
git checkout master # target name
git merge seotweaks # source name
// 1D gaussian kernel
// pretty much ripped from here: http://www.apileofgrains.nl/blur-filters-c/
vector<float> gaussianKernel( int radius, float weight = 1.)
{
int mem_amount = (radius*2)+1;
vector<float> kernel( (radius*2) + 1 );
float twoRadiusSquaredRecip = 1.0 / (2.0 * radius * radius);
float sqrtTwoPiTimesRadiusRecip = 1.0 / (sqrt(2.0 * PI) * radius);
@larsberg
larsberg / createOFGeometries
Last active August 29, 2015 14:08
OF create geometries
static void makeScreenQuad(ofMesh& m, float w=2, float h=2)
{
w *= .5;
h *= .5;
m.clear();
m.addVertex(ofVec3f(-w,-h,0));
m.addVertex(ofVec3f( w,-h,0));
m.addVertex(ofVec3f( w, h,0));
m.addVertex(ofVec3f(-w, h,0));
@larsberg
larsberg / pointOnSphere
Last active August 29, 2015 14:08
get ofVec3f on sphere using
//theta in [0,TWO_PI), phi in [0,PI], and where radius in [0,infty)
static ofVec3f pointOnSphere(float theta, float phi, float radius = 50)
{
ofVec3f p;
p.x = radius * cos(theta) * sin(phi);
p.y = radius * cos(phi);
p.z = radius * sin(theta) * sin(phi);
return p;
@larsberg
larsberg / Mesh2Points.h
Created August 4, 2014 20:49
evenly distributed random points on a mesh
//
// Mesh2Points.h
//
// Created by lars berg on 8/1/14.
//
#pragma once
#include "ofMain.h"
@larsberg
larsberg / RandomPointsOnMesh
Last active August 29, 2015 14:04
Evenly distributed randome points on an ofMesh
#pragma once
#include "ofMain.h"
namespace RandomPointsOnMesh
{
static float areaOfTriangle(ofVec3f p0, ofVec3f p1, ofVec3f p2)
{
return (p2 - p1).cross(p0 - p1).length() * .5;
@larsberg
larsberg / Svg2Mesh
Created August 1, 2014 21:53
OF svg to ofMesh
static void addSvgToMesh(string dir, ofMesh& m)
{
ofxSVG svg;
svg.load(dir);
for ( auto i=0; i<svg.getNumPath(); i++ )
{
auto& path = svg.getPathAt(i);
path.simplify();
@larsberg
larsberg / OFSimpleCullExample
Last active June 2, 2017 11:56
simple culling example for openframeworks
...
void ofApp::draw()
{
ofEnableAlphaBlending();
//pass 1
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
if (!document.styleSheets.length) document.head.appendChild(document.createElement('style'));
var sheet = document.styleSheets[document.styleSheets.length - 1];
var rules = {};
function cssRule(selector, styles) {
var index;
if (selector in rules) {
index = rules[selector];
sheet.deleteRule(index);
} else {
index = rules[selector] = sheet.cssRules.length;