Bug 161 : ortho() causes some surfaces to go black
Last modified: 2005-09-26 17:14




Status:
RESOLVED
Resolution:
WONTFIX -
Priority:
P3
Severity:
normal

 

Reporter:
Zaratustra
Assigned To:
fry

Attachment Type Created Size Actions

Description:   Opened: 2005-09-26 09:03
When the code below is run in ortho() mode, some areas that should be lit are
completely black. The effect increases as the scale grows (with the A key) and
decreases as the scale shrinks (with the Z key)

-------------------------------------------

import processing.opengl.*;

int heightmap[][]={
{ 0,1,1,1,1,1,0,0,0,0,0 } ,
{ 0,1,2,2,2,1,0,0,0,0,0 } ,
{ 0,1,2,3,2,1,0,0,0,0,0 } ,
{ 0,1,2,2,2,1,0,1,1,1,1 } ,
{ 0,1,1,1,1,1,0,1,1,1,1 } ,
{ 0,0,0,0,0,0,0,1,1,1,1 } ,
{ 0,1,1,1,1,1,0,0,0,0,0 } ,
{ 0,1,2,2,2,1,0,0,0,0,0 } ,
{ 0,1,2,2,2,1,0,0,0,0,0 } ,
{ 0,1,2,2,2,1,0,0,0,0,0 } ,
{ 0,1,2,2,2,1,0,0,0,0,0 } };

boolean iso=true;

void setup()
{
size(500,500,OPENGL);
if (iso) ortho(-250,250,-250,250,-1000,1000);
else perspective();
}

float rotx, rotz, sprite_scale;
float sprx, spry, sprz;
float xwin=0, ywin=0, zoom=1;

void draw()
{
rotx=HALF_PI/2;//+(mouseY*0.03);
rotz=HALF_PI/2;//+(mouseX*0.03);
sprite_scale=5;
if (iso) sprite_scale*=5*zoom;

background(128);
strokeWeight(3);
// translate(mouseX,mouseY,10);
// translate(150,100,100);
if (!iso) translate(width/2,height/2,300*zoom);
// else translate(width,0,50);
else translate(width/2,height/2,300);

rotateX(rotx);
rotateZ(rotz);
translate(xwin,ywin,0);
if (!iso) scale(10,10,5);
else scale(50*zoom,50*zoom,25*zoom);
if (!iso) translate(-5,-5,0);
else translate(-5*zoom,-5*zoom,0);
directionalLight(255,255,255,0,1,-1);
for (int y=0; y<10; y++)
{
beginShape(QUADS);
for (int x=0; x<10; x++)
{
if (heightmap[x][y+1]==heightmap[x+1][y])
{
vertex(x, y, heightmap[x][y]);
vertex(x, y+1, heightmap[x][y+1]);
vertex(x+1, y+1, heightmap[x+1][y+1]);
vertex(x+1, y, heightmap[x+1][y]);
}
else
{
vertex(x, y+1, heightmap[x][y+1]);
vertex(x, y, heightmap[x][y]);
vertex(x+1, y, heightmap[x+1][y]);
vertex(x+1, y+1, heightmap[x+1][y+1]);
}
}
endShape();
}
}

void mousePressed()
{
if (iso) iso=false; else iso=true;
if (iso) ortho(-250,250,-250,250,-1000,1000);
else perspective();
}

void keyPressed()
{
if (keyCode==UP) ywin-=2;
if (keyCode==DOWN) ywin+=2;
if (keyCode==LEFT) xwin-=2;
if (keyCode==RIGHT) xwin+=2;
if (key=='a' || key=='A') zoom+=0.05;
if (key=='z' || key=='Z') zoom-=0.05;
}
Additional Comment #1 From fry 2005-09-26 16:26
i could be wrong, but i think this is a bug in your code, for how you're using ortho(). you're
setting up a very different coordinate system and need to adjust the lighting accordingly.
Additional Comment #2 From Zaratustra 2005-09-26 17:07
(In reply to comment #1)
> Additional Comment #1 From fry 2005-09-26 16:26 [reply] i could be wrong, but i
think this is a bug in your code, for how you're using ortho(). you're setting up a very
different coordinate system and need to adjust the lighting accordingly.

Changing the coordinate system around seems to work around the problem.