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 › PImage Problem
Page Index Toggle Pages: 1
PImage Problem (Read 627 times)
PImage Problem
Oct 25th, 2006, 10:31pm
 
Hi

Hope I am posting in the correct thread -

I am trying to include an image that will displayed constantly in the same location for the entire period of use of the applet. On setup the title displays, once the applet enters the draw routine, I can no longer see the title. Because of the background() (which I need). Further more, when I disable the background(), my title has been traslated and scaled to another area of the display and is affected by the what is done in drawTitleImg.drawC();

http://www.swpspce.net/c.png <- illustrates what I would like to achieve.
http://www.swpspce.net/a.png <- illustrates my current problem

thanks in advance for any assistance
angelo

private DrawHeader drawTitleImg;
private PImage guiTitleImg;

void setup()
{
 size(800, 600, OPENGL);

 guiTitleImg = loadImage("titleBC.gif");
 image(guiTitleImg, 10, 10);

 noStroke();
 rect(10,72,340,240);
 drawTitleImg = new DrawHeader();
}

void draw()
{
drawTitleImg.drawC();

pushMatrix();
translate(0,0,0);
image(guiTitleImg, 10, 10);
  noStroke();
rect(360,72,430,430);
rect(10,72,340,240);
popMatrix();
 }


private class DrawHeader
{
 private PImage guiTitleImg;
 
 public DrawHeader()
 {
 }
 
 public void drawC()
 {
 //background(0,153,255);
 float cameraY = height/2.0;
 //float fov = mouseX/float(width) * PI/2;
 float fov = PI/2;
 float cameraZ = cameraY / tan(fov / 2.0);
 float aspect = float(width)/float(height);
 perspective(fov, aspect, cameraZ/10.0, cameraZ*10.0);
   
pushMatrix();
 translate(width/2, height/2, 0);
 rotateX(-TWO_PI/6);
 rotateY(TWO_PI/3 + mouseX/float(height) * TWO_PI);
 rotateZ(TWO_PI/3 + mouseY/float(height) * TWO_PI);
 fill(#0066AA, 255);
    stroke(#0066FF, 125);
 box(100);
 translate(0, 0, 0);
 rotateX(-TWO_PI/6);
 rotateY(TWO_PI/3 + mouseX/float(width) * TWO_PI);
 rotateZ(TWO_PI/3 + mouseY/float(height) * TWO_PI);
   fill(#0066AA, 125);
   stroke(#0066FF, 125);
 box(100);
 popMatrix();
     
 }
 
}  //End drawHeader



Re: PImage Problem
Reply #1 - Oct 25th, 2006, 10:41pm
 
I think you just need to get the order of things right. Anything you draw in setup will be lost, it's a bad place to put any drawing.

Code:

void draw()
{
//background first..
background(128);
//next, anything you want to have in the background
// also any static things behind everything else.
image(title,10,10);
rect(...);

//next anything that moves/alters the display
//put each in a push/pop matrix so they don't interfere
//with each other
pushMatrix();
doThing1();
popMatrix();
pushMatrix();
doThing2();
}
Re: PImage Problem
Reply #2 - Oct 25th, 2006, 10:56pm
 
Hi JohnG

I quickly re-coded up the processing project, the panels and graphic are being displayed semi-correctly although they are still being effected from the translation which occurs in the next instructions. I have changed it around and am still getting a translation occurung where it should not happen.

thanks for you input (one issue down and one to go)...I am stumped here, I would assume that what I am attempting is quite simple? oh, I am using 0119

thanks
angelo


void setup()
{
 size(800, 600, P3D);
 //size(800, 800, P3D);
 guiTitleImg = loadImage("titleBC.gif");
 drawTitleImg = new DrawHeader();
 //noStroke();
}

void draw()
{
 background(125);
 noStroke();
 translate(0,0,0);
 image(guiTitleImg, 10, 10);
 rect(360,72,430,430);
 rect(10,72,340,240);
 

 pushMatrix();
   drawTitleImg.drawC();
 popMatrix();
}


private class DrawHeader
{
 public DrawHeader() {}
 
 public void drawC()
 {
   float cameraY = height/2.0;
 //float fov = mouseX/float(width) * PI/2;  //Zoom Function
 float fov = PI/2;
 float cameraZ = cameraY / tan(fov / 2.0);
 float aspect = float(width)/float(height);
 perspective(fov, aspect, cameraZ/10.0, cameraZ*10.0);
 translate(width/2, height/2, 0);
 rotateX(-TWO_PI/6);
 rotateY(TWO_PI/3 + mouseX/float(height) * TWO_PI);
 rotateZ(TWO_PI/3 + mouseY/float(height) * TWO_PI);
 fill(#0066AA, 255);
    stroke(#0066FF, 125);
 box(100);
 translate(0, 0, 0);
 rotateX(-TWO_PI/6);
 rotateY(TWO_PI/3 + mouseX/float(width) * TWO_PI);
 rotateZ(TWO_PI/3 + mouseY/float(height) * TWO_PI);
   fill(#0066AA, 125);
   stroke(#0066FF, 125);
 box(100);
 }
 
}  //End drawHeader
Re: PImage Problem
Reply #3 - Oct 25th, 2006, 11:04pm
 
Ah-ha, it's the perspective(..) that's causing the problem. Stick perspective(); after the background(128); and it shoudl be okay.
Re: PImage Problem
Reply #4 - Oct 25th, 2006, 11:16pm
 
thanks for your help on this - I must be doing something really wrong here. I dd what you suggested and it does the same thing....

I removed the following lines from DrawHeader
   float cameraY = height/2.0;
 float fov = PI/2;
 float cameraZ = cameraY / tan(fov / 2.0);
 float aspect = float(width)/float(height);
 perspective(fov, aspect, cameraZ/10.0, cameraZ*10.0);

and placed them in the draw(){} following the background();

still no cookie...I will trying starting from scratch, maybe there is a problem specifically here on my side.

angelo

Re: PImage Problem
Reply #5 - Oct 25th, 2006, 11:56pm
 
No no, I meant add an extra perspective(); (blank, no arguments) just after background, leave the other parts in drawHeader.
Re: PImage Problem
Reply #6 - Oct 26th, 2006, 12:38am
 
thanks JohnG - Out of desparation, I just tried that very suggestion.  Just came back to thank you for your help...

So. Thank you-

angelo
Page Index Toggle Pages: 1