Skip to content

Projector Simulator #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions MusicBeam/ProjectorSimulator.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
public class ProjectorSimulator extends PApplet{

private PImage projImg;
private float eyeX,eyeY,eyeZ,sceneX,sceneY,sceneZ;
private float cameraDistance, cameraTheta, cameraPhi;

private float beamWeight;

public ProjectorSimulator(){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment to what this is feature does.

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){
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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove commended code.

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(){
pushMatrix();
blendMode(ADD);
translate(projImg.width,0,0);
rotateY(PI);
strokeWeight(beamWeight);

projImg.loadPixels();
for(int y=0; y<projImg.pixelHeight; y+=(2*beamWeight)){
for (int x =0; x<projImg.pixelWidth; x+=(2*beamWeight)){
int loc = x + y * width;
color c = projImg.pixels[loc];
if( c !=0 && c != color(0)){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove double whitespaces

stroke(c,25);
line(x,y,0,width/2,height/2,500);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a trailing whitespace after a comma

}
}
}
projImg.updatePixels();
popMatrix();
}

private void drawRoom(){
blendMode(BLEND);
pushMatrix();
translate(width/2,height/2,-250);
noFill();
stroke(0);
box(projImg.width,projImg.height, 500);
popMatrix();
}

private void drawImage(){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the unused code.

pushMatrix();
translate(projImg.width,0,0);
rotateY(PI);
image(projImg,0,0);
popMatrix();
}
}
24 changes: 18 additions & 6 deletions MusicBeam/Stage.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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(){
Expand Down