Skip to content
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

Projector Simulator #60

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

LuisMQuinones
Copy link

Implements #59

Proposed Changes

  • Add ProjectorSimulator class
    • Tool that allows for quick effects prototyping
    • Extends PApplet; runs on its own thread
    • Runs on debugMode
  • Modify Stage class to support ProjectorSimulator
    • Add, init, and start ProjectorSimulator sim field
    • Arrange draw() to accommodate image export to ProjectorSimulator
    • Update sim field in draw()

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.
- Add ProjectorSimulator sim field
- Arrange draw to support Projector Simulator
- ProjectorSimulator work on debug mode
@codingjoe
Copy link
Owner

@LuisMQuinones this is pretty amazing!

I just had a first look and ran it. I noticed that the simulator only shows part of the stage. I attached a screenshot:

screen shot 2018-05-31 at 09 49 15

I'll have a deeper look into the code now. I think we should add a keyboard shortcut to en- and disable the debug mode. Maybe some other people want to play with it. Not everyone has a project at hand when they want to test the software.

@codingjoe
Copy link
Owner

Ok, I think i found the problem. I created a very simplified version of your approach:

public class ProjectorSimulator extends PApplet{
  
  private PImage projImg;
  
  private int hires_factor = 2; 
  
  public ProjectorSimulator(){
    super(); 
  }
  
  public void settings() {
    pixelDensity(displayDensity());
    size(800, 600, P3D);
  }
  
  public void setup(){    
    projImg = createImage(800,600,ARGB);
}
  
  public void setImage(PImage img){
    projImg = img;
  }
  
  public void draw(){
    background(0);
    drawBeams();   
  }

  private void drawBeams(){
    blendMode(ADD);
    strokeWeight(hires_factor);
    
    projImg.loadPixels();
    color[] pixels = projImg.pixels;
    translate(0, 0, -500);
    for(int i=0; i < pixels.length; i+=hires_factor){
      color pixel = pixels[i];
      if(pixel != color(0)){
        stroke(pixel);
        int x = (i % (projImg.width * hires_factor)) / hires_factor;
        int y = (i / (projImg.width * hires_factor)) / hires_factor;
        line(projImg.width/hires_factor, 0, 0, x, y, 500);
      }
    }
  }
}

Now the problem is that projImg.width is does not return the correct result for retina (hi-res) displays. projImg.pixels on the other hand does contain this information.
So the array on my MacBook has 8002 * 6002 pixel. Not 800*600.

@codingjoe codingjoe self-assigned this May 31, 2018
@codingjoe codingjoe self-requested a review May 31, 2018 09:46
@LuisMQuinones
Copy link
Author

Thank you! I really appreciate it. I'm still a student, so I'm still a little shy sharing my ideas and code.

As far as a keyboard shortcut, my suggestion is the '`' key. It is used to open the console in games like CS: GO and other valve games. My concern for enabling and disabling debugMode is starting and properly killing threads.

On the retina fix; I looked at the javadocs for PImage, and using projImg.pixelWidth and projOmg.pixelHeight instead of proj.width and proj.height should fix the problem. That, along with initializing hires_factor to pixelDensity, should fix the problem. It should be a quick fix, and I'll have the commit up shortly.

@LuisMQuinones
Copy link
Author

How's performance?
I think creating a new PImage object every draw cycle (in Stage) is taxing. I tried finding a way to get the PApplet's pgrahics object, but I couldn't get it working.
One trick i did to help with performance is to not draw a light beam for every pixel, so it keeps the number of items being drawn to a minimum. That helped a lot.

@codingjoe
Copy link
Owner

codingjoe commented Jun 1, 2018

@LuisMQuinones no reason to be shy here, I wrote this when I was a student too ;) Also my Java is.... well lets say I don't do much Java these days.

Ok, how do we continue. I would suggest you update your PR to support retina properly. I would probably for now also omit the rotation features.
Hide the feature behind the debug flag for now. We can figure out how to trigger debug mode in a separate PR.

Oh and yes, rendering less pixel is totally fine. Especially on a retina there so many pixel ;)

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
@LuisMQuinones
Copy link
Author

I don't quite understand, "I would probably for now also omit the rotation features.
Hide the feature behind the debug flag for now. "

In the current build, the tool is only launched if the debugMode flag is true. User's can:
- Move the camera along theta in spherical coordinates with 'a' and 'd'
- Move the camera distance with 'w' and 's'
- Move the camera along phi in spherical coordinates 'q' and 'e'
- Move the point of reference (in 2D) with the arrow keys
So the tool itself( and the window) doesn't launch if the debug flag is off.

Do you want the tool to open regardless if it's in debugMode? Do you want the tool to open,
but the navigations features are turned off until the debugMode flag is true?

I know it will help people visualize the effects better if the tool opens up alongside the stage window, but my concern would be too many windows to handle for the user.

As my understanding, this is what you when launching the app regularly:
The controller, the projector simulator (without navigation and controls), and the stage at fullscreen at startup?

@LuisMQuinones
Copy link
Author

The simple fix in the last commit should fix the retina issues. I don't have a retina display myself to test it out. @codingjoe let me know if the commit fixes the retina issues

Copy link
Owner

@codingjoe codingjoe left a comment

Choose a reason for hiding this comment

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

Hi @LuisMQuinones what I mean was:
Please remove the rotation feature. It adds complexity more than it adds functionality. For the sake of maintainability I would drop it. Unless you think it's really helpful.

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.

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

color c = projImg.pixels[loc];
if( c !=0 && c != color(0)){
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


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.

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.

- Make changes that @codingjoe requested.

- Use Google Java Style Guide to reformat code.

- Comment and cleaned code for readability and maintainability.
@LuisMQuinones
Copy link
Author

Bump message. It's been a week since I've made the latest commit.

@codingjoe Did you look at the changes that I've made? I've made the changes you wanted, reformat the rest of the code to Google Java Style Guide standards, and documented/commented the class, fields, and methods.

I think the rotation feature and its associated camera system is a big part of the tool, but I'll voice my concern when this PR is merged, and I post my opinion on the issue thread.

@codingjoe
Copy link
Owner

Hi @LuisMQuinones sorry for the late response. I was super busy at work. Ok, so I didn't review the code yet, but I tested it. It still doesn't seem to work correctly for retina displays. I still only see half the effect.
screen shot 2018-06-30 at 14 26 44

@codingjoe
Copy link
Owner

Oh btw, I am trying to find a sponsor in MA for you ;)

@codingjoe
Copy link
Owner

@LuisMQuinones I found some hardware for you :) just send me your shipping address to [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants