Skip to content

Instantly share code, notes, and snippets.

@mazbox
Last active December 12, 2015 05:48
Show Gist options
  • Save mazbox/4724446 to your computer and use it in GitHub Desktop.
Save mazbox/4724446 to your computer and use it in GitHub Desktop.
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);
j = 0;
for(float yy = 0; yy <= 1; yy += 0.25) {
ofVec2f p = p0_p1 * yy + p4_p3 * (1.f - yy);
rowCols[i][j] = p;
texz[i][j] = ofVec2f(xx, yy);
j++;
}
i++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment