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 › I don't think modelX/Y/Z works. Tell me I'm wrong!
Page Index Toggle Pages: 1
I don't think modelX/Y/Z works. Tell me I'm wrong! (Read 460 times)
I don't think modelX/Y/Z works. Tell me I'm wrong!
Dec 30th, 2008, 5:57am
 
EDIT: I have worked around my problem by only calculating the extents of my objects during the first time through the loop.

----

Please see http://mrfeinberg.com/hilbert/ for a demonstration of my problem.

The idea is to generate a shape without knowing in advance exactly where it is, and then to move the camera around the center of that generated shape. I track "where I am" while drawing the shape, then figure out the centroid of all the places I've been.

Unfortunately, it seems like the Processing 3D model does not cleanly separate "world space" and "camera position". Therefore, once you've positioned the camera, you get completely different values for modelX() and its kin, even if you do the same sequence of affine transforms.

Please, someone who knows better than me, tell me the dopey mistake I'm making. Otherwise I'm going to have to move to some non-free scene graph library and abandon Processing for this project, which I don't want to do. (The hilbert curve thingy is just a test, and is not the project.)
Re: I don't think modelX/Y/Z works. Tell me I'm wr
Reply #1 - Dec 30th, 2008, 11:21am
 
Hi

I'm working on a similar problem and hitting the same snag.
modelX/Y/Z isn't suitable for that but it does work as specified. eg. saves x/y/z during a series of transform.

The issue is that there doesn't seem to be a straight forward way to get coordinates x/y from user input and translate it into x/y/z world space. All the code examples use an arbitrary Z.

the world space x/y/z doesn't change but it's easier to position things in relation to the camera centerX/y/z,
i.e. you get to see things.

I was having dificulty with the camera until I applyed a var c to both camera eye and center coordinates.




void setup(){
 size(200, 200, P3D);
 //noFill();
}

//a=mb+c
float a = 0.0;
float m = 0.0;
float b = 0.0;
float c = 0.0;

void draw(){
 background(204);
 //a=mb+c ->not used
 c = mouseY;
 //b =
 if(mousePressed){
   camera(width/2.0, height/1.0, -height/2.0+c,
   width/2.0, height/2.0, 0.0+c,
   0, -1, 0);
   b = -height/2.0+c;
 }
 else{
   m = b;
   camera(width/2.0, height/2.0, -height/2.0+m,
   width/2.0, height/2.0, 0.0+m,
   0, -1, 0);
 }

 pushMatrix();
 translate(width/2.0, height/2.0, 0);
 box(40);
 popMatrix();
 
 for(int i = 0; i<100; i++){

   line(0, height/2.0, (-height/2.0)+(i*20), width, height/2.0, (-height/2.0)+(i*20));

 }
}

Re: I don't think modelX/Y/Z works. Tell me I'm wr
Reply #2 - Dec 30th, 2008, 7:56pm
 
I have found a workaround: I just calculate the extents of my objects the first time through the draw loop, and everything works fine.

See http://mrfeinberg.com/hilbert/ .
Re: I don't think modelX/Y/Z works. Tell me I'm wr
Reply #3 - Jan 2nd, 2009, 6:30pm
 
unfortunately i think you are right.

i found a bug-ticket for this issue for release 135 (http://dev.processing.org/bugs/show_bug.cgi?id=486), saying its fixed.
but in version 1.01 it works only when NOT using camera(). but I need them both. any idea? (apart of tracking them all manually...)

below modified code form the API documentation:


// sh: camera vars
float ang = 0;
int max = 360;

void setup() {
 size(500, 500, P3D);
 noFill();
}

void draw() {
 background(0);
 
 // sh - added code
 // rotate camera
 float ra = 1500;
 
 float posX;
 float posY = -900;
 float posZ;
 float centX = 0;
 float centY = 130;
 float centZ = 0;
 
 posX = sin( radians(ang) ) * ra;
 posZ = cos( radians(ang) ) * ra;

 camera(posX, posY, posZ, centX, centY, centZ, 0, 1, 0 );

 ang += 0.05;
 ang = ( ang > max ) ? 0 : ang;

 // sh - end added code
 // code from API documentation

 pushMatrix();
 // start at the middle of the screen
 translate(width/2, height/2, -200);    
 // some random rotation to make things interesting
 rotateY(1.0); //yrot);
 rotateZ(2.0); //zrot);
 // rotate in X a little more each frame
 rotateX(frameCount / 100.0);
 // offset from center
 translate(0, 150, 0);

 // draw a white box outline at (0, 0, 0)
 stroke(255);
 box(50);

 // the box was drawn at (0, 0, 0), store that location
 float x = modelX(0, 0, 0);
 float y = modelY(0, 0, 0);
 float z = modelZ(0, 0, 0);
 // clear out all the transformations
 popMatrix();

 // draw another box at the same (x, y, z) coordinate as the other
 pushMatrix();
 translate(x, y, z);
 stroke(255, 0, 0);
 box(50);
 popMatrix();
}
Page Index Toggle Pages: 1