How to fix 3D mousebutton rotation angle?

Hi, this is very very urgent I hope someone can help me now!

I'm trying to make a galaxy and somewhat a music visualizer. The stars are rotating based on the cursor position. However, due to that, my object for the music visualizer (labelled sun) has problems now. It is supposed to appear in the middle and it's now all the way at the left (only appearing when my mouse is in the extreme bottom right).

How do I plant my sun object in the middle top such that no matter how the cursor moves it will always be seen? I would like to fix it there however keep the aspect of it rotating (fixing the point but keeping the rotation) I wonder if its possible also. Please help me thanks!!!!

import ddf.minim.*;
import ddf.minim.analysis.*;
import controlP5.*;

Minim minim;
AudioPlayer player;
AudioMetaData meta;
BeatDetect beat;

ControlP5 cp5;

int cols, rows;
int scl = 20; 
int w = 3500;
int h = 1600;
int state = 1;
int  r = 200;
float rad = 70;

float[][] terrain;
float flying = 0;

// Stars parameters
int           depth = 8;
int           nbStarsMax = 10000;
Stars[]       tabStars = new Stars[nbStarsMax];
int           maxStarsSpeed = 5;

// Drawing parameters
int           sizeX = 1280;
int           sizeY = 2000;
boolean       clearScreen = true;
int           taille = 1;
int           transparency = 255;

// Rotation variable
int           rotationMode = 3;
float         angle = 0;
float         delta = radians(0.25);

void setup() {
  size(displayWidth, displayHeight, P3D);
  cols = w/scl;
  rows = h/scl;
  terrain = new float[cols][rows];
  String strX, strY;
  float yoff = 0;
  for (int y = 0; y < rows; y++) {
    float xoff = 0;
    for (int x = 0; x < cols; x++) {  
      terrain[x][y] = map(noise(xoff, yoff), 0, 1, -150, 150);
      xoff += 0.2;
    }
    yoff += 0.2;
    noCursor();
  }
  for (int nb=0; nb<nbStarsMax; nb++) {
    tabStars[nb] = new Stars(random(-2*width, 2*width), random(-2*height, 2*height), 
      -random(depth*255), random(1, maxStarsSpeed));
  } 
  minim = new Minim(this);
  player = minim.loadFile("new life... (original synth instrumental).mp3");
  meta = player.getMetaData();
  beat = new BeatDetect();
  //player.play();
}


void draw() {
  beat.detect(player.mix);
  beat = new BeatDetect(player.bufferSize(), player.sampleRate());
  beat.setSensitivity(350);

  if (state==0) {
    terrain();
    starry();
    sun();
  } else if (state==1) {
    startscreen();
  }
}

void terrain() {
  player.play();
  flying -= 0.02;
  float yoff = flying;
  for (int y = 0; y < rows-1; y++) {
    float xoff = 0;
    for (int x = 0; x < cols; x++) { 
      terrain[x][y] = map(noise(yoff, xoff), 0, 1, -100, 100);
      xoff += 0.2;
    }
    yoff += 0.15;
  }
  background(0);
  stroke(255);
  noFill();

  translate(width/2, height/2+50);
  rotateX(PI/3);
  translate(-w/2, -h/2);

  for (int y = 0; y < rows-1; y++) {
    beginShape(TRIANGLE_STRIP);
    for (int x = 0; x < cols; x++) { 
      vertex(x*scl, y*scl, terrain[x][y]);
      vertex(x*scl, (y+1)*scl, terrain[x][y+1]);
      //rect(x*scl, y*scl, scl,scl);
    }
    endShape();
  }
}

void starry() {
  translate(width/2+((mouseX-(width/2))*10)/(width/2), 
    height/2+((mouseY-(height/2))*10)/(height/2), 0);
  rotateY(-((mouseX-(width/2))*radians(30))/(width/2));
  rotateX(((mouseY-(height/2))*radians(30))/(width/2));
  if (rotationMode==1) {
    angle += delta;
  }
  if (rotationMode==2) {
    angle -= delta;
  }
  rotateZ(angle);
  for (int nb=0; nb<nbStarsMax; nb++) {
    tabStars[nb].aff();
    tabStars[nb].anim();
  }
}

void sun() {
  float t = map(mouseX/4, mouseY/2, width/2, 0, 1);
  beat.detect(player.mix);
  fill(#1A1F18, 20);
  colorMode(HSB, 360, 100, 100);
  noStroke();
  //rect(0, 0, width, height);
  translate(width/2, height/2);
  //translate(width/2+((mouseX-(width/2))*10)/(width/2), 
  //  height/2+((mouseY-(height/2))*10)/(height/2), 0);
  noFill();
  //fill of speaker
  fill(-1, 10);
  if (beat.isOnset()) rad = rad*0.9;
  else rad = 70;
  //ellipse(0, 0, 2*rad, 2*rad);
  sphere(rad);
  lights();
  stroke(-1, 50);
  int bsize = player.bufferSize();
  for (int i = 0; i < bsize - 1; i+=5)
  {
    float x1 = (r)*cos(i*2*PI/bsize);
    float y1 = (r)*sin(i*2*PI/bsize);
    float x2 = (r + player.left.get(i)*100)*cos(i*2*PI/bsize);
    float y2 = (r + player.left.get(i)*100)*sin(i*2*PI/bsize);
    line(x1, y1, x2, y2);
  }
  beginShape();
  noFill();
  stroke(-1, 50);
  for (int i = 0; i < bsize; i+=30)
  {
    float x2 = (r + player.left.get(i)*100)*cos(i*2*PI/bsize);
    float y2 = (r + player.left.get(i)*100)*sin(i*2*PI/bsize);
    vertex(x2, y2);
    pushStyle();
    stroke(-1);
    strokeWeight(2);
    point(x2, y2);
    popStyle();
  }
  endShape();
  // if (flag)
  // showMeta();
}


void startscreen() {
  background(0);
  stroke(255);
  noFill();

  translate(width/2, height/2+50);
  rotateX(PI/3);
  translate(-w/2, -h/2);
  for (int y = 0; y < rows-1; y++) {
    beginShape(TRIANGLE_STRIP);
    for (int x = 0; x < cols; x++) { 
      rect(x*scl, y*scl, scl, scl);
    }
  }
}

void keyPressed() {
  if (keyCode ==' ') {

    if (state==1) {
      delay(1000);
      state = 0;
    }
  }
}

// if(key=='s')saveFrame("###.jpeg");
//  if(key=='a') {
//    fill(0,3);
//   rect(0,0, width, height);
//   fill(255);
//    ellipse(random(width), random(height), 3, 3);
// Hihat2.trigger(); 
// }
//if(key=='g') {
// Kick2.trigger(); 
//  }

void mousePressed() {

  if (mouseButton==LEFT)
    rotationMode = 1;

  if (mouseButton==RIGHT)
    rotationMode = 2;
  if (mouseButton==CENTER)
    rotationMode = 3;

}

Answers

  • we can't run the code because you don't provide the classes

    anyway, you can use pushMatrix and popMatrix to isolate different types of movements in you sketch

Sign In or Register to comment.