Java 无法解析或不是字段(正在处理)
我正在做一个光线跟踪器的处理,我得到一个错误的在线Java 无法解析或不是字段(正在处理),java,class,arraylist,processing,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
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
}
//这是我在其他文件中调用的
添加(新球体(scene.material,center,r));
课堂场景{
私人阵列灯;
私有阵列列表曲面;
私人材料;
场景(){
this.lights=new ArrayList();
this.surfaces=新的ArrayList();
}
空隙设置材料(材料m){
该材料=m;
}
}
抽象类表面{
私人材料m;
表面(材料m){
这个,m=m;
}
}
类球体延伸曲面{
私人Vec3中心;
浮动半径;
球体(材质m,矢量3中心,浮动半径){
超级(m);
this.center=center;
这个半径=半径;
}
}
班级热{
私人浮动时间;
私人Vec3正常;
私人表面;
二等兵雷·r;
命中(射线r,浮动t){
这个。r=r;
这个时间=t;
this.surface=scene.surfaces.get(0);
float xn=(this.r.direction.x)-(surface.center.x);//ERORR
float yn=(此.r.direction.y)-(surface.center.y);
浮点数zn=(此.r.direction.z)-(表面.center.z);
Vec3范数=新的Vec3(xn,yn,zn);
norm.normalize();
正常=正常;
}
}
Vec3类{
浮动x,y,x;
//然后是构造函数和一些函数
}
我尝试在公共场合制作ArrayList曲面,我尝试制作一个getter函数,我尝试将“ArrayList曲面”更改为“ArrayList球体”(小于大于号的内部)
我不知道为什么这不起作用。我怀疑这可能只是处理程序的错误,这是一些什么错误
谢谢 错误消息正确地告诉您问题所在。从更新以下声明
private Surface surface;
到
类
Surface
没有属性center
,因此无法找到center
。你的类球体
确实有一个中心
,但不是每个曲面
都是球体
。我有一个抽象的曲面,其中球体是一种类型,三角形是另一种类型。我不知道撞击内的表面是球体还是三角形。。。这是不可能的吗?我是否只需要创建两个私有三角形;私人领域sph;保留一个空值,然后使用另一个?你应该读一些。。。这就是我得到的。。。
private Sphere surface;