From ee081f35661b2bd3d308b64c8d0d2825acf21378 Mon Sep 17 00:00:00 2001 From: LuisMQuinones Date: Fri, 25 May 2018 20:37:36 -0400 Subject: [PATCH 1/4] Init ProjectorSimulator(Issue #59) This is the initial commit for the Projector Simulator. Implemented the base for Projector Simulator. It has a working camera movement, room representation, and projector source. --- MusicBeam/ProjectorSimulator.pde | 136 +++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 MusicBeam/ProjectorSimulator.pde diff --git a/MusicBeam/ProjectorSimulator.pde b/MusicBeam/ProjectorSimulator.pde new file mode 100644 index 0000000..cac5b11 --- /dev/null +++ b/MusicBeam/ProjectorSimulator.pde @@ -0,0 +1,136 @@ +public class ProjectorSimulator extends PApplet{ + + private PImage projImg; + private float eyeX,eyeY,eyeZ,sceneX,sceneY,sceneZ; + private float cameraDistance, cameraTheta, cameraPhi; + + public ProjectorSimulator(){ + super(); + } + + public void settings() { + pixelDensity(displayDensity()); + size(800, 600, P3D); + } + + public void setup(){ + projImg = createImage(800,600,ARGB); + + eyeX = 0; + eyeY = 0; + eyeZ = 1; + + sceneX = width/2; + sceneY = height/2; + sceneZ =-250; + + cameraDistance = 250; + cameraTheta = 0.01; + cameraPhi = PI/2; +} + + public void setImage(PImage img){ + projImg = img; + } + + public void draw(){ + background(120); + if(keyPressed) + handleKeyPressed(); + camera(eyeX,eyeY,eyeZ,sceneX,sceneY,sceneZ,0,1,0); + float [] coord= toCartesian(cameraDistance, cameraTheta,cameraPhi); + + eyeX = sceneX + coord[0]; + eyeY = sceneY + coord[1]; + eyeZ = sceneZ + coord[2]; + + //drawImage(); //uncomment to see image from stage + drawBeams(); + drawRoom(); + } + + private void handleKeyPressed(){ + if(keyPressed){ + if(key == 'w'){ + cameraDistance -=10; + } + else if(key == 'a'){ + cameraTheta -=0.1; + } + else if(key =='s'){ + cameraDistance +=10; + } + else if(key =='d'){ + cameraTheta +=0.1; + } + else if(key == 'q'){ + cameraPhi -=0.1; + } + else if(key == 'e'){ + cameraPhi +=0.1; + } + else if(key ==CODED){ + if(keyCode == UP){ + sceneZ -= 10; + } + else if(keyCode ==DOWN){ + sceneZ +=10; + } + else if(keyCode == LEFT){ + sceneX -=10; + } + else if(keyCode == RIGHT){ + sceneX += 10; + } + } + } + } + private float [] toCartesian(float p, float theta, float phi){ + float x = p * sin(phi)*cos(theta); + float y = p * sin(phi)*sin(theta); + float z = p * cos(phi); + float [] r = {y,z,x}; + return r; +} + + private void drawBeams(){ + stroke(0,120); + pushMatrix(); + blendMode(ADD); + translate(projImg.width,0,0); + rotateY(PI); + strokeWeight(1); + + projImg.loadPixels(); + for(int y=0; y Date: Fri, 25 May 2018 21:23:36 -0400 Subject: [PATCH 2/4] Modify Stage to support ProjectorSimulator - Add ProjectorSimulator sim field - Arrange draw to support Projector Simulator - ProjectorSimulator work on debug mode --- MusicBeam/Stage.pde | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/MusicBeam/Stage.pde b/MusicBeam/Stage.pde index b4d99d1..07b2748 100644 --- a/MusicBeam/Stage.pde +++ b/MusicBeam/Stage.pde @@ -4,11 +4,19 @@ import processing.core.PSurface; public class Stage extends PApplet { MusicBeam ctrl = null; + ProjectorSimulator sim; Stage (MusicBeam main) { super(); ctrl = main; + sim = new ProjectorSimulator(); + + if(ctrl.debugMode){ + String[] args = {"Simulator"}; + PApplet.runSketch(args, sim); + } + } public void settings() { @@ -34,16 +42,20 @@ public class Stage extends PApplet { background(0); noStroke(); - if (ctrl.debugMode) { - fill(120, 100, 100); - textSize(30); - text(frameRate, 100, 100); - } - translate(width/2, height/2); for (int i = 0; i < effectArray.length; i++) if (effectArray[i].isActive()) effectArray[i].refresh(); + + if (ctrl.debugMode) { + resetMatrix(); + PImage img = get(); + sim.setImage(img); + + fill(120, 100, 100); + textSize(30); + text(frameRate, 100, 100); + } } public int getMaxRadius(){ From 06b5e4c3d6ba9c8b565d0ca3e8d388200fd690fe Mon Sep 17 00:00:00 2001 From: LuisMQuinones Date: Fri, 1 Jun 2018 14:33:46 -0400 Subject: [PATCH 3/4] Fix ProjectorSimulator for Retina Display Problem: projImg.width and projImg.height does not return the proper values for Retina Displays. Solution: Instead of using projImg.width and projImg.height; use projImg.pixelWidth and projImg.pixelHeight. These will return the proper output for normal and retina displays. The rest of the code should work untouched. The initial camera position was also moved back to give a better view of the entire room --- MusicBeam/ProjectorSimulator.pde | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/MusicBeam/ProjectorSimulator.pde b/MusicBeam/ProjectorSimulator.pde index cac5b11..5a48de1 100644 --- a/MusicBeam/ProjectorSimulator.pde +++ b/MusicBeam/ProjectorSimulator.pde @@ -4,12 +4,15 @@ public class ProjectorSimulator extends PApplet{ private float eyeX,eyeY,eyeZ,sceneX,sceneY,sceneZ; private float cameraDistance, cameraTheta, cameraPhi; + private float beamWeight; + public ProjectorSimulator(){ super(); } public void settings() { pixelDensity(displayDensity()); + beamWeight = pixelDensity; size(800, 600, P3D); } @@ -24,7 +27,7 @@ public class ProjectorSimulator extends PApplet{ sceneY = height/2; sceneZ =-250; - cameraDistance = 250; + cameraDistance = 800; cameraTheta = 0.01; cameraPhi = PI/2; } @@ -94,20 +97,19 @@ public class ProjectorSimulator extends PApplet{ } private void drawBeams(){ - stroke(0,120); pushMatrix(); blendMode(ADD); translate(projImg.width,0,0); rotateY(PI); - strokeWeight(1); + strokeWeight(beamWeight); projImg.loadPixels(); - for(int y=0; y Date: Fri, 8 Jun 2018 13:48:14 -0400 Subject: [PATCH 4/4] Reformat, comment, and clean code - Make changes that @codingjoe requested. - Use Google Java Style Guide to reformat code. - Comment and cleaned code for readability and maintainability. --- MusicBeam/ProjectorSimulator.pde | 203 +++++++++++++++---------------- 1 file changed, 97 insertions(+), 106 deletions(-) diff --git a/MusicBeam/ProjectorSimulator.pde b/MusicBeam/ProjectorSimulator.pde index 5a48de1..6ec29a5 100644 --- a/MusicBeam/ProjectorSimulator.pde +++ b/MusicBeam/ProjectorSimulator.pde @@ -1,138 +1,129 @@ -public class ProjectorSimulator extends PApplet{ - +// Projector Simulator +// Author: Luis Quinones +// May - June 2018 +// Description: +// - This tool is meant to help visualize the beams that are created from a +// projector +// - It gives a better understanding of the feel and look of both the effect and +// the room the projector is in +// - A stage instance is responsible for initializing and starting the thread +// - The stage instance that is responsible for Projector Simulator object +// is suppose to call setImage() on its draw() +// Controls: +// Keys 'w' and 's' zooms the camera in and out + +public class ProjectorSimulator extends PApplet { + + // Stage's image: The light beams are + // created based off of this image private PImage projImg; - private float eyeX,eyeY,eyeZ,sceneX,sceneY,sceneZ; - private float cameraDistance, cameraTheta, cameraPhi; - + + // Processing 3D camera's parameters + private float eyeX, eyeY, eyeZ, sceneX, sceneY, sceneZ; + + // The room's (box's) dimensions + private float roomWidth, roomHeight, roomDepth; + + // Used for Standard and Retina (High-DPI Display) + // Used for stroke weight of beam; 1 = Standard, 2 = Retina private float beamWeight; - - public ProjectorSimulator(){ - super(); + + // The number of rows and columns skipped for efficiency + int skip; + + public ProjectorSimulator() { + super(); } - + public void settings() { pixelDensity(displayDensity()); beamWeight = pixelDensity; size(800, 600, P3D); } - - public void setup(){ - projImg = createImage(800,600,ARGB); - - eyeX = 0; - eyeY = 0; - eyeZ = 1; - - sceneX = width/2; - sceneY = height/2; - sceneZ =-250; - - cameraDistance = 800; - cameraTheta = 0.01; - cameraPhi = PI/2; -} - - public void setImage(PImage img){ + + public void setup() { + projImg = createImage(800, 600, ARGB); + + roomWidth = projImg.width; + roomHeight = projImg.height; + roomDepth = 500; + + sceneX = roomWidth / 2.0; + sceneY = roomHeight / 2.0; + sceneZ = -1.0 * roomDepth / 2.0; + + eyeX = sceneX; + eyeY = sceneY; + eyeZ = roomDepth; + + skip = 2; + } + + // Sets the image that the simulation is based on + public void setImage(PImage img) { projImg = img; } - - public void draw(){ + + public void draw() { background(120); - if(keyPressed) + + if (keyPressed) { handleKeyPressed(); - camera(eyeX,eyeY,eyeZ,sceneX,sceneY,sceneZ,0,1,0); - float [] coord= toCartesian(cameraDistance, cameraTheta,cameraPhi); - - eyeX = sceneX + coord[0]; - eyeY = sceneY + coord[1]; - eyeZ = sceneZ + coord[2]; - - //drawImage(); //uncomment to see image from stage + } + + camera(eyeX, eyeY, eyeZ, sceneX, sceneY, sceneZ, 0, 1, 0); + drawBeams(); - drawRoom(); + drawRoom(); } - - private void handleKeyPressed(){ - if(keyPressed){ - if(key == 'w'){ - cameraDistance -=10; - } - else if(key == 'a'){ - cameraTheta -=0.1; - } - else if(key =='s'){ - cameraDistance +=10; - } - else if(key =='d'){ - cameraTheta +=0.1; - } - else if(key == 'q'){ - cameraPhi -=0.1; - } - else if(key == 'e'){ - cameraPhi +=0.1; - } - else if(key ==CODED){ - if(keyCode == UP){ - sceneZ -= 10; - } - else if(keyCode ==DOWN){ - sceneZ +=10; - } - else if(keyCode == LEFT){ - sceneX -=10; - } - else if(keyCode == RIGHT){ - sceneX += 10; + + // Handles key presses + // 'w' and 's' for zooming camera + private void handleKeyPressed() { + if (keyPressed) { + if (key == 'w') { + eyeZ -= 10; + } else if (key == 's') { + eyeZ += 10; } } } - } - private float [] toCartesian(float p, float theta, float phi){ - float x = p * sin(phi)*cos(theta); - float y = p * sin(phi)*sin(theta); - float z = p * cos(phi); - float [] r = {y,z,x}; - return r; -} - - private void drawBeams(){ + + // Draw lines that simulates the + // beams from a projector + private void drawBeams() { pushMatrix(); blendMode(ADD); - translate(projImg.width,0,0); - rotateY(PI); + translate(projImg.width, 0, 0); + rotateY(PI); strokeWeight(beamWeight); - projImg.loadPixels(); - for(int y=0; y