This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//closest point on line | |
//http://paulbourke.net/geometry/pointlineplane/ | |
ofVec3f closestPointOnLine(ofVec3f p, ofVec3f l0, ofVec3f l1 ) | |
{ | |
if(l0 == l1) return ofVec3f(); | |
float u = (((p.x-l0.x) * (l1.x-l0.x)) + ((p.y-l0.y) * (l1.y-l0.y)) + ((p.z-l0.z) * (l1.z-l0.z))) / l1.distanceSquared( l0 ); | |
if( u < 0.0f ) | |
return l0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void exportFbo(ofFbo& _fbo) | |
{ | |
auto path = ofSystemSaveDialog("fbo.png", "save as"); | |
ofShortPixels pixels; | |
_fbo.readToPixels(pixels); | |
ofSaveImage(pixels, path.getPath()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
void ofApp::draw() | |
{ | |
ofEnableAlphaBlending(); | |
//pass 1 | |
glEnable(GL_CULL_FACE); | |
glCullFace(GL_FRONT); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofMain.h" | |
namespace RandomPointsOnMesh | |
{ | |
static float areaOfTriangle(ofVec3f p0, ofVec3f p1, ofVec3f p2) | |
{ | |
return (p2 - p1).cross(p0 - p1).length() * .5; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Mesh2Points.h | |
// | |
// Created by lars berg on 8/1/14. | |
// | |
#pragma once | |
#include "ofMain.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
OlderNewer