我正在处理光线跟踪器,我在线上得到错误
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
}
我尝试在公共场所制作一个ArrayList曲面,我尝试制作一个getter函数,我尝试更改&#34; ArrayList曲面&#34;到&#34; ArrayList Sphere&#34; (里面小于大于号)。
我不知道为什么这不起作用。我怀疑它可能只是处理程序的错误,它有些错误。
谢谢!
答案 0 :(得分:1)
错误消息正确告诉您问题所在。从
更新以下声明private Surface surface;
到
private Sphere surface;