PeasyCam cursor location in comparison to objects (Shapes3D).

Thank you for all of the help so far, but I have hit another roadblock. I am using PeasyCam and Shapes3D to render an AI collection. I can draw the cells and go through them with PeasyCam, no issues. I want to be able to select on of the cells and review information about it. The cursor location (2D) and the object (3D) location do not match up due to the rotation/translation in 3D. Since I am letting PeasyCam do everything, I do not know how to get the 2D coordinate of the 3D objects. Any suggestion or optimizations are welcome.

Tagged:

Answers

  • I found code for a 3Dcursor on the site and I am using it for this project now, thank you for the help.

  • Shapes3D has a picking function - look at the example 'S3D4P_Picking' that comes with the library.

  • Answer ✓

    The code below is the picking example modified to include PeasyCam

    import peasy.test.*;
    import peasy.org.apache.commons.math.*;
    import peasy.*;
    import peasy.org.apache.commons.math.geometry.*;
    
    
    import shapes3d.utils.*;
    import shapes3d.animation.*;
    import shapes3d.*;
    
    Box[] box = new Box[20];
    Shape3D picked = null;
    boolean clicked = false;
    PeasyCam pcam;
    
    float bsize, a, d = 50, c = 120;
    
    void setup() {
      size(400, 400, P3D);
      cursor(CROSS);
      for (int i = 0; i < box.length; i++) {
        bsize = 5 + (int)random(12);
        box[i] = new Box(this, bsize, bsize, bsize);
        box[i].moveTo(random(-d, d), random(-d, d), random(-d, d));
        box[i].fill(randomColor());
        box[i].stroke(color(64, 0, 64));
        box[i].strokeWeight(0.6);
        box[i].drawMode(S3D.SOLID | S3D.WIRE);
        box[i].tag = "Box " + i;
      }
      pcam = new PeasyCam(this, 200);
    }
    
    void draw() {
      background(128);
      pushMatrix();
      if (clicked) {
        clicked = false;
        picked = Shape3D.pickShape(this, mouseX, mouseY);
        if (picked != null)
          picked.fill(randomColor());
      }
      for (int i = 0; i < box.length; i++)
        box[i].draw();
      popMatrix();
      a += 0.002;
    }
    
    void mouseClicked() {
      clicked = true;
    }
    
    int randomColor() {
      return color(random(100, 220), random(100, 220), random(100, 220));
    }
    
  • Thank you. I will use this for the basis of my new re-write. I will be posting another question dealing with hierarchical createShape(GROUP). Hopefully between the two, I will be able to make more progress on this project. THANKS

  • You are welcome. I have moved this discussion to "Questions about Libraries" because it is about using Shapes3D and PeasyCam.

    I don't remember a method called createShape(...) but there is a parentShape.addShape(childShape) method which can be used to build complex shapes.

    Look at the Earth and Moon example method where the orbiter has been added to moon and the moon added to Earth. In this example the child-shapes' position is always relative to the its parent.

  • I looked for the Moon-Earth sample, but could not find it, do you happen to have a link?

  • It is called S3D4P_Earth - sorry for confusion.

  • Thank you for all of your help and guidance.

Sign In or Register to comment.