Shape3D and picking problem
in
Contributed Library Questions
•
5 months ago
Hi, I'm new to the forum and quite new to Processing.
I'm doing this 3D colored points map, I'm implementing this for a school project, the code is'nt the goal for this project so, I'm not cheating.
I'd like to print on screen a text relative to the hovered point, I've looked to the picking example in Shape3D and implemented it in my sketch. Here is the problem, it is very approsimative, it almost doesn't work...
Thank you for your support.
here is the code:
I'm doing this 3D colored points map, I'm implementing this for a school project, the code is'nt the goal for this project so, I'm not cheating.
I'd like to print on screen a text relative to the hovered point, I've looked to the picking example in Shape3D and implemented it in my sketch. Here is the problem, it is very approsimative, it almost doesn't work...
Thank you for your support.
here is the code:
- import shapes3d.utils.*;
import shapes3d.animation.*;
import shapes3d.*;
int resolution = 200;
luogo[] luoghi = new luogo[50];
boolean clicked = false;
Shape3D picked = null;
PVector pickedPos = new PVector();
void setup() {
size(640, 320, P3D);
colorMode(HSB, resolution);
sphereDetail(8);
textFont(createFont("Georgia", 24));
smooth();
ortho();
for (int i = 0; i < luoghi.length; i++) {
// set up for the points
luoghi[i] = new luogo(this, 20, 1);
luoghi[i].setLuogo((int)random(resolution),(int)random(resolution),(int)random(resolution),"ciccia"+i);
}
}
void draw() {
background(0,0,0);
translate((int)width/2,(int)height/2);
// check if the mouse is over a point
picked = Shape3D.pickShape(this, mouseX-width/2, mouseY-height/2);
if (picked != null) {
println("found : "+mouseX+" "+mouseY);
pickedPos = picked.getPosVec();
}
// draw the points
for (int i = 0; i < luoghi.length; i++) {
luoghi[i].disegna(resolution,pickedPos);
}
}
void mouseClicked() {
clicked = true;
}
// this class extends the Helix class in Shape3D library
class luogo extends Helix { // mi appoggio alla funzione Helix della libreria Shape3D
int h,s,b,mX,mY;
String nome; // connected text
boolean drawTXT = false;
luogo (PApplet app, int a, int b) {
super(app, a, b);
this.setRadius(5,5,1);
this.setHelix(1f, 0);
this.drawMode(S3D.BOTH_CAP | S3D.WIRE);
this.tag = "Box " + random(5);
}
void setLuogo (int hh, int ss, int bb, String nom) {
h=hh;
s=ss;
b=bb;
nome=nom;
}
void disegna(int res, PVector pick) {
// color the point and positionate it as hsb rapresentation
this.fill(color(h,s,b),S3D.S_CAP | S3D.E_CAP);
this.stroke(color(0,0,100));
float x = sin((float)((TWO_PI/res)*h)+(float)frameCount/360)*s;
float y = map(b,0,res,-res/2,res/2);
float z = cos((float)((TWO_PI/res)*h)+(float)frameCount/360)*s;
// if the mouse is over this point print the text
if (pickedPos.dist(this.getPosVec())==0f) {
pushMatrix();
rotateX((float)30/360*TWO_PI);
translate(-200,-85);
text(nome, 0, 0, 0);
popMatrix();
}
// drawing
this.moveTo(x,y,z);
this.rotateToX((float)30/360*TWO_PI);
this.draw();
}
void drawText() {
drawTXT = !drawTXT;
}
int getH() {
return h;
}
int getS() {
return s;
}
int getB() {
return b;
}
int getName() {
return nome;
}
}
1