Hello,
you need to click the mouse on the center of a sphere and start dragging the mouse and release later
this version works but only when you haven’t moved peasycam before (or double click it prior to drawing)
this line is to blame:
list.add(new PVector(mouseX-width/2, mouseY-height/2, lerp( 60, 0, amt ) ));
maybe a guru like @GoToLoop can be so kind to explain how to
retrieve the Matrix set by peasyCam and change the line in a way that the
mouse position reflects the matrix of the cam.
I can’t find gotoloop’s post with peasycam Matrix.
Remark
(((
It also reminds me of
// kind of similar (not really)
// see https://discourse.processing.org/t/pro-question-place-a-point-in-3d-with-mouse/6664/3
// see https://discourse.processing.org/t/p3d-formula-opposite-of-screenx-and-screeny-is/10121/2
))
Greetings,
Chrisir
// get 3d spital coordinates of spheres and draw a curve between them with mouse.
// doesn't work because of peasyCam
// kind of similar (not really)
// see https://discourse.processing.org/t/pro-question-place-a-point-in-3d-with-mouse/6664/3
// see https://discourse.processing.org/t/p3d-formula-opposite-of-screenx-and-screeny-is/10121/2
import peasy.*;
PeasyCam cam;
// 2D coordinates on screen for both spheres
PVector pvSphere2D_Number1, pvSphere2D_Number2;
// dragging yes/no
boolean mouseDown=false;
// list
ArrayList<PVector> list = new ArrayList();
// ----------------------------------------------------------
void setup() {
size(1500, 500, P3D);
cam = new PeasyCam(this, 500);
}
void draw() {
background(255);
if (keyPressed) {
if (key == 'a' || key == 'A') {
cam.setActive(false);
} else if (key==' ') {
list.clear();
} else if (key != 'a' && key != 'A') {
// hit another key than a to make cam active again
cam.setActive(true);
}
}//if
// show 2 spheres
pushMatrix(); // new
pvSphere2D_Number1=new PVector(screenX(300, 100, 60), screenY(300, 100, 60));
translate(300, 100, 60);
noStroke();
lights();
fill(0, 0, 255);
sphere(65);
popMatrix(); // new
pushMatrix(); // new
pvSphere2D_Number2=new PVector(screenX(140, 140, 0), screenY(140, 140, 0));
translate(140, 140, 0);
noStroke();
lights();
fill(0, 255, 255);
sphere(65);
popMatrix(); // new
// During mouse down (dragging) we record the points
if (mouseDown) {
float amt = 0.5; // map( dist( mouseX,mouseY, ) );
list.add(new PVector(mouseX-width/2, mouseY-height/2, lerp( 60, 0, amt ) ));
}
// display the recorded points
beginShape();
noFill();
stroke(255, 0, 0);
for (PVector pvMy : list) {
curveVertex(pvMy.x, pvMy.y, pvMy.z);
}
endShape();
//
}
// --------------------------------------------------------------------------------------------
void mousePressed() {
// start dragging but only when on a sphere
// println("A");
if (pvSphere2D_Number1.dist(new PVector(mouseX, mouseY)) < 64) {
println("1");
mouseDown=true;
}
if (pvSphere2D_Number2.dist(new PVector(mouseX, mouseY)) < 64) {
println("2");
mouseDown=true;
}
}
void mouseReleased() {
// end dragging
mouseDown=false;
}
//