We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › texturing a grid of vertices
Page Index Toggle Pages: 1
texturing a grid of vertices (Read 530 times)
texturing a grid of vertices
Feb 20th, 2010, 12:37pm
 
hi,

i'm working on a project where i'd like to deform a map of the united states based on specific statistical information across in the country. essentially, i'd like to increase the altitude of certain areas on the map if certain statistics are higher than others. i'm pretty sure i'll know how to deform then actual map based on my dataset, however i'm having some issues actually creating a mesh and adding the united states image texture onto it. i'm trying to create a grid to texture onto with the following:


Code:
void draw() {
 background(0);
 translate(width / 2, height / 2);
 rotateY(map(mouseX, 0, width, -PI, PI));
 rotateZ(45);
 beginShape();
 stroke(255, 0, 0 );
 for(int i = 0; i < points; i++){
 vertex(-i*2,0, -i*2);
 vertex(i*2,0, -i*2);
 vertex(i*2,0, i*2);
 vertex(-i*2,0, i*2);
 }
 endShape();
}


the result doesn't seem to be producing a grid however.  so i'm wondering how i could start to structure a grid using vertices within a for loop, and also texture it with an image.

thanks.
Re: texturing a grid of vertices
Reply #1 - Feb 21st, 2010, 7:44am
 
I only have the draw method available so I am making some assumptions about what you are doing.

So you have an image of the United States which I will assume you have loaded into a PImage object I will call img and gSize is the size of a grid square.

Inside draw() method
Code:


// Thes will be used to identify which part of the image to use as the
// texture for the quad_strip
float u, deltaU, v, deltaV;
deltaU = 1.0 / nbrCols;
deltaV = 1.0 / nbrRows;
u = 0;
v = 0;
textureMode(NORMAL);

fill(255);
noStroke();

for(int y = 0; y < nbrRows - 1; y++){
  beginShape(QUAD_STRIP);
  texture(img);  // we are using a texture
  u = 0;  // init horz text pos
  for(x = 0; x < nbrCols; x ++){
     vertex(x * gSize, y * gSize, u, v;
     vertex(x * gSize, y * gSize + gSize, u, v + deltaV);
     u += deltaU;
  }
  v += deltaV;
  endShape();
}

Note the code is untested.

I suggest that
nbrColss ~ img width /10
nbrRows ~ img height / 10
gSize ~ 10

You can try different values and use those best for you.





Page Index Toggle Pages: 1