hope someone can help me with this. I’m using the p5.js lib in webGL. I have a sphere as earth rotating around x,y,z coordinates (0,0,0 - where the sun would be) then a I have another smaller sphere rotating around earth as the moon. I have a ‘pointLight’ that is located at (0,0,0) that’s basically the sun’s light shining in all directions. Unfortunately when the moon is between the sun and the earth it doesn’t cast a shadow onto earth. Does anyone know how I would do this?
function setup() {
createCanvas(800, 800, WEBGL);
}
function draw() {
background(0);
camera(0, -150, (height/2.0) / tan(PI*30.0 / 180.0), 0, 0, 0, 0, 1, 0);
pointLight(250, 250, 250, 0, 0, 0);
globalOrbSpeed+=0.1;
globalRotSpeed+=0.1;
renderPlanet(imgEarth, -12, 2, 120, 400,0,0, true);
}
function renderPlanet(txture, rotSpeed, orbSpeed, planetRad, transX, transY, tranZ, moonPlanet) {
push()
texture(txture);
rotateY(radians(globalOrbSpeed*orbSpeed));
translate(transX,transY,tranZ);
rotateY(radians(globalRotSpeed*rotSpeed));
sphere(planetRad, 100, 100);
if (moonPlanet === true) {
directionalLight(0, 255, 0, 1, 0, 0);
renderPlanet(imgMoon, -30, 18, 36, 220,0,0,false);
}
pop()
}