3d and 2d coordinates

edited January 13 in Library Questions

coords

In 3d sketches null of coordinares begins here (green number "1"), how to make it begin there (green number "2"), like in 2d sketches? I realize that mouseX and mouseY not working properly because beginning of coordinates is not in the upper left corner.

Answers

  • edited January 12

    @djevazi --

    Can you explain your specific problem with an example sketch?

    Here is a basic 3D sketch. When you draw a box simple, it appears by default in the upper left hand corner. When you draw a simple line (0,0) refers to the upper left hand corner.

    void setup(){
      size(400, 400, P3D);
      noLoop();
    }
    
    void draw(){
      box(100,100,100);
      line(0,0,200,200);
    }
    

    These two examples don't exhibit your problem, so can you explain in more detail what you mean?

  • I think it's peasycam that centres the origin like that, it's not a default thing.

  • Alternatively, camera defines a lookat point, maybe he's doing that.

    We won't know without some code being posted.

  • edited January 12

    https://forum.processing.org/two/discussion/comment/85129#Comment_85129 here is my previous post with a code, yes, the problem is that peasyCam draw null coordinates not in the upper left cornes, so, I can't understand how to make mouse coordinates work like in 2d.

  • @djevazi -- Two possible solutions:

    1. Don't use PeasyCam -- just use P3D without it.
    2. Change the origin while using PeasyCam -- I don't know what that would entail without actually seeing your code, but here is a previous discussion: https://forum.processing.org/one/topic/working-with-peasycam-change-the-origin-of-rotation.html
  • @jeremydouglass, here is my code:

    import peasy.*;
    PeasyCam jcam;
    
    float r=200;
    int segments=30;
    int brushsize = 200;
    int cameraOn=2;
    
    PVector thisPos;
    float[] rotationspi;
    
    ArrayList <Point> points = new ArrayList <Point>();
    
    Brush brush;
    
    
    void setup()
    {
      size(800, 800, P3D);
      jcam = new PeasyCam(this, 600);
    
      for (int i=0; i<segments; i++)   // initialize
      {
        float lat = map(i, 0, segments, -HALF_PI, HALF_PI);
        for (int j=0; j<segments; j++)
        {
          float lon=map(j, 0, segments, -PI, PI);
    
          float x = r*sin(lon)*cos(lat);
          float y = r*sin(lon)*sin(lat);
          float z = r*cos(lon);
          PVector temp = new PVector(x, y, z);
          Point pt1= new Point(temp);
          points.add(pt1);
        }
      }
    
      PVector brushPos = new PVector(0, 0);
      brush = new Brush(brushPos);
    }
    
    
    void draw()
    {
      background(150);
    
      rotationspi = jcam.getRotations();
    
      stroke(255,0,0);
      fill(255,0,0);
    
      pushMatrix();
      rotateX(rotationspi[0]);
      rotateY(rotationspi[1]);
      rotateZ(rotationspi[2]);
      line(0,250,0,0,0,0);
      text("local X", 260, 0, 0);
      line(0,0,0,250,0,0);
      text("local Y", 10, 250, 0);
      popMatrix();
    
    
    
      if(cameraOn%2==0)
      {
        jcam.setActive(true);
      }
      else
      {
        jcam.setActive(false);
      }
    
    
      for (int i=0; i<points.size(); i++)   // smooth selection
      {
        //float xx = screenX(points.get(i).pos.x, points.get(i).pos.y);
        //float yy = screenY(points.get(i).pos.x, points.get(i).pos.y);
    
        float force =  (dist(points.get(i).posScreen.x,points.get(i).posScreen.y, mouseX, mouseY)*255)/(brushsize/2);
    
        colorMode(RGB);
    
        if (dist(points.get(i).posScreen.x, points.get(i).posScreen.y, mouseX, mouseY)<brushsize/2)
        {
          points.get(i).colore = color(255, 0+force, 0+force);
        } else
        {
          points.get(i).colore = 255;
        }
    
        if(mousePressed)
        {
          if(dist(points.get(i).posScreen.x, points.get(i).posScreen.y,mouseX,mouseY)<brushsize/2)
          {
            PVector mouse = new PVector(mouseX-thisPos.x,mouseY-thisPos.y);
            mouse.setMag(100/force);
            points.get(i).pos.add(mouse);
          }
        }
        points.get(i).display();
      }
    
      //------
    
      jcam.beginHUD();   // 2D menu
    
      if(keyPressed)
      {
        if(key=='[')    
        {
          brushsize--;
        }
        if(key==']')
        {
          brushsize++;
        }
      }
    
      if(cameraOn%2==0)
      {
        fill(255);
        text("camera is ON",20,20);
      }
      else
      {
        fill(255);
        text("camera is OFF",20,20);
      }
    
      brush.pos= new PVector(mouseX, mouseY);  // brush
      brush.display();
    
      jcam.endHUD();
    }
    
    void mousePressed()
    {
      thisPos = new PVector(mouseX,mouseY);
    }
    
    void keyPressed()
    { 
      if(key=='c')
      {
        cameraOn++;
      }
    
    }
    
    
    class Brush
    {
      PVector pos;
      color brColor = color(255, 0, 0);
    
      Brush(PVector posIn)
      {
        pos = posIn;
      }
    
      void display()
      {
        noFill();
        stroke(255, 0, 0);
        pushMatrix();
        ellipse(pos.x, pos.y, brushsize, brushsize);
        ellipse(pos.x, pos.y, brushsize/2, brushsize/2);
        ellipse(pos.x, pos.y, 2, 2);
        popMatrix();
      }
    }
    
    
    class Point
    {
      PVector pos;
      PVector posScreen=new PVector();  // we store the 2D pos 
      color colore;
    
    
    
    
      Point(PVector posIn)
      {
        pos = posIn;
      }
    
      void display()
      {
        noStroke();
        fill(colore);
        pushMatrix();
        translate(pos.x, pos.y, pos.z);
        box(3);
    
        posScreen.x = screenX( 0, 0, 0 );
        posScreen.y = screenY( 0, 0, 0 );
    
        popMatrix();
      }
    }
    
  • edited January 14

    @djevazi --

    If you do decide to take the "don't use PeasyCam" route, a recent discussion that demonstrates implementing partial rotation of an object without it:

    https://forum.processing.org/two/discussion/20235/align-box-with-vector

  • thanks for help!

Sign In or Register to comment.