TextureSphere with Text

I am using Gillian Ramsay’s version of textureSphere and I would like to add text to interact with the operation of the program.
However, when the sphere is rotated or translated, it also rotates or translates the text area on screen. This is undesirable.
Is it possible to separate the text from the canvas of the sphere to keep the text area fixed (and hidable)?
Regards
Peter Turner

1 Like

It would help to see the code

To isolate normally you would write pushMatrix(); before the sphere section and popMatrix(); after this section

When you use a camera() command just say camera(); noLights(); prior to the text (!) section

peasyCam has a HUD, surround the text section with cam.beginHUD(); and cam.endHUD();

1 Like

Hi Chrisir, and thanks for your response.

The text in question is either a textarea or a menu.

I have tried cam.beginHUD(); and cam.endHUD(); around the text in question and it doesn’t prevent the text from rotating with the sphere.

Please find attached the java file.

Regards
Peter Turner

(Attachment eclipses.java is missing)

1 Like

As I said, use pushMatrix and popMatrix

beginHUD is only for Peasycam

Attachment eclipses.java is missing

Is it there now?

Regards
Peter Turner

(Attachment eclipses.java is missing)

Hello Chrisir

I have changed it to a text file, but it’s obviously written in java.

I am using Peasycam. The orher camera has been commented out.

Regards
Peter Turner

(Attachment eclipses.txt is missing)

Hi Chrisi

The system won’t allow me to attach a text file

Strange.

I have put the code within this email, so hopefully that won’t get stopped.

/**

  • Texture Sphere
  • by Gillian Ramsay

The code can be found here and the image file can be downloaded here.

1 Like

If you move the pushMatrix() in front of the camera statement then the text doesn’t move :slight_smile:

void draw() {
  background(0);
  pushMatrix();
  camera(width/2+map(mouseX, 0, width, -2*width, 2*width), 
    height/2+map(mouseY, 0, height, -height, height), 
    height/2/tan(PI*30.0 / 180.0), 
    width, height/2.0, 0, 
    0, 1, 0);
  translate(width/2, height/2, 0);  
  textureSphere(200, 200, 200, img);
  popMatrix();
  fill(255);
  textSize(32);
  text("Hello World", width - 220, height - 20);
}
1 Like

Thank you Peter.

I have modified it a little and am using PeasyCam. Will pushMatrix() popMatrix() around cam = new PeasyCam(…) work? I thought I had already tried it. I’ll try again.

Regards
Peter Turner

No it doesn’t work with PeasyCam. I’ll try it with camera.

Regards
Peter Turner

No it doesn’t work with camera either. The sphere is unresponsive to mouse/touchpad movement.

Regards
Peter Turner

I’ll try your code exactly, and see where it differs from mine

Regards
Peter Turner

All the libraries come with examples. In Processing select File > Examples… from the menus, expand the Contributed Libraries tab and in the PeasyCam library open the example called HeadUpDisplay it shows how to keep the text stationary

1 Like

Yes Peter, you’re right.

I’ll have to see where I’ve gone wrong, and whether it works with PeasyCam (which gives better control of the sphere).

Thank you.

Regards
Peter Turner

This is strange.

Is this with Peasycam?

Hi Chrisir

Problem solved. The cam.beginHUD(); cam.endHUD(); wrapper needs to surround the text, not the sphere, and it applies to plain text, not a textarea.

Thank you.

Next problem is how to write to the text whilst running, similar to EditText in Java, rather than having it static and non interactive.

Regards
Peter Turner

1 Like




/** 
 * TextBox Writer (v2.4)
 * by  Inarts (2013/Oct)
 * mod GoToLoop
 * https : // forum.processing.org/two/discussion/20882/very-basic-question-how-to-create-an-input-text-box#latest
 * forum.processing.org/two/discussion/423/
 * how-to-write-a-class-for-text-area-without-using-any-library
 *
 * studio.processingtogether.com/sp/pad/export/ro.9Zo$UbIWYZEDR/latest
 */

TextBox tbox;

final int stateNormal   = 0;
final int stateInputBox = 1;
int state=stateNormal; 

// the user name 
String result="/"; 

void setup() {
  size(1240, 480);

  rectMode(CORNER);
  textAlign(LEFT);
  strokeWeight(1.5);

  instantiateBox();
  tbox.isFocused = true;
}

void draw() {
  background(#778C85);

  if (state==stateNormal) {
    backgroundImage();
    text("Click mouse\nYour name: "+result, 19, 19);
  } else  if (state==stateInputBox) {
    backgroundImage();
    tbox.display();
  }
}//func

// ----------------------------------------------------

void backgroundImage() {

  // just a background (from the forum)

  int verticalNumberLines=20;
  int horizontalNumberLines=20;
  int space=5;

  for (int i=0; i<width; i+=width/verticalNumberLines)
  {
    for (int j=0; j<height; j+=space)
    {
      point(i, j);
    }
  }

  for (int j=0; j<height; j+=height/horizontalNumberLines)
  {
    for (int i=0; i<width; i+=space)
    {
      point(i, j);
    }
  }
}

void mouseClicked() {

  if (state==stateNormal) {
    // in normal mode: 
    // switch on input box
    state = stateInputBox;
  } else  if (state==stateInputBox) {
    // do nothing
  }
}

void keyTyped() {
  if (state==stateNormal) {
    // do nothing
  } else if (state==stateInputBox) {
    //
    tbox.tKeyTyped();
  }
}//func 

void keyPressed() {
  if (state==stateNormal) {
    //
  } else if (state==stateInputBox) {
    //
    tbox.tKeyPressed();
  }
}//func

void instantiateBox() {
  tbox = new TextBox(
    "Please enter your name: ", 
    width/2-width/3, height/4 + height/16, // x, y
    width/3, height/2 - height/4 - height/8, // w, h
    215, // lim
    0300 << 030, color(-1, 040), // textC, baseC
    color(-1, 0100), color(#FF00FF, 0200)); // bordC, slctC
}

// ============================================================================================

class TextBox {

  // demands rectMode(CORNER)

  final color textC, baseC, bordC, slctC;
  final short x, y, w, h, xw, yh, lim;

  boolean isFocused;
  String txt = "";
  String title; 

  TextBox(
    String tt, 
    int xx, int yy, 
    int ww, int hh, 
    int li, 
    color te, color ba, color bo, color se) {

    title=tt;

    x = (short) xx;
    y = (short) yy;
    w = (short) ww;
    h = (short) hh;

    lim = (short) li;

    xw = (short) (xx + ww);
    yh = (short) (yy + hh);

    textC = te;
    baseC = ba;
    bordC = bo;
    slctC = se;
  }

  void display() {
    stroke(isFocused? slctC : bordC);

    // outer 
    fill(baseC);
    rect(x-10, y-90, w+20, h+100);

    fill(0); 
    text(title, x, y-90+20);

    // main / inner
    fill(baseC);
    rect(x, y, w, h);


    fill(textC);
    text(txt + blinkChar(), x, y, w, h);
  }

  void tKeyTyped() {

    char k = key;

    if (k == ESC) {
      // println("esc 2");
      state=stateNormal; 
      key=0;
      return;
    } 

    if (k == CODED)  return;

    final int len = txt.length();

    if (k == BACKSPACE)  txt = txt.substring(0, max(0, len-1));
    else if (len >= lim)  return;
    else if (k == ENTER || k == RETURN) {
      // this ends the entering 
      println("RET ");
      state  = stateNormal; // close input box 
      result = txt;
    } else if (k == TAB & len < lim-3)  txt += "    ";
    else if (k == DELETE)  txt = "";
    else if (k >= ' ')     txt += str(k);
  }

  void tKeyPressed() {
    if (key == ESC) {
      println("esc 3");
      state=stateNormal;
      key=0;
    }

    if (key != CODED)  return;

    final int k = keyCode;

    final int len = txt.length();

    if (k == LEFT)  txt = txt.substring(0, max(0, len-1));
    else if (k == RIGHT & len < lim-3)  txt += "    ";
  }

  String blinkChar() {
    return 
      isFocused && (frameCount>>2 & 1) == 0 ? "_" : "";
  }

  boolean checkFocus() {
    return 
      isFocused = mouseX > x & mouseX < xw & mouseY > y & mouseY < yh;
  }
  //
}// class
//
1 Like

Thank you Chrisir.

I’ve been off the computer for a couple of days, but have tried your TBox and it works perfectly.

I just need to adjust some details to fit in with the rest of my code.

Thanks.

Regards
Peter Turner

2 Likes