const THREE = require("three");

export class Bulle {

    constructor(id, x, y, z,r = 0,g = 0,b = 255) {
      this._id = id;
      this._x = x;
      this._y = y;
      this._z = z;
      this._r = r;
      this._g = g;
      this._b = b;
    }

    get id() {
      return this._id;
    }

    set id(id) {
      this._id = id;
    }

    get x() {
      return this._x;
    }

    set x(x) {
      this._x = x;
    }

    get y() {
      return this._y;
    }

    set y(y) {
      this._y = y;
    }

    get z() {
      return this._z;
    }

    set z(z) {
      this._z = z;
    }

    setRGB(r, g, b){
      this._r = r;
      this._g = g;
      this._b = b;
    }

    distanceXYZ(bulle) {
      let dx = this._x - bulle.x;
      let dy = this._y - bulle.y;
      let dz = this._z - bulle.z;
      return Math.sqrt(dx*dx + dy*dy + dz*dz);
    }

    toString() {
      return "["+this._id+"] : \n x : " + this._x + "\n y : " + this._y + "\n z : " + this._z;
    }

    affichage(taille){
      let color = rgbToHex(this._r,this._g,this._b);
      let geometry = new THREE.SphereGeometry( taille, 32 ,32 );
      let material = new THREE.MeshBasicMaterial( {color: color} );
      let mesh = new THREE.Mesh( geometry, material );

      mesh.position.set(this._x, this._y, this._z);

      return mesh;
    }

}

function rgbToHex(r, g, b) {
    return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
}
