Fill() and Transform

edited September 2016 in Library Questions

Hi,why the fill and transform and rotate goes to next shape,although i used popMatrix and pushMatrix?

import peasy.*;
import saito.objloader.*;
import spout.*;

//PrintWriter output;
OBJModel model ;
OBJModel Smodel ;
OBJModel tmpmodel ;

Spout spout;


PeasyCam cam;

float z=0;
float easing = 0.005;
float r;
float k;
int VertCount;
PVector[] Verts;
PVector[] locas;
PVector Mouse;
PVector Mouse2;

int VECS = 600;


void setup()
{
  size(800, 800, P3D);
  frameRate(30);
  noStroke();

  model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
  model.enableDebug();
  model.scale(200);
  model.translateToCenter();


  Smodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
  Smodel.enableDebug();
  Smodel.scale(200);
  Smodel.translateToCenter();


  tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
  tmpmodel.enableDebug();
  tmpmodel.scale(200);
  tmpmodel.translateToCenter();

  //output = createWriter("positions.txt"); 

  cam = new PeasyCam(this, width/2, height/2, 0, 1600);

  spout = new Spout(this);

  spout.createSender("Self");
}



void draw()
{
  background(0);
  lights();



  int VertCount = model.getVertexCount ();
  Verts = new PVector[VertCount];
  locas = new PVector[VertCount];
  r =100;
  k = k + 0.01;


PVector psVerts[] = new PVector[VECS];
PVector psVerts2[]= new PVector[VECS];


  cam.setMouseControlled(false);


  Mouse = new PVector(mouseX-width/2, mouseY-height/2, z);
  Mouse2 = new PVector(width/2 -height/2, z);





  //println(frameCount);
  pushMatrix();




  translate(width/2, height/2, 0);
  rotateY(k);


  for (int i = 0; i < VertCount; i++) {
    //PVector orgv = model.getVertex(i);

    locas[i]= model.getVertex(i);
    Verts[i]= Smodel.getVertex(i);


    //PVector tmpv = new PVector();


    if (frameCount> 100) {



      float randX = noise(randomGaussian());
      float randY = noise(randomGaussian());
      float randZ = noise(randomGaussian());

      PVector Ran = new PVector(randX, randY, randZ);

      //float norX = abs(cos(k)) * randX;
      //float norY = abs(cos(k)) * randY;
      //float norZ = abs(cos(k)) * randZ;









      if ((Verts[i].y > Mouse.y  - r/2 && Verts[i].y < Mouse.y  + r/2 && Verts[i].x > Mouse.x  - r/2 && Verts[i].x < Mouse.x  + r/2 && Verts[i].z > Mouse.z  - 1920/2 && Verts[i].z <  Mouse.z  + 1920/2)||(Verts[i].y > Mouse2.y  - r/2 && Verts[i].y < Mouse2.y  + r/2 && Verts[i].x > Mouse2.x  - r/2 && Verts[i].x < Mouse2.x  + r/2 && Verts[i].z > Mouse2.z  - 1920/2 && Verts[i].z <  Mouse2.z  + 1920/2)) {
        tmpmodel.setVertex(i, locas[i].x, locas[i].y, locas[i].z);
      } else {   



        Verts[i].x+=Ran.x;
        Verts[i].y+=Ran.y;
        Verts[i].z+=Ran.z;

        if (Verts[i].x > width/2 ) {
          Verts[i].x=-width/2;
        } else if (Verts[i].x < -width/2) {
          Verts[i].x=width/2;
        }
        if (Verts[i].y > height/2 ) {
          Verts[i].y=-height/2;
        } else if (Verts[i].y < -height/2) {
          Verts[i].y=height/2;
        }

        if (Verts[i].z < -800/2 ) {  
          Verts[i].z=800/2;
        } else if ( Verts[i].z > 800/2) {
          Verts[i].z=-800/2;
        }
        tmpmodel.setVertex(i, Verts[i].x, Verts[i].y, Verts[i].z);
      }
    }
    // output.println("Verts " + Verts[i] + " locas " +locas[i]);
  }

  pushMatrix();
  rotateY(-k); //-----------------HERE
  //translate(0, 0, 0);
  //rotateY(k); //
  fill(26, 59, 45);
  noStroke();
  beginShape();

  for (int i=0; i < VECS; i+=30 ) {

    psVerts[i] = new PVector (Mouse.x, Mouse.y,Mouse.z);
   psVerts2[i] = new PVector(Mouse2.x, Mouse2.y,Mouse2.z);



  vertex(psVerts[i].x, psVerts[i].y, psVerts[i].z);
  vertex(psVerts2[i].x, psVerts2[i].y, psVerts2[i].z);
  vertex(noise(-width/2,+width/2),noise(-height/2,+height/2),noise(-width/2,+width/2));
  }
  endShape();
  popMatrix();


  pushMatrix();
  rotateY(-k); //-----------------HERE

  translate(Mouse.x, Mouse.y, Mouse2.z+width/2);
  rotateY(k); //-------------AND HERE

  fill(255, 0, 0);

  ellipse(0, 0, 10, 10);
  popMatrix();




  pushMatrix();
  rotateY(-k); //-----------------HERE
  fill(255, 0, 0);
  translate(Mouse2.x, Mouse2.y, Mouse2.z+width/2);
  rotateY(k); //-------------AND HERE


  ellipse(0, 0, 10, 10);
  popMatrix();


  noStroke();

  tmpmodel.draw();

  popMatrix();



  pushMatrix();
  translate(width/2, height/2, 0);
  rotateY(k);
  noFill();

  stroke(255);
  strokeWeight(7);
  box(width, height, 800);
  popMatrix();
  //output.flush(); // Writes the remaining data to the file
  //output.close(); // Finishes the file
  //saveFrame();
  println(z);

  spout.sendTexture();
}

void keyPressed() {
  if (keyCode == UP) {
    z++;
  }
  if (keyCode == DOWN) {
    z--;
  }
}

Answers

Sign In or Register to comment.