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 & HelpOpenGL and 3D Libraries › Manipulating array values and images displayed
Page Index Toggle Pages: 1
Manipulating array values and images displayed (Read 619 times)
Manipulating array values and images displayed
Dec 16th, 2008, 10:55pm
 
Hi guys, I am fairly new to Processing and am working on a project currently which I have run into a problem. I have arrays which display my PNG images right now. Since they are in 3D space, I use the mouseY location to move the camera in and out.

What I want to do is also tie the mouseY value to the number of images the array displays. I plan on having 4 checkpoints on the mouseY values which change the array display values. What I am having trouble is with the mouseY value having no effect on the number of displayed images whatsoever. I need it to happen dynamically as the user moves the mouse but that is not currently happening. Does OpenGL not support dynamically drawing and erasing elements on the screen?  

Thanks

Here is my code currently:
Quote:

//Base code taken from 'Space Junk' by Ira Greenberg

import processing.opengl.*;

PImage a, b, c, dd;

float ang;


int oillimitOne = 6;
int waterlimitOne = 3;
int treelimitOne = 15;
int landfilllimitOne = 6;

Oil[]oils = new Oil[oillimitOne];
Water[]waters = new Water[waterlimitOne];
Tree[]trees = new Tree[treelimitOne];
Landfill[]landfills = new Landfill[landfilllimitOne];

void setup(){

 size(1024, 768, OPENGL);
 background(0);
 
 a = loadImage("gastank.png");
 b = loadImage("water.png");
 c = loadImage("tree.png");
 dd = loadImage("landfill.png");


     
for (int i = 0; i< oils.length; i++){
   oils[i] = new Oil(int(random(-10, 10)), int(random(-10, 10)),
   int(random(-10, 10)), int(random(-140, 140)), int(random(-140, 140)),
   int(random(-140, 140)));
 }
   
 for (int i = 0; i< waters.length; i++){
   waters[i] = new Water(int(random(-10, 10)), int(random(-10, 10)),
   int(random(-10, 10)), int(random(-140, 140)), int(random(-140, 140)),
   int(random(-140, 140)));
 }
 
  for (int i = 0; i< trees.length; i++){
   trees[i] = new Tree(int(random(-10, 10)), int(random(-10, 10)),
   int(random(-10, 10)), int(random(-140, 140)), int(random(-140, 140)),
   int(random(-140, 140)));
 }
   
  for (int i = 0; i< landfills.length; i++){
   landfills[i] = new Landfill(int(random(-10, 10)), int(random(-10, 10)),
   int(random(-10, 10)), int(random(-140, 140)), int(random(-140, 140)),
   int(random(-140, 140)));
 }


 
}

void draw(){
 background(0);
 fill(200);

   
 pointLight(51, 102, 255, 65, 60, 100);
 pointLight(200, 40, 60, -65, -60, -150);
 
 //raise overall light in scene
 ambientLight(90, 90, 10);

 translate(mouseX/2, height/2, -10*mouseY);
 println(mouseY);
 

 rotateX(radians(ang)/2);

 for (int i = 0; i< oils.length; i++){
   oils[i].drawOil();}
   
 for (int i = 0; i< waters.length; i++){
   waters[i].drawWater();}
   
 for (int i = 0; i< trees.length; i++){
   trees[i].drawTree();}
   
 for (int i = 0; i< landfills.length; i++){
   landfills[i].drawLandfill();}

 //used in rotate function calls above
 ang++;
}

class Oil {

 //properties
 int w, h, d;
 int shiftX, shiftY, shiftZ;
 
//constructor
 Oil(int w, int h, int d, int shiftX, int shiftY, int shiftZ){
   this.w = w;
   this.h = h;
   this.d = d;
   this.shiftX = shiftX;
   this.shiftY = shiftY;
   this.shiftZ = shiftZ;
 }
void drawOil(){
   
   translate(w + shiftX, -h/2 + shiftY, -d/2 + shiftZ);
   image(a, w+shiftX, -h/2 + shiftY);

   rotateY(radians(50));
   rotateX(radians(30));
   rotateZ(radians(25));
 }
}

class Water {

 //properties
 int w, h, d;
 int shiftX, shiftY, shiftZ;
 
//constructor
 Water(int w, int h, int d, int shiftX, int shiftY, int shiftZ){
   this.w = w;
   this.h = h;
   this.d = d;
   this.shiftX = shiftX;
   this.shiftY = shiftY;
   this.shiftZ = shiftZ;
 }
void drawWater(){

   translate(w + shiftX, -h/2 + shiftY, -d/2 + shiftZ);
   image(b, w+shiftX, -h/2 + shiftY);

   rotateY(radians(50));
   rotateX(radians(30));
   rotateZ(radians(25));
 }
}

class Tree {

 //properties
 int w, h, d;
 int shiftX, shiftY, shiftZ;
 
//constructor
 Tree(int w, int h, int d, int shiftX, int shiftY, int shiftZ){
   this.w = w;
   this.h = h;
   this.d = d;
   this.shiftX = shiftX;
   this.shiftY = shiftY;
   this.shiftZ = shiftZ;
 }
void drawTree(){

   translate(w + shiftX, -h/2 + shiftY, -d/2 + shiftZ);
   image(c, w+shiftX, -h/2 + shiftY);

   rotateY(radians(50));
   rotateX(radians(30));
   rotateZ(radians(25));
 }
}

class Landfill {

 //properties
 int w, h, d;
 int shiftX, shiftY, shiftZ;
 
//constructor
 Landfill(int w, int h, int d, int shiftX, int shiftY, int shiftZ){
   this.w = w;
   this.h = h;
   this.d = d;
   this.shiftX = shiftX;
   this.shiftY = shiftY;
   this.shiftZ = shiftZ;
 }
void drawLandfill(){
   
   translate(w + shiftX, -h/2 + shiftY, -d/2 + shiftZ);
   image(dd, w+shiftX, -h/2 + shiftY);

   rotateY(radians(50));
   rotateX(radians(30));
   rotateZ(radians(25));
 }
}
Page Index Toggle Pages: 1