Skip to content

Instantly share code, notes, and snippets.

View mazbox's full-sized avatar

Marek Bereza mazbox

View GitHub Profile
@mazbox
mazbox / gist:2724338
Created May 18, 2012 09:46
line-line intersection in 3d for openframeworks
ofVec3f utils::lineLineIntersection(ofVec3f p1, ofVec3f p2, ofVec3f p3, ofVec3f p4) {
ofVec3f pa, pb;
utils::lineLineIntersectSegment(p1,p2,p3,p4,pa,pb);
return (pa+pb)/2.f;
}
// from the bourkster.
bool utils::lineLineIntersectSegment(ofVec3f p1, ofVec3f p2, ofVec3f p3, ofVec3f p4, ofVec3f &pa, ofVec3f &pb) {
@mazbox
mazbox / gist:2910777
Created June 11, 2012 15:48
Openframeworks Line Equation class
class LineEquation {
public:
float m;
float c;
void setFrom2Points(ofVec2f a, ofVec2f b) {
ofVec2f g = b - a;
float m = g.y / g.x;
void tricks::gl::effects::Bloom::end() {
output.end();
out1.begin();
ofClear(0, 0, 0, 255);
// convolution 1
shader.begin();
shader.setUniformTexture("tDiffuse", output.getTextureReference(0), 0);
shader.setUniform2f("uImageIncrement", blurX.x*ofGetWidth(), blurX.y*ofGetHeight());
/**
* Bloom.cpp
*
* Created by Marek Bereza on 05/10/2011.
*/
#include "Bloom.h"
void tricks::gl::effects::Bloom::setup(bool drawToFbo) {
this->drawToFbo = drawToFbo;
blurX = ofVec2f( 0.001953125, 0.0 );
@mazbox
mazbox / gist:3313248
Created August 10, 2012 10:26
unrolled normalized penner equations
#ifndef PI
# define PI 3.14159265358979
#endif
inline float easeInBack(float t) {
float s = 1.70158f;
return t*t*((s+1)*t - s);
}
@mazbox
mazbox / gist:3742083
Created September 18, 2012 08:43
Midi to Frequency, Frequency to Midi, stolen from Puredata + freq to note name
float mtof(float f)
{
return (8.17579891564 * exp(.0577622650 * f));
}
float ftom(float f)
{
return (17.3123405046 * log(.12231220585 * f));
}
@mazbox
mazbox / gist:4724446
Last active December 12, 2015 05:48
How to bilinear interpolate a quad
ofVec2f rowCols[5][5];
ofVec2f texz[5][5];
int i = 0;
int j = 0;
for(float xx = 0; xx <= 1; xx += 0.25) {
// here's the meat
ofVec2f p0_p1 = quad[0]*xx + quad[1]*(1.f-xx);
ofVec2f p4_p3 = quad[2]*xx + quad[3]*(1.f-xx);
@mazbox
mazbox / gist:4724476
Created February 6, 2013 17:59
Given a midi note index, get a note in the scale.
#define PENTATONIC 2
#define CHROMATIC 1
#define WHOLE 3
#define MAJOR 4
#define MINOR 0
@mazbox
mazbox / gist:4724484
Created February 6, 2013 18:00
Convert a midi note to speed (1 is original speed, 0.5 would be an octave lower, 2, an octave higher etc.)
float midiNoteToSpeed(int midiNote, int originalNote) {
return pow(2, (midiNote-originalNote)/12.f);
}
#include "LiveAudio.h"
#include <math.h>
#include <stdlib.h>
class MyLiveAudio : public LiveAudio {
public:
float random() {
return (rand() %10000) / 5000.f - 1.f;
}