Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

reset position if inside shape

$
0
0

hello,again,i have made this code,with a 3d model,the model starts dismorph after 100 frames.I have a box shape that is moved with mouse,i want when ever the vertices be inside the box,to reset their position to the original position,and reconstruct the model,while the others dismorph. Always resetting the position when they are in the box,and move when they are not.Can anyone help me.Until now what it happens,is that when the vertices are inside the box they stop moving.

Thanks in Advance

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


OBJModel model ;
OBJModel tmpmodel ;

PeasyCam cam;

float easing = 0.005;
float r;
float k =0.00001;
int VertCount;
PVector[] Verts;
PVector Mouse;

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

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

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



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



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

  int VertCount = model.getVertexCount ();
  PVector[] Verts = new PVector[VertCount];
  PVector[] locas = new PVector[VertCount];
  float r =80;
  PVector Mouse = new PVector(mouseX-width/2, mouseY-height/2, 0);


  cam.setMouseControlled(true);










  //println(frameCount);
  pushMatrix();
  translate(width/2, height/2, 0);



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


    Verts[i]= model.getVertex(i);
    arrayCopy(Verts, locas);
    //PVector tmpv = new PVector();
    if (frameCount> 100) {



      float randX = random(-5, 5);
      float randY = random(-5, 5);
      float randZ = random(-5, 5);

      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].x > Mouse.x  - r/2 && Verts[i].x < Mouse.x  + r/2) {
        if (Verts[i].x > Mouse.y  - r/2 && Verts[i].x < Mouse.y  + r/2) {
          if (Verts[i].x > Mouse.z  - r/2 && Verts[i].x <  Mouse.z  + r/2) {


            arrayCopy(locas, Verts);
          }
        }
      } 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) {
          Verts[i].x+=-Ran.x;
        }
        if (Verts[i].y > height/2 || Verts[i].y < -height/2) {
          Verts[i].y+=-Ran.y;
        }
        if (Verts[i].z < -800/2 || Verts[i].z > 800/2) {
          Verts[i].z+=-Ran.z;
        }
      }
      tmpmodel.setVertex(i, Verts[i].x, Verts[i].y, Verts[i].z);
    }
    k+=0.0001;
  }

  pushMatrix();
  translate(Mouse.x, Mouse.y, Mouse.z);
  noFill();
  stroke(255);
  box(r);
  popMatrix();


  noStroke();

  tmpmodel.draw();

  popMatrix();



  pushMatrix();
  translate(width/2, height/2, 0);
  noFill();
  stroke(255);
  box(width, height, 600);
  popMatrix();
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles