Initial position the object with Proscene in Processing

Hello guys,

I'm trying to combine the use of toxilibs and proscene libraries to view objects in a scene.

How could I set the initial positions of the object? (More to the middle of the screen, and a certain angle - straight for example).

I'm trying to combine more than one command, but it looks like a interfefe on the other, one could give any tips?

Below is the code and the image, to pass a better idea I'm trying to do.

Note: You need a .stl file to render and libraries, of course ...

Code import toxi.geom.*; import toxi.geom.mesh.*; import toxi.processing.*; import remixlab.proscene.*; import remixlab.dandelion.core.*; import remixlab.dandelion.geom.*;

TriangleMesh mesh;
ToxiclibsSupport gfx;

Scene scene;
Trackable lastAvatar;
Particle[] particle;

float p1 = -1, p2 = -50, p3 = 30, p4 = -15;
float zoom         = 7;
int nbPart         = 2000;
boolean avoidWalls = true;
//int flockWidth = 1280, flockHeight = 720, flockDepth = 600;

PVector pCam;

void setup() {
  size(displayWidth, displayHeight, OPENGL);
  surface.setTitle("Corpo Humano");
  noStroke();
  //smooth();
  //lights(); //Inicia Luzes

  pCam = new PVector(-1, -50, 30);

  //Inicia ambiente para Cena
  scene = new Scene(this);
  scene.setAxesVisualHint(false);
  scene.setGridVisualHint(false);
  scene.addAnimationHandler(this, "animateScene");
  scene.setAnimationPeriod(40); // 25Hz
  scene.mouseAgent().setPickingMode(MouseAgent.PickingMode.CLICK);

  //scene.setBoundingBox(new Vec(0, 0, 0), new Vec(flockWidth, flockHeight, flockDepth)); //
  //scene.camera().setTranslationSensitivity(-10);
  //scene.camera().frame().setRotationSensitivity(1.5);
  //scene.camera().setUpVector(new Vec(0, 0, -1), true); // boolean noMove

  scene.camera().setPosition(new Vec(10, -90, -25));
  scene.camera().lookAt(new Vec(10, 30, 30));
  //scene.camera().frame().setRotation(p1, p2, p3, p4);

  scene.showAll();
  scene.startAnimation();

  mesh = (TriangleMesh)new STLReader().loadBinary(sketchPath("Exemplo.stl"),STLReader.TRIANGLEMESH); //Carrega Malha para desenho
  gfx  = new ToxiclibsSupport(this); //Objeto para atualizar "desenho"

  particle = new Particle[nbPart];
  for (int i = 0; i < particle.length; i++)
    particle[i] = new Particle();
}

void draw() {
  background(37);

  //Efeitos de Luz na Cena
  ambientLight(10, 10, 120);
  directionalLight(192, 168, 128,0, -1000, -0.5);
  directionalLight(255, 64, 0, 0.5f, -0.5f, -0.1f);

  scale(zoom);         //Muda scala para zoom 
  gfx.mesh(mesh,true); //Desenha Objeto

  pushStyle();
    strokeWeight(0.7*-1); 
    beginShape(POINTS);
      for (int i = 0; i < nbPart; i++) {
        particle[i].draw();
      }
    endShape();
  popStyle();
}

void keyPressed() {
  //validaTecla(key);

  //Teste
  if (key == '1') p1 += 1.5;
  else if (key == '2') p1 -= 1.05;
  else if (key == '3') p2 += 1.05;
  else if (key == '4') p2 -= 1.05;
  else if (key == '5') p3 += 1.05;
  else if (key == '6') p3 -= 1.05;
  else if (key == '7') p4 += 1.05;
  else if (key == '8') p4 -= 1.05;

  scene.camera().frame().setRotation(p1, p2, p3, p4);
  println("Pontos: " + p1, p2, p3, p4);
}

void mousePressed(){
  //println("Camera: " + scene.camera().getPosition(); ??
}

void adjustFrameRate() {
  if (scene.avatar() != null)
    frameRate(1000/scene.animationPeriod());
  else
    frameRate(60);

  if (scene.animationStarted())
    scene.restartAnimation();
}

void animateScene(Scene s) {
  for (int i = 0; i < nbPart; i++)
    if (particle[i] != null)
      particle[i].animate();
}

class Particle {
  PVector speed;
  PVector pos;
  int age;
  int ageMax;

  public Particle() {
    speed = new PVector();
    pos = new PVector();
    init();
  }

  public void animate() {
    speed.z -= 0.05f;
    pos = PVector.add(pos, PVector.mult(speed, 10f));

    if (pos.z < 0.0) {
      speed.z = -0.8f * speed.z;
      pos.z = 0.0f;
    }

    if (++age == ageMax)
      init();
  }

  public void draw() {    
    strokeWeight(0.2);
    stroke( 255 * ((float) age / (float) ageMax), 255 * ((float) age / (float) ageMax), 255);
    vertex(pos.x, pos.y, pos.z);
  }

  public void init() {    
    pos = new PVector(0.0f, 0.0f, 0.0f);
    float angle = 2.0f * PI * random(1);
    float norm = 0.04f * random(1);
    speed = new PVector(norm * cos(angle), norm * sin(angle), random(1));
    age = 0;
    ageMax = 50 + (int) random(100);
  }
}

Initial position

Humano03

Tagged:
Sign In or Register to comment.