Clickable text that's rotating in peasy?
in
Contributed Library Questions
•
10 months ago
I'm creating something that uses Peasy to rotate the camera. The screen has some text that spins around and I need to make each text spot clickable. I have spent a few hours trying to figure this out, but I have no success. Does anyone have any ideas and can help me with this problem?
I know how to make a non-moving rect() clickable using an if-statement with mouseX and mouseY. But I don't know what to do if the rect() is rotating. Any suggestions are welcome. Using other libraries like controlP5 is okay with me too; I really need help getting this to work!
I've uploaded a .zip of the sketch if you want to
download it on dropbox, or you can view the code below:
- import peasy.*;
- PeasyCam cam;
- PFont font;
- PImage pim;
- float rot=0;
- ArrayList<String> aList = new ArrayList<String>();
- void setup(){
- size(800, 600, P3D);
- //smooth();
- hint(DISABLE_DEPTH_TEST); // avoids z-fighting
- font = loadFont("Helvetica-50.vlw");
- textFont(font);
- cam = new PeasyCam(this, 400, 400, 0, 1500); // default settings on double click
- cam.setMinimumDistance(.001);
- cam.setMaximumDistance(20000);
- aList.add("Testing1");
- aList.add("Testing2");
- aList.add("Testing3");
- aList.add("Testing4");
- aList.add("Testing5");
- aList.add("Testing6");
- aList.add("Testing7");
- aList.add("Testing8");
- aList.add("Testing9");
- aList.add("Testing10");
- aList.add("Testing11");
- aList.add("Testing12");
- }
- void draw(){
- background(0);
- translate(width/2, height/2);
- rot-=.001;
- showText();
- cam.setRotations(0, 0, rot);
- }
- void showText() {
- for (int i=0; i<aList.size(); i++) {
- String label = aList.get(i);
- float labelWidth = textWidth(label);
- float textHeight = 50;
- float[] rotations = cam.getRotations();
- pushMatrix();
- translate(40*(i+4)*cos(i),
- 100+40*(i+4)*sin(i),
- textHeight);
- pushMatrix();
- // Make text always face camera
- rotateX(rotations[0]);
- rotateY(rotations[1]);
- rotateZ(rotations[2]);
- translate(0,0,1);
- fill(100);
- rect(- labelWidth/2 - 2, -textHeight -1.5 ,labelWidth+4, textHeight+textHeight/2);
- fill(255);
- textSize(textHeight); textAlign(CENTER);
- text(label, 0, 0, 0);
- popMatrix();
- popMatrix();
- }
- }
1