Rotating mouseX,mouseY

edited August 2016 in Programming Questions

Do you know if there is any way of rotating mouseX mouseY as the object rotates?Always correspondents with the 2d screen

Tagged:

Answers

  • I believe screenX and screenY functions do the trick.

    https://processing.org/reference/screenX_.html

    Kf

  • no it doesnt work,

  • i just rotate the shape,and the camera still :P

  • No that doesnt work either.The is a point where mouseX=-mouseX and is reversed

  • i make it.Here is all the code,because i use pushMatrix,i had to cancel the first rotation and then put an other rotation after translation

     import peasy.*;
    import saito.objloader.*;
    
    
    //PrintWriter output;
    OBJModel model ;
    OBJModel Smodel ;
    OBJModel tmpmodel ;
    
    PeasyCam cam;
    
    float z=0;
    float easing = 0.005;
    float r;
    float k =0.00001;
    int VertCount;
    PVector[] Verts;
    PVector[] locas;
    PVector Mouse;
    
    void setup()
    {
      size(800, 800, P3D);
      frameRate(30);
      noStroke();
    
      model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      model.enableDebug();
      model.scale(150);
      model.translateToCenter();
    
    
      Smodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      Smodel.enableDebug();
      Smodel.scale(150);
      Smodel.translateToCenter();
    
    
      tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
      tmpmodel.enableDebug();
      tmpmodel.scale(150);
      tmpmodel.translateToCenter();
    
      //output = createWriter("positions.txt"); 
    
      cam = new PeasyCam(this, width/2, height/2, 0, 1200);
    }
    
    
    
    void draw()
    {
      background(129);
      lights();
    
    
    
      int VertCount = model.getVertexCount ();
      Verts = new PVector[VertCount];
      locas = new PVector[VertCount];
      float r =200;
    
    
    
    
    
      cam.setMouseControlled(false);
    
    
      Mouse = new PVector(mouseX-width/2, mouseY-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  - r/2 && Verts[i].z <  Mouse.z  + r/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);
          }
          k+=0.000001;
        }
        // output.println("Verts " + Verts[i] + " locas " +locas[i]);
      }
    
      pushMatrix();
      rotateY(-k); //-----------------HERE
      translate(Mouse.x, Mouse.y, Mouse.z);
      rotateY(k); //-------------AND HERE
      noFill();
      stroke(255);
      box(r);
      popMatrix();
    
    
      noStroke();
    
      tmpmodel.draw();
    
      popMatrix();
    
    
    
      pushMatrix();
      translate(width/2, height/2, 0);
      rotateY(k);
      noFill();
      stroke(255);
      box(width, height, 600);
      popMatrix();
      //output.flush(); // Writes the remaining data to the file
      //output.close(); // Finishes the file
      //saveFrame();
      println(z);
    }
    
    void keyPressed() {
      if (keyCode == UP) {
        z++;
      }
      if (keyCode == DOWN) {
        z--;
      }
    }
    
Sign In or Register to comment.