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" SPACESHIP
float zs = 0.1; //accelaration SPACESHIP
float endZS; //accelaration SPACESHIP
float easing = 0.05; //accelaration SPACESHIP
Cubo[] cubos;//CUBES
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*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();
}
}