Last active
August 28, 2023 08:41
-
-
Save companje/008510d3cec63c09d8bfc124ab26abcc to your computer and use it in GitHub Desktop.
Quads
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
PImage cam, screen; | |
ArrayList<Quad> cam_quads, screen_quads; | |
void setup() { | |
size(1280, 480, P3D); | |
cam = loadImage("vis_200.png"); | |
cam_quads = load_quads("cam_quads.txt"); | |
screen_quads = load_quads("screen_quads.txt"); | |
} | |
void draw() { | |
background(80); | |
noFill(); | |
stroke(255); | |
image(cam, 0, 0); | |
draw_quads(cam_quads); | |
translate(640, 0); | |
draw_quads(screen_quads, cam_quads, cam); | |
} | |
class Quad { | |
int p[] = new int[8]; | |
Quad(String s) { | |
p = int(split(s, " ")); | |
} | |
} | |
void draw_quads(ArrayList<Quad> quads) { | |
beginShape(QUADS); | |
for (Quad q : quads) { | |
for (int i=0; i<8; i+=2) { | |
vertex(q.p[i], q.p[i+1]); | |
} | |
} | |
endShape(); | |
} | |
void draw_quads(ArrayList<Quad> xy_quads, ArrayList<Quad> uv_quads, PImage tex) { | |
beginShape(QUADS); | |
texture(tex); | |
for (int j=0; j<xy_quads.size(); j++) { | |
Quad xy = xy_quads.get(j); | |
Quad uv = uv_quads.get(j); | |
for (int i=0; i<8; i+=2) { | |
vertex(xy.p[i], xy.p[i+1], uv.p[i], uv.p[i+1]); | |
} | |
} | |
endShape(); | |
} | |
ArrayList<Quad> load_quads(String filename) { | |
ArrayList<Quad> quads = new ArrayList(); | |
for (String s : loadStrings(filename)) | |
quads.add(new Quad(s)); | |
return quads; | |
} |
Author
companje
commented
Aug 28, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment