Problem with lighting
in
Programming Questions
•
1 year ago
Hi, specialists!
In a sense I'm new to Processing and have big trouble with getting grip on the (otherwise impressive!) built-in 3D-abilities.
Are you with me, the following code should show a sphere »containing« a cube with its edges reaching out of the sphere (although I do not understand the order of the translations and rotations, but that is another cup of tea). The whole scene ought to be lit from the top right side with the light shining into the scene.
void setup() {
size (400,400,OPENGL);
}
void draw() {
directionalLight ( 128,128,128, -1,1,-1);
translate(width/2,height/2,0);
noStroke();
fill(128,128,255);
sphere (100);
fill(255,255,255);
rotateX(PI/4);
box(135);
}
Now the question is: why is the sphere lit as expected but the box's edges are as black as my soul? And, what's more, when the last stanza is expanded with a 2nd rotation like this
fill(255,255,255);
rotateX(PI/4);
rotateZ(PI/4);
box(135);
then the box seems to be lit from below!?
That doesn't make any sense to me - can anyone help me? (I have more code samples, but OpenGL seems to do what it wants - I just can't make sense of what I'm seeing. And I've tried for hours, now).
Thanks for all hints!
Cheers from Vienna/Austria
phaidros
In a sense I'm new to Processing and have big trouble with getting grip on the (otherwise impressive!) built-in 3D-abilities.
Are you with me, the following code should show a sphere »containing« a cube with its edges reaching out of the sphere (although I do not understand the order of the translations and rotations, but that is another cup of tea). The whole scene ought to be lit from the top right side with the light shining into the scene.
void setup() {
size (400,400,OPENGL);
}
void draw() {
directionalLight ( 128,128,128, -1,1,-1);
translate(width/2,height/2,0);
noStroke();
fill(128,128,255);
sphere (100);
fill(255,255,255);
rotateX(PI/4);
box(135);
}
Now the question is: why is the sphere lit as expected but the box's edges are as black as my soul? And, what's more, when the last stanza is expanded with a 2nd rotation like this
fill(255,255,255);
rotateX(PI/4);
rotateZ(PI/4);
box(135);
then the box seems to be lit from below!?
That doesn't make any sense to me - can anyone help me? (I have more code samples, but OpenGL seems to do what it wants - I just can't make sense of what I'm seeing. And I've tried for hours, now).
Thanks for all hints!
Cheers from Vienna/Austria
phaidros
1