Using peasycam within a class?

Hi! I’m coding some projections that need to be switched between using keypresses. Each projection is its own class and one of them, “Stars”, which just displays a bunch of stars, is 3d. I’m using peasycam for this, but I keep getting this error: ‘The constructor “PeasyCam(Stars,int)” does not exist’ on my line that says cam = new PeasyCam(this, 100);

Could someone tell me why this is happening and how to fix it?
Any help would be greatly appreciated!! :slight_smile:
here is the full code for the class:

public class Stars extends Scene
{
  ArrayList<Star> stars;
  float b = 0;
  boolean fade;
  int x;
  import peasy.*;
 
  
  PeasyCam cam;
  
  void initialize() {
    stars = new ArrayList <Star>();
  // size(600,600,P3D);
    fullScreen(P3D);
    cam = new PeasyCam(this, 100);
    cam.setMinimumDistance(50);
    cam.setMaximumDistance(500);
    
    for (int i = 0; i < 80; i++)
    {
      Star s = new Star();
      stars.add(s);
    }
  }
  void display() 
  {
    background(b);
    for(Star s : stars)
    s.display();
    if (fade)
      fade();
    x ++;
    camera (x, height/2, (height/2)/tan(PI/6), x, height/2, 0,0,1,0);
  }
  
  
  class Star
  {
    float x = random(-2000, 2000);
    float y = random(-2000, 2000);
    float z = random(-2000,2000);
  
    /*Star()
    {
    }
    */
    void display()
    {
      pushMatrix();
      noStroke();
      fill(255);
      translate(x,y,z);
      sphere(5);
      popMatrix();
    }    
  }
  
  void fade()
  {
    if (b < 255)
      b += 1;
    for (int i = stars.size()-1; i > 0; i --)
      {
        Star s = stars.get(i);
        stars.remove(s);
      }
  }
  
  
   void keyPressed()
  {
    
    if (key == ' ')
    {
      fade = true;
    }
  }
}
1 Like

Peasycam requires a constructor like this :

PeasyCam (PApplet, int);

So a reference to the PApplet and an Integer.

You use this PeasyCam(Stars, Int), which does not exist.

That happens, because the normal way to initialize a PeasyCam instance is to give it a reference to the PApplet like this :
PeasyCam(this, 100);

‚this‘ is a reference to the class the line is a part of. ‚this‘ should give back a PApplet reference if you‘re using it within the PApplet, which you are not. You‘re using it within the class Stars, so it returns a reference with class Stars.

To change that, either initialize your PeasyCam within the PApplet (so outside of any self-made classes). Or you can give your Stars class a reference to the Papplet. So void initialize() would become void initialize(PApplet parent) and you can use parent instead of ‚this‘ in your PeasyCam.

2 Likes