Esempio n. 1
0
        public static Cubie CreateCubie(Cubicle cubicle, string name, Vector3D center, double size, IFactory factory)
        {
            Cubie cubie = new Cubie(cubicle, name, center, size);
            //Debug.WriteLine(name);
            Vector3D  c      = center;
            double    offset = size / 2;
            CubieFace face   = null;
            int       i      = 0;

            if (name.IndexOf("U") >= 0)
            {
                c    = center; c.Y += offset;
                face = CubieFace.ConstructCubieFace(cubie, "U", c, size, factory);
                cubie.Faces.Add("U", face);
                cubicle.SetCubieFace("U", face);
            }

            if (name.IndexOf("D") >= 0)
            {
                c    = center; c.Y -= offset;
                face = CubieFace.ConstructCubieFace(cubie, "D", c, size, factory);
                cubie.Faces.Add("D", face);
                cubicle.SetCubieFace("D", face);
            }

            if (name.IndexOf("F") >= 0)
            {
                c    = center; c.Z += offset;
                face = CubieFace.ConstructCubieFace(cubie, "F", c, size, factory);
                cubie.Faces.Add("F", face);
                cubicle.SetCubieFace("F", face);
            }

            if (name.IndexOf("B") >= 0)
            {
                c    = center; c.Z -= offset;
                face = CubieFace.ConstructCubieFace(cubie, "B", c, size, factory);
                cubie.Faces.Add("B", face);
                cubicle.SetCubieFace("B", face);
            }

            if (name.IndexOf("L") >= 0)
            {
                c    = center; c.X -= offset;
                face = CubieFace.ConstructCubieFace(cubie, "L", c, size, factory);
                cubie.Faces.Add("L", face);
                cubicle.SetCubieFace("L", face);
            }

            if (name.IndexOf("R") >= 0)
            {
                c    = center; c.X += offset;
                face = CubieFace.ConstructCubieFace(cubie, "R", c, size, factory);
                cubie.Faces.Add("R", face);
                cubicle.SetCubieFace("R", face);
            }

            return(cubie);
        }
Esempio n. 2
0
        public static CubieFace ConstructCubieFace(Cubie cubie, string name, Vector3D center, double size, IFactory factory)
        {
            CubieFace face      = new CubieFace(cubie, name, center, size);
            double    edgeWidth = size * 0.05;
            Size      faceSize  = new Size(size, size);

            IMesh u = factory.CreateMesh(face.Name, ConstructVertexes(CubeConfiguration.Faces[name].Normal, center, faceSize, edgeWidth), CubeConfiguration.Faces[name].Color);

            face._faceMesh = u; face._meshes.Add(u);

            Vector3D[] decorCenters = new Vector3D[4];
            Size[]     sizes        = new Size[4];
            if (name == "U" || name == "D")
            {
                //decorator:
                Vector3D decorCenter;
                decorCenter = center; decorCenter.Z += size / 2 - edgeWidth / 2; decorCenters[0] = decorCenter; sizes[0] = new Size(edgeWidth, size);
                decorCenter = center; decorCenter.Z -= size / 2 - edgeWidth / 2; decorCenters[1] = decorCenter; sizes[1] = new Size(edgeWidth, size);
                decorCenter = center; decorCenter.X += size / 2 - edgeWidth / 2; decorCenters[2] = decorCenter; sizes[2] = new Size(size, edgeWidth);
                decorCenter = center; decorCenter.X -= size / 2 - edgeWidth / 2; decorCenters[3] = decorCenter; sizes[3] = new Size(size, edgeWidth);
            }
            else if (name == "F" || name == "B")
            {
                //decorator:
                Vector3D decorCenter;
                decorCenter = center; decorCenter.X += size / 2 - edgeWidth / 2; decorCenters[0] = decorCenter; sizes[0] = new Size(edgeWidth, size);
                decorCenter = center; decorCenter.X -= size / 2 - edgeWidth / 2; decorCenters[1] = decorCenter; sizes[1] = new Size(edgeWidth, size);
                decorCenter = center; decorCenter.Y += size / 2 - edgeWidth / 2; decorCenters[2] = decorCenter; sizes[2] = new Size(size, edgeWidth);
                decorCenter = center; decorCenter.Y -= size / 2 - edgeWidth / 2; decorCenters[3] = decorCenter; sizes[3] = new Size(size, edgeWidth);
            }
            else if (name == "L" || name == "R")
            {
                //decorator:
                Vector3D decorCenter;
                decorCenter = center; decorCenter.Y += size / 2 - edgeWidth / 2; decorCenters[0] = decorCenter; sizes[0] = new Size(edgeWidth, size);
                decorCenter = center; decorCenter.Y -= size / 2 - edgeWidth / 2; decorCenters[1] = decorCenter; sizes[1] = new Size(edgeWidth, size);
                decorCenter = center; decorCenter.Z += size / 2 - edgeWidth / 2; decorCenters[2] = decorCenter; sizes[2] = new Size(size, edgeWidth);
                decorCenter = center; decorCenter.Z -= size / 2 - edgeWidth / 2; decorCenters[3] = decorCenter; sizes[3] = new Size(size, edgeWidth);
            }
            else
            {
                System.Diagnostics.Debug.Assert(false);
            }


            for (int i = 0; i < decorCenters.Length; i++)
            {
                face._meshes.Add(factory.CreateMesh(face.Name, ConstructVertexes(CubeConfiguration.Faces[name].Normal, decorCenters[i], sizes[i], 0), Colors.Black));
            }
            return(face);
        }
Esempio n. 3
0
        public override void DoTransform(double deltaAngle)
        {
            //  Debug.WriteLine("start DoTransform");
            foreach (CubicleFace face in AffectedFaces)
            {
                Cubie     cubie     = face.CubieFace.Cubie;
                CubieFace cubieFace = face.CubieFace;
                //cubicle.Cubie.Rotate(BasicOp.Axis, deltaAngle, false);
                Vector3D axis = face.CubieFace.Cubie.UnitX;

                if (Axis == Axis.X)
                {
                    axis = face.CubieFace.Cubie.UnitX;
                }
                else if (Axis == Axis.Y)
                {
                    axis = face.CubieFace.Cubie.UnitY;
                }
                else if (Axis == Axis.Z)
                {
                    axis = face.CubieFace.Cubie.UnitZ;
                }

                Quaternion3D rot       = Quaternion3D.CreateFromAxisAngle(axis, deltaAngle);
                Matrix3D     rotMatrix = Ext3D.CreateFromQuaternion(rot);
                Matrix3D     matrix    = cubie.Transform;// Matrix.Invert(cubie.Transform);
                matrix.Invert();


                Matrix3D rotation = Ext3D.CreateTranslation(Ext3D.Transform(-AxisTranslationFromOrigin, matrix)) * rotMatrix * Ext3D.CreateTranslation(Ext3D.Transform(AxisTranslationFromOrigin, matrix));
                if (IsAxisMoving)
                {
                    Vector3D v1;
                    if (!_axisTranslation.ContainsKey(cubieFace))
                    {
                        Matrix3D m = (cubieFace as ITransform).Transform; m.Invert();
                        v1 = Ext3D.Transform(Axis2TranslationFromOrigin, m);
                        _axisTranslation.Add(cubieFace, v1);
                    }
                    v1 = _axisTranslation[cubieFace];
                    Matrix3D r = rotation; r.Invert();
                    v1 = Ext3D.Transform(v1, r);// Matrix.Invert(rotation));

                    Matrix3D rotationAxis = Ext3D.CreateTranslation(-v1) * rotMatrix * Ext3D.CreateTranslation(v1);
                    rotation = rotationAxis * rotation;

                    _axisTranslation[cubieFace] = v1;
                }
                (cubieFace as ITransform).DoTransform(rotation, false);
            }
        }
Esempio n. 4
0
 public void SetCubieFace(CubieFace face)
 {
     CubieFace        = face;
     face.CubicleFace = this;
 }
Esempio n. 5
0
 public void SetCubieFace(string faceName, CubieFace face)
 {
     _cubicleFaces[faceName].SetCubieFace(face);
 }