// lightbulb class that renders pointlight with a colored sphere to visualize its position class LightBulb extends GGen { // GGen network. a light + sphere at the same position FlatMaterial mat; GPointLight light --> GSphere bulb --> this; // set up sphere to be a flat color bulb.mat(mat); mat.color(@(1, 1, 1)); @(1, 1, 1) => bulb.scale; // set light falloff light.falloff(0.14, 0.7); // falloff chart: https://wiki.ogre3d.org/tiki-index.php?page=-Point+Light+Attenuation vec3 lightCol; Math.random2f(0.5, 1.5) => float pulseRate; // randomize pulse rate for fading in/out fun void color(float r, float g, float b) { @(r, g, b) => lightCol; // save the set color mat.color(@(r, g, b)); // set material color light.diffuse(@(r, g, b)); // set light diffuse color } // this is called automatically every frame but ChuGL // IF the GGen or one of its parents is connected to GG.scene() fun void next(float i) { // fluctuate intensity // 0.5 + 0.5 * Math.sin((now/second) * pulseRate) => light.intensity; // range [0, 1] i => light.intensity; // fluctuate material color light.intensity() * lightCol => mat.color; } } adc => Gain g => OnePole p => blackhole; adc => g; 200 => g.gain; 3 => g.op; 0.9 => p.pole; // camera angle GG.camera() @=> GCamera @ cam; @(0, 10, 10) => cam.position; cam.lookAt(@(0, 0, 0)); // scene setup GG.scene() @=> GScene @ scene; scene.backgroundColor(@(0, 0, 0)); // black background scene.light().intensity(0); // disable default directional light // ground for lights to cast on GPlane ground --> GG.scene(); @(10, 10, 1) => ground.scale; @(-Math.PI/2, 0, 0) => ground.rotation; // make the plane lay flat // instantiate lightbulbs GGen lightGroup --> scene; LightBulb whiteLight--> lightGroup; 1 => lightGroup.posY; // lift all lights 1 unit off the ground // -2 => whiteLight.posZ; whiteLight.color(1, 1, 0.5); // Gameloop ================================== while (true) { // rotate lights // GG.dt() => lightGroup.rotY; // nextFrame <<< p.last()>>>; p.last() + 1 / 2=> float input; whiteLight.next(input); GG.nextFrame() => now; }