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 & HelpOpenGL and 3D Libraries › Broken lines in 3d graphics with P3D
Page Index Toggle Pages: 1
Broken lines in 3d graphics with P3D (Read 938 times)
Broken lines in 3d graphics with P3D
Sep 21st, 2005, 11:16pm
 
Hi,

I am a newbie to processing and am having trouble with 3d graphics on it. I might be making some mistake with my code here but I have tried several things and nothing works.
I have comfortably decided to put the blame on processing and so here is my post.

If any of you can comment it will be great.

OS: windows xp sp2
Version of processing: 0.91 beta
Comments: I am using P3D. I realized OPENGL had several issues so I am not using it.

The Problem:
Below is a simple code which is supposed to draw a box and when a user presses any key it should rotate about the X axis by 5 degrees.

The trouble is that the box which rotates is all cropped and broken.

When I first saw this I felt it is because ortho by default is ortho(0,width,0,height,-10,+10). I suspected that the -10 and +10 is causing this, so I added ortho(0,width,0,height,-100,+100) but that simply broke the whole thing - the box simply does not appear.

Is this a problem with my code? or is this a problem with processing? If it is the former please let me know what is wrong here. If it is the latter is there a work around?

This sounds fairly fundamental to me so somebody must have hit this. I searched the database and previous posts but found nothing pertaining to ortho and P3D.

Please help. Thanks in advance.

--- here is my code ---
color black = color(0,0,0);
color white = color(255,255,255);
int X=0;
void setup()
{
size(200, 200, P3D);
background(255,255,255);
lights();
}
void drawAtom(color clr)
{
 pushMatrix();
 // Uncomment stuff below or just ortho line
 // and nothing will showup
 //resetMatrix();
 //ortho(0,200,0,200,-100,100);
 stroke(clr);
 translate(50,50,0);
 rotateX(radians(X));
 translate(25,25,0);
 box(15);
 popMatrix();
}
void draw()
{
}
void keyPressed()
{
 drawAtom(white);
 X = X+5;
 drawAtom(black);
}
Re: Broken lines in 3d graphics with P3D
Reply #1 - Sep 22nd, 2005, 12:08pm
 
I've not tested the code, but I'm fairly sure that you don't want to put the draw stuff inside keyPressed().

keyPresed() will get called more than once during a draw() cycle, and so in one frame, you're probably having drawAtom called many times which is possibly causing the problem.

you could try something like this:
Code:

boolean doDraw;
...
void setup()
{
...
doDraw=false;
}

void draw()
{
if(doDraw)
{
drawAtom(white);
X = X+5;
drawAtom(black);
}
}

//note this will work oddly if you press mutliple keys, and will become false as soon as any are released.. maybe link it to a specific key...

void keyPressed()
{
doDraw=true;
}

void keyReleased()
{
doDraw=false;
}
Re: Broken lines in 3d graphics with P3D
Reply #2 - Sep 22nd, 2005, 3:05pm
 
Thanks for the response John. I tried moving stuff out of keypressed into draw as you mentioned, but the problem still exists.

I strongly feel this is something to do with the projection.  

Another interesting thing to see is that with with "ortho" it totally vanishes.

Here is what I tried:
void draw()
{
 if (doDraw == true)
 {
   drawAtom(white);
   X = X+5;
   drawAtom(black);
 }
}
void keyPressed()
{
 doDraw=true;
}

void keyReleased()
{
 doDraw=false;  
}
Page Index Toggle Pages: 1