¿How can I animate 2D figures on 3D environment?

edited December 2 in Library Questions

¡Need your help! I managed to do this.

import processing.sound.*;
PGraphics gui;
PFont font;
// Se declaran las variables de sonido 
SoundFile sample;
Amplitude rms;
// Declara un valor de escala
float scale = 5.0;
// Declara un valor de suavizado
float smoothFactor = 0.25;
// Suavizado
float sum;
float z=1000;

void setup() {
  fullScreen(P3D);
  //noStroke();  
  //Se carga el archivo y se hace un loop.(Se reinicia automaticamente)
  sample = new SoundFile(this, "digimon.mp3");
  sample.loop();
  // Se crea y se redirige el medidor de RMS
  rms = new Amplitude(this);
  rms.input(sample);
}

void draw() {
  background(0);
  translate(width/2, height/2, 0);
  scale(100);
  lights();
  rotateY(map(mouseX, 0, width, -PI, PI));
  rotateX(map(mouseY, 0, height, -PI, PI));  
  informacion();
  circulo();
  ellipse(width/2, height/2, 1000, 1000);
  fill(64, 64, 196);
  fractal(2);
}
float r(float theta, float a, float b, float m, float n1, float n2, float n3) {

  return pow(pow(abs(cos(m*theta/4.0)/a), n2)+
    pow(abs(sin(m*theta/4.0)/b), n3), -1.0/n1);
}

This is my "fractal" function.

void fractal(int level) {
  //noStroke();
  float rmsScaled = sum * (height/2) * scale;
  sum += (rms.analyze() - sum) * smoothFactor; 
  box(rmsScaled/300.0);
  if (level<=0) return;
  for (int x=-1; x<2; x+=2) {
    for (int y=-1; y<2; y+=2) {
      for (int z=-1; z<2; z+=2) {
        pushMatrix();
        translate(x, y, z);
        scale(1/2f);
        fractal(level-1);
        popMatrix();
      }
    }
  }
}

And this is my "informacion" function

void informacion() {
  pushMatrix();
  camera();
  hint(DISABLE_DEPTH_TEST);
  fill(255, 255, 255);
  text("Rainerio Amézquita Sánchez", 10, 20 );
  text("Proyecto Graficación", 10, 30 );
  text("Visualizador de Audio versión 3.0", 10, 40 );
  noFill();
  popMatrix();
}

My problem is that I have this function and I want to show it on screen, but it doesn´t work. I used camera(); and hint(DISABLE_DEPTH_TEST); to "separate" 2D figures from 3D. Oh, I just forgot. The 2D figures doesn´t have to be affected by the camera movement, just the 3D ones. This function just show a Circle, and change his size using the music. HELP!!

void circulo() {  
  pushMatrix();  
  camera();
  hint(DISABLE_DEPTH_TEST); 
  beginShape();
  float rmsScaled = sum * (height/2) * scale;
  sum += (rms.analyze() - sum) * smoothFactor; 
  //Vertices...
  for (float theta=0; theta<=2*PI; theta+=0.1) {
    float rad=r(theta, 
      rmsScaled/100.0, //a
      rmsScaled/100.0, //b
      0, //m
      1, //n1
      1, //n2
      1  //n3
      );
    float x=rad*cos(theta)*50;
    float y=rad*sin(theta)*50;
    vertex(x, y);
  }
  endShape();
  popMatrix();
}

Answers

  • Srry, I forgot. I'm just a little nervous about posting my code haha. This code is a "Music Visualizer", that´s what I'm trying to do. :v

  • @Sefiro10 -- re:

    My problem is that I have this function and I want to show it on screen, but it doesn´t work.

    So you are saying that you expect circulo() to draw something on the screen, but nothing happens -- is that right?

Sign In or Register to comment.