using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;

namespace CSGBuilder {
    [Serializable()]
    class Translation : Transformation, ISerializable {
        // Az eltolási mértékek
        private double dx, dy, dz;

        #region Public properties
        public double Dx {
            get { return dx; }
            set { dx = value; }
        }

        public double Dy {
            get { return dy; }
            set { dy = value; }
        }

        public double Dz {
            get { return dz; }
            set { dz = value; }
        }
        #endregion

        public Translation(double dx, double dy, double dz) {
            this.dx = dx;
            this.dy = dy;
            this.dz = dz;
            SetMatrix();
        }

        public override void GetObjectData(SerializationInfo info, StreamingContext context) {
            base.GetObjectData(info, context);
            info.AddValue("Dx", dx);
            info.AddValue("Dy", dy);
            info.AddValue("Dz", dz);
        }

        public Translation(SerializationInfo info, StreamingContext context) : base(info, context) {
            dx = info.GetDouble("Dx");
            dy = info.GetDouble("Dy");
            dz = info.GetDouble("Dz");
        }

        // Elkészíti a transzformáció mátrixát 
        public override void SetMatrix() {
            TrMatrix = new Matrix(4, 4);
            TrMatrix.LoadIdentity();
            TrMatrix[0, 3] = dx;
            TrMatrix[1, 3] = dy;
            TrMatrix[2, 3] = dz;
        }

        public override string ToString() {
            return "Translation(" + dx.ToString("F2") + ", " + dy.ToString("F2") + ", " + dz.ToString("F2") + ")";
        }

        public override string Type() {
            return "Translation";
        }
    }
}
