无法解析或不是字段(处理中)

Cannot be resolved or is not a field (Processing)

我正在处理光线追踪器,在线时出现错误

float xn = (this.r.direction.x) - (surface.center.x);

"surface.center cannot be resolved or is not a field"

这是我的代码。

//This is what I called in some other file
scene.surfaces.add(new Sphere(scene.material, center, r));

class Scene {
  private ArrayList<Light> lights;
  private ArrayList<Surface> surfaces;
  private Material material;
  Scene() {
    this.lights = new ArrayList<Light>();
    this.surfaces = new ArrayList<Surface>();
  }
  void setMaterial (Material m) {
    this.material = m;
  }
}

abstract class Surface {
  private Material m;
  Surface(Material m) {
    this.m = m;
  }
}

class Sphere extends Surface {
  private Vec3 center;
  float radius;

  Sphere(Material m, Vec3 center, float radius) {
    super(m);
    this.center = center;
    this.radius = radius;
  }
}

class Hit {
private float time;
private Vec3 normal;
private Surface surface;
private Ray r;

Hit(Ray r, float t) {
  this.r = r;
  this.time = t;
  this.surface = scene.surfaces.get(0);

  float xn = (this.r.direction.x) - (surface.center.x); //ERORR
  float yn = (this.r.direction.y) - (surface.center.y);
  float zn = (this.r.direction.z) - (surface.center.z);

  Vec3 norm = new Vec3(xn, yn, zn);
  norm.normalize();

  this.normal = norm;
  }
}

class Vec3 {
  float x, y, x;
  //then constructor and some functions
}

我尝试在 public 中创建 ArrayList 表面,我尝试创建 getter 函数,我尝试将 "ArrayList Surfaces" 更改为 "ArrayList Sphere"(内部较小的大于号)。

我不知道为什么这不起作用。我怀疑这可能只是 Processing 程序的错误,这是一些错误。

谢谢!

错误消息正确地告诉您问题所在。从

更新以下声明
private Surface surface;

private Sphere surface;