FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Programs
(Moderators: fry, REAS)
   help with 3D translations
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: help with 3D translations  (Read 392 times)
senior

89237688923768 WWW
help with 3D translations
« on: Oct 7th, 2003, 7:49pm »

okay, I give up -- I've spent ages working with my code, and can't track down my bug. If anyone can help me, it'd be greatly appreciated.
 
What the app should do:
- there is an array of strings
- when the mouse is clicked, a counter is incremented.
- the first time it is clicked, the first element of the array is printed at the middle of the window. each subsequent click (should) cause the next element in the array to be printed in the middle, and the other elements to drift back in the window.
- what *is* happening, is that there is a drift, so that the elements are being printed in the incorrect location.
 
The bug is somewhere in my translation; if I remove it, everything gets printed in the right place. I know it has to do with push() and pop(), because I'm constantly translating backwards in the window.
 
I'm sure I'll figure this out a minute after I post it, but I'd appreciate any tips.
 
You can view the crappy applet at http://www.cs.queensu.ca/~senior/discrete_regressing_text/ .
 
Cheers!
 
Code:

BFont fontA;
int text_brightness = 85;
float scroll=-30.0f;
float slide=0.0f;
float move;
 
String[] numbers = {"zero","one","two","three","four","five","six","seven"};
int counter=0;
 
void setup()
{
  size(512,512);
  colorMode(HSB,400,100,100);//photoshop HSB mode
  background(275,100,20);
  fontA = loadFont("Meta-Bold.vlw.gz");
  textFont(fontA, 48);
  textMode(ALIGN_CENTER);
  framerate(24);
  fill(48,85,text_brightness);
  lights();
}
 
void loop()
{
  //dark purple
  background(275,100,20);
  //translate to the center
  translate(width/2,height/2,0);
   
  //slide everything back to make room for the new item
  push();
  if(slide > (-10*counter)) {
    slide-=1.0f;
  }
  translate(slide,slide,slide); //the problem area
   
  move=0;
  for(int i=0;i<counter-1;i++) {
    fill(48,85,text_brightness);
    push();
 move = (counter-i-1)*scroll;
 translate(move,move,move);
 text(numbers[i],0,0);
    pop();
  }
  pop();
  if(counter>0){
    text(numbers[counter-1],0,0);
  }
}
 
void mousePressed() {
  if(counter < numbers.length) {
    counter+=1;
  }
}
 
Koenie

170825270170825270koeniedesign WWW Email
Re: help with 3D translations
« Reply #1 on: Oct 7th, 2003, 8:06pm »

I think the problem has to do with line 42:
 
  translate(move, move, move);
 
should be:
 
  translate(0, move, move);
 
I probably didn't understand the problem totally, but this places the text in the x-center of the applet.
Hope this helps.
 
Koenie
 

http://koeniedesign.com
Bijeoma

myloveiloved
Re: help with 3D translations
« Reply #2 on: Oct 8th, 2003, 12:31am »

its my understanding that you want the horizontal positions of the text to be aligned. if so change the x value for both the translate calls to 0.
 
translate(0,slide,slide);  
translate(0,move,move);  
 
bryan
 
 
senior

89237688923768 WWW
Re: help with 3D translations
« Reply #3 on: Oct 8th, 2003, 12:44am »

Sorry, I guess I wasn't clear in my explanation.
 
As you click, notice that the y-value of the 2nd element keeps increasing towards the top of the screen. I want each new element to take the place of the previous one. this does that, but it is then scrolling too much, so that the gap between the 1st and 2nd elements grows.
 
Sorry, this is an annoying problem for me to explain... It's been a few years since taking computer graphics in uni, and I can't remember any of it!
 
I'll try to post another example soon.
 
Thanks for your help!
 
UPDATE: to see where the items should move to, delete the line "translate(slide,slide,slide)". The items will now just jump to the correct locations instead of sliding nicely.
« Last Edit: Oct 8th, 2003, 12:53am by senior »  
benelek

35160983516098 WWW Email
Re: help with 3D translations
« Reply #4 on: Oct 8th, 2003, 1:43am »

there were a number of lines i had to modify in order to get it to do what you want (i've marked those lines i changed). note that new numbers might now appear in front of the "current" number, if you click too fast.
 
Code:

BFont fontA;
int text_brightness = 85;
float scroll=-30.0f;
float slide=0.0f;
float move;
 
String[] numbers = {"zero","one","two","three","four","five","six","seven"};
int counter=0;
 
void setup()
{
  size(512,512);
  colorMode(HSB,400,100,100);//photoshop HSB mode
  background(275,100,20);
  fontA = loadFont("Meta-Bold.vlw.gz");
  textFont(fontA, 48);
  textMode(ALIGN_CENTER);
  framerate(24);
  fill(48,85,text_brightness);
  lights();
}
 
void loop()
{
  //dark purple
  background(275,100,20);
  //translate to the center
  translate(width/2,height/2,0);
 
  //slide everything back to make room for the new item
  push();
  if(slide > (scroll*counter)) { //changed this line
    slide-=2.0f; //changed this line
  }
  translate(slide,slide,slide);
 
  move=0;
  for(int i=0;i<counter-1;i++) {
    fill(48,85,text_brightness);
    push();
    move = (-i-1)*scroll; //changed this line
    translate(move,move,move);
    text(numbers[i],0,0);
    pop();
  }
  pop();
  if(counter>0){
    text(numbers[counter-1],0,0);
  }
}
 
void mousePressed() {
  if(counter < numbers.length) {
    counter+=1;
  }
}
 
senior

89237688923768 WWW
Re: help with 3D translations
« Reply #5 on: Oct 8th, 2003, 4:17pm »

Thank you so much!
All this time I thought I wasn't popping at the right time, but I had just missed a variable... arg!
 
Thanks again!
 
Pages: 1 

« Previous topic | Next topic »