Example #1
0
        void createPieces()
        {
            Pieces = new Piece[nbPieceX,nbPieceY];

            int ptr0 = 0;
            int ptr2 = nbPieceX;

            int ptrV0 = (nbPieceY - 1) * nbPieceX * cutter.NbPoints + 2 * nbPieceX;

            //used to build profile texture
            List<uint> indProfile = new List<uint> ();

            for (int y = 0; y < nbPieceY; y++) {
                int ptr1 = ptrV0 + nbPieceY;

                int ptr3 = ptrV0;
                for (int x = 0; x < nbPieceX; x++) {
                    List<uint> ind = new List<uint>();

                    #region Compute border indices
                    //indice du bord sup
                    if (y == 0) {
                        ind.Add ((uint)ptr0);
                        ptr0++;
                    } else {
                        ind.AddRange (Enumerable.Range(ptr0, cutter.NbPoints).Select(i => (uint)i).ToArray());
                        ptr0 += cutter.NbPoints;
                    }
                    //indice du bord droit
                    if (x == nbPieceX - 1) {
                        ind.Add ((uint)(ptr1 + y));
                        ptr1++;
                    } else {
                        ind.AddRange (Enumerable.Range(ptr1 + y * cutter.NbPoints, cutter.NbPoints).Select(i => (uint)i).ToArray());
                        ptr1 += cutter.NbPoints * nbPieceY ;
                    }
                    //
                    //indice du bord inférieur
                    if (y == nbPieceY - 1) {
                        if (x == nbPieceX - 1)
                            ind.Add (BorderOffset - 1);
                        else
                            ind.Add ((uint)(ptr2+1));
                        ind.Add ((uint)ptr2);
                        ptr2++;
                    } else {
                        if (x == nbPieceX - 1)
                            ind.Add ((uint)(ptr1 + y));
                        else
                            ind.Add ((uint)(ptr2 + cutter.NbPoints));

                        ind.AddRange (Enumerable.Range(ptr2+1, cutter.NbPoints - 1).Reverse().Select(i => (uint)i).ToArray());
                        ind.Add ((uint)ptr2);//1st point of left border
                        ptr2 += cutter.NbPoints;
                    }

                    //indice du bord gauche
                    if (x == 0)
                        ptr3 += nbPieceY ;
                    else if (x > 0 ) {
                        //						ind.Add (ptr3 + Cut.NbPoints);
                        ind.AddRange (Enumerable.Range(ptr3+y*cutter.NbPoints+1, cutter.NbPoints-1).Reverse().Select(i => (uint)i).ToArray());
                        ptr3 += cutter.NbPoints * nbPieceY ;
                    }
                    #endregion

                    indProfile.AddRange (ind);
                    indProfile.Add (uint.MaxValue);

                    Pieces [x, y] = new Piece (this, (uint)x, (uint)y, ind);

                }
            }

            createProfileTexture (indProfile.ToArray());

            //init neighbourhoud, borders indices, and zordered list
            ZOrderedPieces = new List<Piece>();
            for (int y = 0; y < nbPieceY; y++) {
                for (int x = 0; x < nbPieceX; x++) {
                    Piece p = Pieces [x, y];
                    lock(Mutex)
                        ZOrderedPieces.Add (p);
                    if (y < nbPieceY - 1)
                        p.Neighbours [2] = Pieces [x, y + 1];
                    if (x < nbPieceX - 1)
                        p.Neighbours [1] = Pieces [x + 1, y];
                    if (y > 0)
                        p.Neighbours [0] = Pieces [x, y - 1];
                    if (x > 0)
                        p.Neighbours [3] = Pieces [x - 1, y];
                }
            }
        }
Example #2
0
        public void Rotate(Piece pcr)
        {
            if (Visited)
                return;
            Visited = true;

            float target = 0f;
            float res = Angle / MathHelper.PiOver2;
            int nbPi = (int)Math.Floor(-res);

            if (res % 1 != 0)
                nbPi++;

            switch (nbPi) {
            case 0:
                target = -MathHelper.PiOver2;
                break;
            case 1:
                target = -MathHelper.Pi;
                break;
            case 2:
                target = -MathHelper.ThreePiOver2;
                break;
            case 3:
                target = -MathHelper.TwoPi;
                break;
            }

            rotationRef = pcr;
            Animation.StartAnimation(new Animation<float> (this, "Angle", target, 0.2f));

            for (int i = 0; i < IsLinked.Length; i++) {
                if (!IsLinked [i])
                    continue;
                Neighbours [i].Rotate(pcr);
            }
        }
Example #3
0
        public void Render(Piece[] pces)
        {
            GL.CullFace (CullFaceMode.Front);

            GL.BindVertexArray(vaoHandle);

            GL.ActiveTexture (TextureUnit.Texture1);
            GL.BindTexture(TextureTarget.Texture2D, profileTexture);
            GL.ActiveTexture (TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, Image);

            foreach (Piece p in pces) {
                MainWin.mainShader.Color = new Vector4 (0.4f, 0.4f, 0.4f, 1);
                MainWin.mainShader.Model = p.Transformations;
                MainWin.mainShader.ColorMultiplier = p.ColorMultiplier;

                //border, only when not linked
                for (int i = 0; i < nbSides; i++) {
                    if (p.IsLinked [i])
                        continue;
                    GL.DrawElements (PrimitiveType.TriangleStrip, p.indBorderLength[i],
                        DrawElementsType.UnsignedInt, p.IndBorderPtr[i]);
                }

                MainWin.mainShader.Color = new Vector4 (1, 1, 1, 1);

                GL.DrawElements (PrimitiveType.Triangles, p.indFillLength,
                    DrawElementsType.UnsignedInt, p.IndFillPtr);
            }

            GL.BindVertexArray (0);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            GL.CullFace (CullFaceMode.Back);
        }