Created
July 28, 2018 15:14
-
-
Save behreajj/18900b43c48a8a055a09417c66df7247 to your computer and use it in GitHub Desktop.
Contain UVs
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 setup() { | |
/* ... */ | |
containUvs(txtr, width, height); | |
} | |
void containUvs(PImage txtr, float w, float h) { | |
float wc = txtr.width; | |
float hc = txtr.height; | |
float sketchAspect = w / h; | |
float invSketchAspect = 1.0 / sketchAspect; | |
float txtrAspect = wc / hc; | |
float invTxtrAspect = hc / wc; | |
float wf = sketchAspect * invTxtrAspect; | |
float hf = invSketchAspect * txtrAspect; | |
boolean txtrWide = wc > hc; | |
boolean sketchWide = w > h; | |
u = txtrWide ? sketchWide ? | |
wf : 1.0 : sketchWide ? wf : 1.0; | |
v = txtrWide ? sketchWide ? | |
1.0 : hf : sketchWide ? 1.0 : hf; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment