We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all, I'm trying to make a grid of vertices with one image texture. Once I have the image mapped correctly, I am planning on manipulating the individual vertices to create cool effects.
I am having trouble mapping the image, see my code below:
image used http://i.imgur.com/XGx2X7e.jpg
int detail = 50;
PImage img;
int gridx;
int gridy;
void setup() {
size(720, 427, P3D);
img = loadImage("car.jpg");
//textureMode(NORMAL);
stroke(0);
gridx = (width/detail);
gridy = (height/detail);
}
void draw() {
for (int j = 0; j < gridy; j ++) {
beginShape(QUAD_STRIP);
texture(img);
for (int i = 0; i < gridx; i++) {
float u = width/gridx*i; // not sure what to do here
println(u);
vertex( i * detail, j * detail, u, 0 );
vertex( i * detail, (j+1) * detail, u, img.height );
}
endShape();
}
}
Answers
I don't understand
shall the image cover the entire grid or one image per cell?
what happens now with the sketch and what do you want it to happen?
look here:
https://www.processing.org/reference/vertex_.html
your u calculation was right, but you were using the full height of the texture for each row, hence the repetition.
a QUAD_STRIP expects vertices in this order
so the code needs to be something like this:
Thanks Chrisir and koogs. Chrisir: I was looking to map one image to the whole grid -- the way koogs' has it. That diagram is also helpful.
A follow up question: I'm trying to figure out how to make this like a terrain style grid. I have implemented some random numbers to transform the vertex positions, but they don't seem to line up properly.
It's much easier to see when you do noLoop()
That's because the random value for the bottom of one strip needs to be the same as the top of the next, but you're adding random numbers to them.
Try using noise () instead. Or generate ask the numbers first, store them in an array, creat your grid from these.
Good call - thanks