We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › "frames" in processing
Page Index Toggle Pages: 1
"frames" in processing? (Read 1463 times)
"frames" in processing?
Apr 12th, 2010, 7:21am
 
in html you can use somthing like frames. on the top of the program you can program a menu with buttons and below you have the main contain. when you click the button, only the under part of the program changes. you can save only the under part of the program, print it or load it,...

I would like to make a 3d program. on the top of the program I would like to have some buttons with controlP5 in 2 dimensions and below I would like to have a coordinate system with 3 dimensions that you can rotate, translate.. independent of the menu..

is this possible? and how?

thank you for your help
Re: "frames" in processing?
Reply #1 - Apr 12th, 2010, 7:27am
 
You can draw on an off-screen buffer (except in OpenGL mode) then "paste" this drawing on the sketch area to make a composite screen.
Re: "frames" in processing?
Reply #2 - Apr 12th, 2010, 7:40am
 
you can take a look at pushMatrix() and popMatrix() in the reference. if you add popMatrix() right at the beginning of your draw() function and popMatrix() right at the end of draw(), you should get what you are looking for. if you are using a 3d-camera e.g. peasy, there is a controlP5 example  that shows you how to use a peasy cam and keeping the gui on top.
Re: "frames" in processing?
Reply #3 - Apr 12th, 2010, 7:51am
 
hey.. I'm sorry, but I'm a beginner. I have no idea of what you're talking. is it possible that you could program me an easy example with this two parts?

would be very very nice.. because it's very difficult to find something on the internet.. and when I've found somehing, I can't understand it because it's not my mother tongue..

sorry..
Re: "frames" in processing?
Reply #4 - Apr 12th, 2010, 8:16am
 
just put pushMatrix(); right at the beginning of draw, then put anything else including your code that draws your 3d system, then put popMatrix(); right at the end of draw. you might encounter that 3d shapes will cut through the gui, to avoid this effect, put hint(ENABLE_DEPTH_TEST); before pushMatrix() and hint(DISABLE_DEPTH_TEST); after popMatrix().
Re: "frames" in processing?
Reply #5 - Apr 12th, 2010, 9:13am
 
hey..

ok, I understand how this works.. I asked for an example because of the first answer..

but if I want to save this, I save the whole program. I would like to save only the things that are in the 3d system.. like for example in a text editor. you just save what you've written and not the buttons where you can choose the color or the font style..

when I now want to save this, I save the whole program with all buttons,... or not?
Re: "frames" in processing?
Reply #6 - Apr 12th, 2010, 9:37am
 
Just save the off-screen graphics.
That's a PGraphics made with createGraphics().
You can act on it like you do with regular sketch (prefixing the functions with the name of the graphics object) and then do img(gfx, 10, 50); for example to show on screen, and gfx.save() to save it to disk.
Re: "frames" in processing?
Reply #7 - Apr 12th, 2010, 1:47pm
 
but this all doesn't work. because I can't use the controlP5 with the P3D renderer.

that's written:
### INFO you are using renderer processing.core.PGraphics3D
to draw controlP5 you have to call the controlP5.draw() method inside of
your processing sketch draw() method.

so I should seperate these two things, the buttons and the coordinate system, but that also doesn't work.. what shall I do?
I've no idea..
Re: "frames" in processing?
Reply #8 - Apr 12th, 2010, 1:48pm
 
import controlP5.*;
ControlP5 controlP5;
int messageBoxResult = -1;
ControlGroup messageBox;
String messageBoxString = "";
float rotx=radians(-5), roty=radians(-20);
int achl=600;
int a=100, offx=0, offy=0,offz=0;
int transx, transy, transz=-300;
int lastWidth, lastHeight;
int pfeil=6;

void setup(){  
size(800,600,P3D);
controlP5 = new ControlP5(this);
lastWidth = width;  
lastHeight = height;  
frame.setResizable(true);
stroke(0);  
strokeWeight(1);  
strokeJoin(MITER);  
transx=width/2;
transy=height/2;  
registerPre(this);
controlP5.Button b = controlP5.addButton("toggleBox",1,20,20,100,20);
b.setLabel("Toggle Box");  
}


void pre(){  
if(width != lastWidth || height != lastHeight){    
 int deltaX = transx - lastWidth/2;    
 int deltaY = transy - lastHeight/2;    
 transx = deltaX + width/2;  
 transy = deltaY + height/2;  
 lastWidth = width;  
 lastHeight = height;  
}
}

void draw(){  
background(226);  
//camera();  //  
//perspective();
hint(ENABLE_DEPTH_TEST);
pushMatrix();
translate(transx,transy,transz);  
rotateX(rotx);  
rotateY(roty);  
koordinatensystem();  
//einheitswuerfel();  
//punkt(150,150,150);
//quadf(2,3,2);
popMatrix();
hint(DISABLE_DEPTH_TEST);
line(10,20,30,40);

}

void koordinatensystem(){  
strokeWeight(1.5);  
beginShape(LINES);
 stroke(255,0,0); //z-achse rot  
 vertex(0,0,-achl);  
 vertex(0,0,achl);
 
vertex(0,0,-achl);  // Pfeil 1
vertex(pfeil,0,-achl+pfeil);
vertex(0,0,-achl);
vertex(-pfeil,0,-achl+pfeil);

vertex(0,0,achl); //Pfeil 2
vertex(pfeil,0,achl-pfeil);
vertex(0,0,achl);
vertex(-pfeil,0,achl-pfeil);

 stroke(0,255,0);  //y-achse grün
 vertex(0,-achl,0);  
 vertex(0,achl,0);  
    vertex(0,achl,0); // Pfeil 1
    vertex(0,achl-pfeil,pfeil);
    vertex(0,achl,0);
    vertex(0,achl-pfeil,-pfeil);
 
    vertex(0,-achl,0); // Pfeil 2
    vertex(pfeil,-achl+pfeil,0);
    vertex(0,-achl,0);
    vertex(-pfeil,-achl+pfeil,0);
   
   
   
 stroke(0,0,255);  //x-achse blau
 vertex(-achl,0,0);  
 vertex(achl,0,0);  
 
 vertex(-achl,0,0); // Pfeil 1
 vertex(-achl+pfeil,0,pfeil);  
  vertex(-achl,0,0);
 vertex(-achl+pfeil,0,-pfeil);  
 
 vertex(achl,0,0); // Pfeil 2
  vertex(achl-pfeil,0,pfeil);
   vertex(achl,0,0);
  vertex(achl-pfeil,0,-pfeil);
endShape();}




void einheitswuerfel(){  
 beginShape(QUADS);  
noStroke();  
fill(255,0,0);  
vertex(-a/2+offx,-a/2+offy,a/2+offz);
vertex(-a/2+offx,a/2+offy,a/2+offz);
vertex(a/2+offx,a/2+offy,a/2+offz);
vertex(a/2+offx,-a/2+offy,a/2+offz);  
fill(0,255,0);  vertex(-a/2+offx,-a/2+offy,a/2+offz);
vertex(a/2+offx,-a/2+offy,a/2+offz);
vertex(a/2+offx,-a/2+offy,-a/2+offz);  
vertex(-a/2+offx,-a/2+offy,-a/2+offz);
fill(0,0,255);  
vertex(-a/2+offx,-a/2+offy,-a/2+offz);
vertex(a/2+offx,-a/2+offy,-a/2+offz);
vertex(a/2+offx,a/2+offy,-a/2+offz);  
vertex(-a/2+offx,a/2+offy,-a/2+offz);  
fill(255,255,0);  
vertex(-a/2+offx,a/2+offy,-a/2+offz);
vertex(a/2+offx,a/2+offy,-a/2+offz);
vertex(a/2+offx,a/2+offy,a/2+offz);
vertex(-a/2+offx,a/2+offy,a/2+offz);  
fill(0,255,255);
vertex(a/2+offx,-a/2+offy,a/2+offz);
vertex(a/2+offx,-a/2+offy,-a/2+offz);
vertex(a/2+offx,a/2+offy,-a/2+offz);
vertex(a/2+offx,a/2+offy,a/2+offz);
fill(255,0,255);
vertex(-a/2+offx,-a/2+offy,-a/2+offz);
vertex(-a/2+offx,a/2+offy,-a/2+offz);
vertex(-a/2+offx,a/2+offy,a/2+offz);  
vertex(-a/2+offx,-a/2+offy,a/2+offz);
endShape();
}






void punkt(int px, int py, int pz){  
 beginShape(POINTS);  
 strokeWeight(6);  
 stroke(0);  
 vertex(px,py,pz);
 vertex(px+20,py+20);
 endShape();
}


void quadf(int a, int b, int c){
 noFill();
 strokeWeight(1);
 stroke(0);
 smooth();
beginShape();
for (float x=-250;x<250;x+=1) {

vertex(x, -a*x*x - b*x - c);

}
endShape();
}


void mouseDragged() {  float factor = 0.01;  
if (key==CODED){ // Alt + Maus --> Rotation  
if(keyCode==ALT){    
 rotx += (pmouseY-mouseY) * factor;      
roty += (mouseX-pmouseX) * factor;    }    

if(keyCode==CONTROL){ // Ctrl + Maus --> Translation  
transx+=(mouseX-pmouseX);      transy+=(mouseY-pmouseY);    }  }}





void keyPressed(){  
 if(key!=CODED){    
     if (key=='1'){      
       rotx=0;      
       roty=0;    
       transx=width/2;      
       transy=height/2;      
       transz=-300;    
     }    
     
     if (key=='3'){      
       rotx=0;      
       roty=radians(-90);      
       transx=width/2;      
       transy=height/2;      
       transz=-300;    
      }    
     
     if (key=='7'){      
       rotx=radians(-90);      
       roty=0;      
       transx=width/2;      
       transy=height/2;    
       transz=-300;    
     }    
     }  
   
 if (key == CODED) {    
   if(keyCode==CONTROL){      
     if(key=='1'){        
       rotx=0;        
       roty=PI;      
     }      
   
     if(key=='3'){        
       rotx=0;        
       roty=radians(90);      
     }      
   
     if(key=='7'){        
       rotx=radians(90);        
       roty=0;      
     }    
   }  
 }
}

Re: "frames" in processing?
Reply #9 - Apr 13th, 2010, 2:12am
 
beginner_processing wrote on Apr 12th, 2010, 1:47pm:
but this all doesn't work. because I can't use the controlP5 with the P3D renderer.
[...]
so I should seperate these two things, the buttons and the coordinate system, but that also doesn't work.. what shall I do
I've no idea..

Uh, well, follow my suggestion If you draw in a P3D graphics and leave the main sketch in default mode, I think it should work.
Try this with a simpler sketch, one control, base stuff in 3D. Then you can extend to your more complex sketch.

Actually, there was a very similar thread in the past, where I answered in a similar way, and gave an example:
frame around the applet / saving without a frame
Page Index Toggle Pages: 1