Skip to content

Instantly share code, notes, and snippets.

@cie
Last active June 4, 2020 10:48
Show Gist options
  • Save cie/276f7450611eead1425cbed8e5a12d71 to your computer and use it in GitHub Desktop.
Save cie/276f7450611eead1425cbed8e5a12d71 to your computer and use it in GitHub Desktop.
Processing calculate inverse of screenX/screenY (WIP, not working perfectly)
void mouseDragged() {
if (mouseButton == RIGHT) {
float z = screenZ(k.x,k.y,k.z);
println(z);
PMatrix3D proj = ((PGraphics3D) this.getGraphics()).projection;
PMatrix3D transform = ((PGraphics3D) this.getGraphics()).modelview;
PMatrix3D a = transform.get();
PMatrix3D b = proj.get();
a.invert();
b.invert();
PVector m = new PVector((float)mouseX/width*2-1, (float)(height-mouseY)/height*2-1, 1);
PVector aa = a.mult(b.mult(m, null), null);
PVector pm = new PVector((float)pmouseX/width*2-1, (float)(height-pmouseY)/height*2-1, 1);
PVector paa = a.mult(b.mult(pm, null), null);
PVector d = aa.sub(paa);
println(k, aa, paa);
k = k.add(d.mult(z));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment