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.
Index › Can´t get matrix position
 Pages: 1
 Can´t get matrix position (Read 2274 times)
 ginji Can´t get matrix position May 25th, 2010, 4:19am   Hello!I modity a original code that I found on openprocessing.org, but now I've some problems. I want to get de x and y position from the matrix to, after that, intersect the spaceship with the cubes. But I can´t get anything.If anyone understand what is the resolution, i'll be very grateful! Code:```PMatrix3D matrix;float p = 10; //"size" SPACESHIPfloat zs = 0.1; //accelaration SPACESHIPfloat endZS; //accelaration SPACESHIPfloat easing = 0.05; //accelaration SPACESHIPCubo[] cubos;//CUBESvoid setup(){  size(800,600,P3D);  noStroke();  cursor(CROSS);    //call CUBES  cubos = new Cubo[1000];    for (int i = 0; i < cubos.length; i++ ) {    cubos[i] = new Cubo(random(-3000,3000),random(-3000,3000),random(0,50));  }    matrix = new PMatrix3D();  // this is a hack for 1.0.9  ((PGraphics3D)g).cameraNear = -8;}void draw(){  background(230);  //LIGHT  directionalLight(126, 126, 126, 0, 0, -1);  ambientLight(150, 150, 150);    //accelaration SPACESHIP  endZS += 0.001;  zs = zs + (endZS - zs)*easing;  // scene location -- note the z is the camera offset  translate(width/2,height*3/5.95,(height/2)/tan(PI/6));  // move a step (-1 in Z = into the scene)  matrix.translate(0,0,-zs);  // rotate according to the current mouse position  matrix.rotateY( 0.0001 * (width/2-mouseX) );  PMatrix3D inv = new PMatrix3D(matrix);  inv.invert();  applyMatrix(inv);      pushMatrix();  applyMatrix(matrix);    translate(0, 20, -40);  spaceship();  popMatrix();    //CUBES  translate(0,-50,0);  for (int i = 0; i < cubos.length; i++ ) {    cubos[i].display();  }}void keyPressed(){  matrix = new PMatrix3D();  println(matrix.get());}void spaceship(){  beginShape(TRIANGLES);  fill(92,201,206);  vertex(-p, 0,0);  vertex(p, 0, 0);  vertex(0, 0, p-30);  fill(92,201,206);  vertex(0, -p+5, 0);  vertex(p, 0, 0);  vertex(0, 0, p-30);  fill(92,201,206);  vertex(0, -p+5, 0);  vertex(-p, 0, 0);  vertex(0, 0, p-30);  fill(92,201,206);  vertex(0, -p+5, 0);  vertex(-p, 0, 0);  vertex(p, 0, 0);  endShape(CLOSE);} ``` Code:```class Cubo {    float x,z;  float s;     //size CUBES    Cubo(float tempX, float tempZ, float tempS) {    x = tempX;    z = tempZ;    s = tempS;  }    void display() {    fill(242,118,56);        pushMatrix();    translate(x,65-(s/2),z);    box(10+s);    popMatrix();  }} ```
 ginji Re: Can´t get matrix position Reply #1 - May 30th, 2010, 4:21pm   Finally I find a way to get de position of the matrix with this: Code:```  PMatrix3D mp = (PMatrix3D)getMatrix();  mx = mp.m03;  my = mp.m13;  mz = mp.m23; ```Now I have this: Code:```PMatrix3D matrix;float p = 10; //"size" SPACESHIPfloat zs = 0.1; //accelaration SPACESHIPfloat endZS; //accelaration SPACESHIPfloat easing = 0.05; //accelaration SPACESHIPCubo[] cubos;//CUBESfloat mx;float my;float mz;void setup(){  size(800,600,P3D);  noStroke();  cursor(CROSS);    //call CUBES  cubos = new Cubo[1000];    for (int i = 0; i < cubos.length; i++ ) {    cubos[i] = new Cubo(random(-3000,3000),random(-3000,3000),random(0,50));  }    matrix = new PMatrix3D();  // this is a hack for 1.0.9  ((PGraphics3D)g).cameraNear = -8;}void draw(){  background(230);  //LIGHT  directionalLight(126, 126, 126, 0, 0, -1);  ambientLight(150, 150, 150);    //accelaration SPACESHIP  endZS += 0.001;  zs = zs + (endZS - zs)*easing;  // scene location -- note the z is the camera offset  translate(width/2,height*0.7,(height/2)/tan(PI/6));  // move a step (-1 in Z = into the scene)  matrix.translate(0,0,-zs);  // rotate according to the current mouse position  matrix.rotateY( 0.0001 * (width/2-mouseX) );  PMatrix3D inv = new PMatrix3D(matrix);  inv.invert();  applyMatrix(inv);      pushMatrix();  applyMatrix(matrix);    translate(0, 20, -260);  spaceship();  popMatrix();    //CUBES  for (int i = 0; i < cubos.length; i++ ) {    cubos[i].display();  }    PMatrix3D mp = (PMatrix3D)getMatrix();  mx = mp.m03;  my = mp.m13;  mz = mp.m23;    println("mx: " + mx);  println("my: " + my);  println("mz: " + mz);  }void keyPressed(){  matrix = new PMatrix3D();}void spaceship(){  beginShape(TRIANGLES);  fill(92,201,206);  vertex(-p, 0,0);  vertex(p, 0, 0);  vertex(0, 0, p-30);  fill(92,201,206);  vertex(0, -p+5, 0);  vertex(p, 0, 0);  vertex(0, 0, p-30);  fill(92,201,206);  vertex(0, -p+5, 0);  vertex(-p, 0, 0);  vertex(0, 0, p-30);  fill(92,201,206);  vertex(0, -p+5, 0);  vertex(-p, 0, 0);  vertex(p, 0, 0);  endShape(CLOSE);} ```But now, I can't use this values to intersect the spaceship (matrix) with the cubes.I'm trying with this code in cube's class but the intersection isn't correctly: Code:```  if (x >= mx-300 && x <= mx+300 && z >= mz-300 && z <= mz+300){    f = color (24,240,10);  } else {    f = color (242,118,56);  } ```Bye!
 Pages: 1