正在处理java:尝试克隆对象时,没有复制/存储颜色

vs3odd8k  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(154)

我试着复制一个立方体物体,它由6个面物体组成。每个面对象都由一个向量(成功克隆到新面)和一个颜色(这是未克隆的属性)构成。我最近发现函数重载,不管你信不信,哈哈。
这是用于为多维数据集对象创建多维数据集克隆的构造函数。

// Cloning Cubie constructor
  Cubie(Cubie c)  {
    // These four variables are successfully being stored and copied to the new Cubie objects.
    this.matrix = c.matrix;
    this.x = c.x;
    this.y = c.y;
    this.z = c.z;
    for(int i = 0; i < faces.length; i++) {
      // Debugging print statement
      println("Before: " + colToString(c.colours[i]));
      // Attempt 1 at cloning the Face object by using constructor made for cloning
      this.faces[i] = new Face(c.faces[i]);
      // Attempt 2 at cloning the face object by creating a new Face with the original's values
      // this.faces[i] = new Face(new PVector(x, y, z), c.colours[i]);
      // Another debugging print statement
      if(c.colours[i] != this.colours[i]) println("THEY ACTUALLY DON'T MATCH THO FAM");
    }
    // Another fucking debugging print statement
    // for(Face face : this.faces)  println("\t\t" + colToString(face.c));
  }

这是用于克隆面的构造函数。颜色通常会传递给对象,但正如您从上面的代码片段中看到的,我尝试根据原始faces变量值手动创建一个新的face对象,并使用下面的face克隆构造函数直接复制对象本身(如果这有意义的话)。

// Clone face constructor
  Face(Face f)  {
    this.normal = f.normal;
    this.c = f.c;
  }

如果您需要更多信息,请随时给我留言:zardos෦6558谢谢!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题