// 1. Prepare mouse listener // HID input and a HID message Hid hi; HidMsg msg; // which mouse 0 => int device; // get from command line if( me.args() ) me.arg(0) => Std.atoi => device; // open mouse 0, exit on fail if( !hi.openMouse( device ) ) me.exit(); <<< "mouse '" + hi.name() + "' ready", "" >>>; // 2. Set up the ChuGL scene GScene scene --> GG.scene(); scene.enableFog(); GSphere ball --> GG.scene(); ball.sca( @(.5, .5, .5)); ball.mat().color( @(.25, .25, 1) ); GG.camera().posZ( 100 ); GG.windowed(512, 1024); // make the amplitude of sound obey the inverse square law // GG.camera().worldPos() - ball.worldPos() => posdiff; // Math.pow( posdiff.magnitude(), 2 ) => float attenuation; 0.01 => float attenuation; // 3. Set up the physics simulation 0.01 => float dt; -9.81 => float g; 0.0 => float p; 0.0 => float a; 0.0 => float v; 10 => float m; // define the force applied per mouse click 1000 => float f; ball.posY(p); // 4. Set up the responseive audio // FM synthesis (using Step instead of .sync == 2; see fm2.ck) 1 => float gain; // modulator to carrier SinOsc modulator => SinOsc carrier => UGen directPath => dac; carrier => UGen reverbPath => JCRev reverb => blackhole; // step function, add to modulator output Step step => carrier; // setup direct path gain attenuation * gain => directPath.gain; // setup reverb path, currently the reverb is disabled. 0.01 => reverbPath.gain; 0.5 => reverb.mix; // carrier frequency 440 => float freq; freq => step.next; // modulator frequency freq * 0.618 => modulator.freq; // index of modulation 300 => modulator.gain; // 3. Game loop int counter; while( true ) { // wait on HidIn as event // hi => now; while( hi.recv( msg ) ) { if( msg.isButtonDown() ) { // <<< "mouse button", msg.which, "down" >>>; // <<< "mouse X:", GG.mouseX() >>>; // <<< "mouse Y:", GG.mouseY() >>>; f / m => a; } else { 0 => a; } } a * dt +=> v; g * dt +=> v; v * dt +=> p; ball.posY(p); if( Math.fabs(p) > 8 ){ -v => v; } if( counter % 5 == 0 ) { // GG.camera().worldPos() - ball.worldPos() => posdiff; // 1 / Math.pow( posdiff.magnitude(), 2 ) => attenuation; attenuation * gain => directPath.gain; // <<< "Attenuation: ", attenuation >>>; // <<< "Position: ", p >>>; } 1 +=> counter; // <<< "Position: ", p >>>; // <<< "FPS: ", GG.fps() >>>; 1::ms => now; GG.nextFrame() => now; }