gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 11:02:46 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com