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

标签 java class arraylist processing

我在处理光线追踪器时在线上出错

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

“surface.center 无法解析或不是字段”

这是我的代码。

//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;

关于java - 无法解析或不是字段(处理中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30653175/

相关文章:

java - 如何在微调器中获取国家/地区名称和国家/地区调用 (ISD) 代码

php - 无法从数组中的类访问静态成员变量

java - 如何在 Java 中从 ArrayList 中切出 ArrayList?

android - 如何在 SQLite 中存储 ArrayList<GeoPoint>?

java - 如何找到短语的第n个字母,并保留所有的起始字母?

java - 使用 Java 流从现有 map 创建新 map

java - 无法将背景图像添加到我的 jpanel,找不到错误,我也不明白错误

python - 封装导入模块的范围

android - 如何在自定义 ImageView 中将 R.Drawable 作为参数传递

java - 将 HTML 代码添加到列表中