With 's' you can move backward.
The mouse position is for the concentration. If you move backwards then the light can stop shining on the sphere like instant.
Why is that? And is it possible to increase it's range?
- import peasy.*;
- PeasyCam cam;
- PVector interest;
- SpotLight spotLigth;
- void setup() {
- size(600, 600, P3D);
- cam = new PeasyCam(this, 400);
- interest = new PVector(0, 0, -100);
- spotLigth = new SpotLight(color(255, 200, 200), 0, 0, 0, interest, PI, 600);
- }
- void draw() {
- background(0);
- if (keyPressed) {
- if (key == 'w') {
- spotLigth.z --;
- }
- if (key == 's') {
- spotLigth.z ++;
- }
- if (key == 'a') {
- spotLigth.x --;
- }
- if (key == 'd') {
- spotLigth.x ++;
- }
- if (key == 'q') {
- spotLigth.y ++;
- }
- if (key == 'e') {
- spotLigth.y --;
- }
- }
- float concentration = map(mouseX, 0, width, -50, 100);
- println(concentration);
- spotLigth.concentration = concentration;
- noStroke();
- spotLigth.render();
- translate(interest.x, interest.y, interest.z);
- sphere(80);
- }
- class SpotLight {
- /*
- // red or hue value (depending on current color mode)
- float v1;
- // float: green or saturation value (depending on current color mode)
- float v2;
- // float: blue or brightness value (depending on current color mode)
- float v3;
- */
- color c;
- // xyz-coordinate of the light
- float x;
- float y;
- float z;
- // direction along the x axis
- // float nx;
- // float ny;
- // float nz;
- PVector interest;
- // angle of the spotlight cone
- float angle;
- // exponent determining the center bias of the cone
- float concentration;
- SpotLight(color c, float x, float y, float z, PVector interest, float angle, float concentration) {
- this.c = c;
- this.x = x;
- this.y = y;
- this.z = z;
- this.interest =interest;
- this.angle = angle;
- this.concentration = concentration;
- }
- void render() {
- float v1, v2, v3;
- if (g.colorMode == RGB) {
- v1 = red(c);
- v2 = green(c);
- v3 = blue(c);
- }
- else {
- v1 = hue(c);
- v2 = green(c);
- v3 = blue(c);
- }
- PVector v = new PVector(x, y, z);
- v.add(interest);
- v.normalize();
- float nx = v.x;
- float ny = v.y;
- float nz = v.z;
- spotLight(
- v1, v2, v2,
- x, y, z,
- nx, ny, nz,
- angle,
- concentration);
- }
- }
1