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 & HelpSyntax Questions › Use of modelX (/Y/Z)
Page Index Toggle Pages: 1
Use of modelX (/Y/Z) (Read 217 times)
Use of modelX (/Y/Z)
Dec 19th, 2008, 8:18pm
 
Hi,

I'm having a bit of problem with trying to keep track of points in a model in a situation where there are multiple translation involved.  Here is a hypothetical project code:

Code:


Arm arm1, arm2;
void setup(){
 size(800,500, P3D);
 arm1 = new Arm(60, 170, 10);
 arm2 = new Arm(160, 170, -10);
 smooth();
}


void draw(){
 background(130);
 strokeWeight(2);
 
 
 drawArmPair(0, 0,color(0,255,0));
 drawArmPair(200, 0,color(0,255,0));
 
 
 // here is the problem
 translate(50,150); // let's say you can't modify this
 drawArmPair(0, 0,color(255,0,0));
 drawArmPair(200, 0,color(255,0,0));

}


void drawArmPair(int x, int y, color c){

pushMatrix();
 translate(x, y);
 stroke(1);
 arm1.draw();
 arm2.draw();
 
 stroke(c);
 popMatrix();
 line(arm1.sx, arm1.sy, arm1.sz, arm2.sx, arm2.sy, arm2.sz);
}


class Arm{
 int x, y, z;
 
 float sx, sy, sz;

 Arm(int x, int y, int z){
   this.x = x;
   this.y = y;
   this.z = z;
 }
 void draw(){
   
   pushMatrix();

   int j = 1;
   float nx = x*j+millis()/10+screenX(10,10);
   float ny = y*j+ millis()/10+100;
   translate(x,y);
   rotateX(map(noise(nx/100 ), 0f, 1f, 0f, TWO_PI));
 
   
   line(0,0, 100, 100);
   
   sx = screenX(100, 100, 0);
   sy = screenY(100, 100, 0);
   sz = screenZ(100, 100, 0);
   popMatrix();
 }

}



I'm trying to show a case where the "model" positions have to be partially restored.  As you can see, the green bar model works fine, but breaks once the models are translated to a different location.


The all colored bars are supposed to be attached to the arms.  I want to use modelX to be able to evaluate the location of the arms that handle the color bars, but I'm not really sure how to go about doing it.

Any suggestion?  Thanks!
Page Index Toggle Pages: 1