コード例 #1
0
        public KochTetrahedron( double scale, double extrusionHeight, double extrusionMultiplier, eSubdivisions subdivs, bool useDL )
            : base( useDL )
        {
            TetrahedronFace[] Triangles;

            switch ( subdivs )
            {
            case eSubdivisions.Zero:
                SierpinskiTetrahedron.CreateDefaultTetrahedron( scale, out Triangles );
                break;
            case eSubdivisions.One:
            case eSubdivisions.Two:
            case eSubdivisions.Three:
            case eSubdivisions.Four:
            case eSubdivisions.Five:
            case eSubdivisions.Six:
            case eSubdivisions.Seven:
            case eSubdivisions.Eight:
                SierpinskiTetrahedron.CreateDefaultTetrahedron( scale, out Triangles );
                for ( int i = 0; i < (int)subdivs; i++ )
                {
                    TetrahedronFace[] temp;
                    this.SubdivideKoch( extrusionHeight, ref Triangles, out temp );
                    Triangles = temp;
                    extrusionHeight *= extrusionMultiplier;
                }
                break;
            default: throw new ArgumentOutOfRangeException( "Subdivisions other than contained in the enum cause overflows and are not allowed." );

            }

            PrimitiveMode = OpenTK.Graphics.OpenGL.BeginMode.Triangles;
            SierpinskiTetrahedron.GetVertexArray( ref Triangles, out VertexArray );
            IndexArray = null;
        }
コード例 #2
0
        /// <summary>Creates a Sierpinski Tetrahedron which is centered at (0,0,0) and fits into a sphere of radius 1f, or a diameter of 2f</summary>
        /// <param name="scale">Default: 1f.</param>
        /// <param name="subdivs">The number of subdivisions of the Tetrahedron.</param>
        /// <param name="useDL"></param>
        public SierpinskiTetrahedron(double scale, eSubdivisions subdivs, bool useDL)
            : base(useDL)
        {
            TetrahedronFace[] Triangles;
            switch (subdivs)
            {
            case eSubdivisions.Zero:
                CreateDefaultTetrahedron(scale, out Triangles);
                break;

            case eSubdivisions.One:
            case eSubdivisions.Two:
            case eSubdivisions.Three:
            case eSubdivisions.Four:
            case eSubdivisions.Five:
            case eSubdivisions.Six:
            case eSubdivisions.Seven:
            case eSubdivisions.Eight:
            case eSubdivisions.Nine:
                CreateDefaultTetrahedron(scale, out Triangles);
                for (int i = 0; i < (int)subdivs; i++)
                {
                    TetrahedronFace[] temp;
                    SubdivideTetrahedron(ref Triangles, out temp);
                    Triangles = temp;
                }
                break;

            default: throw new ArgumentOutOfRangeException("Subdivisions other than contained in the enum cause overflows and are not allowed.");
            }

            PrimitiveMode = OpenTK.Graphics.OpenGL.BeginMode.Triangles;
            SierpinskiTetrahedron.GetVertexArray(ref Triangles, out VertexArray);
            IndexArray = null;
        }
コード例 #3
0
        public SlicedSphere(double radius, Vector3d offset, eSubdivisions subdivs, eDir[] sides, bool useDL)
            : base(useDL)
        {
            double Diameter = radius;

            PrimitiveMode = OpenTK.Graphics.OpenGL.BeginMode.Triangles;
            if (sides[0] == eDir.All)
            {
                sides = new eDir[] { eDir.FrontTopRight,
                                     eDir.FrontBottomRight,
                                     eDir.FrontBottomLeft,
                                     eDir.FrontTopLeft,
                                     eDir.BackTopRight,
                                     eDir.BackBottomRight,
                                     eDir.BackBottomLeft,
                                     eDir.BackTopLeft, };
            }

            VertexArray = new VertexT2dN3dV3d[sides.Length * 3];
            IndexArray  = new uint[sides.Length * 3];
            uint counter = 0;

            foreach (eDir s in sides)
            {
                GetDefaultVertices(s, Diameter, out VertexArray[counter + 0], out VertexArray[counter + 1], out VertexArray[counter + 2]);
                IndexArray[counter + 0] = counter + 0;
                IndexArray[counter + 1] = counter + 1;
                IndexArray[counter + 2] = counter + 2;
                counter += 3;
            }

            if (subdivs != eSubdivisions.Zero)
            {
                for (int s = 0; s < (int)subdivs; s++)
                {
                    #region Assemble Chunks and convert to Arrays
                    List <Chunk> AllChunks = new List <Chunk>();
                    for (uint i = 0; i < IndexArray.Length; i += 3)
                    {
                        Chunk chu;
                        Subdivide(Diameter,
                                  ref VertexArray[IndexArray[i + 0]],
                                  ref VertexArray[IndexArray[i + 1]],
                                  ref VertexArray[IndexArray[i + 2]],
                                  out chu);
                        AllChunks.Add(chu);
                    }

                    Chunk.GetArray(ref AllChunks, out VertexArray, out IndexArray);
                    AllChunks.Clear();
                    #endregion Assemble Chunks and convert to Arrays
                }
            }

            for (int i = 0; i < VertexArray.Length; i++)
            {
                Vector3d.Add(ref VertexArray[i].Position, ref offset, out VertexArray[i].Position);
            }
        }
コード例 #4
0
ファイル: Capsule.cs プロジェクト: zphilip/PerceptualImaging
        public Capsule( double radius, double height, eSubdivisions subdivs, bool useDL )
            : base(useDL)
        {
            uint HoseSubDivs = 0;
            SlicedSphere.eSubdivisions spheresubdivs = SlicedSphere.eSubdivisions.Zero;

            switch ( subdivs )
            {
            case eSubdivisions.None:
                spheresubdivs = SlicedSphere.eSubdivisions.Zero;
                HoseSubDivs = 0;
                break;
            case eSubdivisions.One:
                spheresubdivs = SlicedSphere.eSubdivisions.One;
                HoseSubDivs = 1;
                break;
            case eSubdivisions.Two:
                spheresubdivs = SlicedSphere.eSubdivisions.Two;
                HoseSubDivs = 3;
                break;
            case eSubdivisions.Three:
                spheresubdivs = SlicedSphere.eSubdivisions.Three;
                HoseSubDivs = 7;
                break;
            case eSubdivisions.Four:
                spheresubdivs = SlicedSphere.eSubdivisions.Four;
                HoseSubDivs = 15;
                break;
            }
            PrimitiveMode = OpenTK.Graphics.OpenGL.BeginMode.Triangles;

            OpenTK.Graphics.OpenGL.BeginMode TemporaryMode;
            VertexT2dN3dV3d[] TemporaryVBO;
            uint[] TemporaryIBO;

            List<Chunk> AllChunks = new List<Chunk>();
            Vector3d offset1 = new Vector3d( 0.0, 0.0, height ),
                     offset2 = new Vector3d( 0.0, 0.0, -height );
            for ( int i = 0; i < 4; i++ )
            {
                SlicedHose.eSide tempSide = SlicedHose.eSide.FrontTop;
                switch ( i )
                {
                case 0:
                    tempSide = SlicedHose.eSide.FrontBottom;
                    break;
                case 1:
                    tempSide = SlicedHose.eSide.BackBottom;
                    break;
                case 2:
                    tempSide = SlicedHose.eSide.BackTop;
                    break;
                case 3:
                    tempSide = SlicedHose.eSide.FrontTop;
                    break;
                }
                SlicedHose tempHose = new SlicedHose( tempSide, HoseSubDivs, radius, offset1, offset2, false );
                tempHose.GetArraysforVBO( out TemporaryMode, out TemporaryVBO, out TemporaryIBO );
                tempHose.Dispose();
                AllChunks.Add( new Chunk( ref TemporaryVBO, ref TemporaryIBO ) );
            }

            SlicedSphere front = new SlicedSphere( radius, offset1, spheresubdivs,
                                                       new SlicedSphere.eDir[] {
                                                           SlicedSphere.eDir.BackBottomRight,
                                                           SlicedSphere.eDir.FrontTopRight,
                                                           SlicedSphere.eDir.BackTopRight,
                                                           SlicedSphere.eDir.FrontBottomRight,
                                                          },
                                                       false );

            front.GetArraysforVBO( out TemporaryMode, out TemporaryVBO, out TemporaryIBO );
            AllChunks.Add( new Chunk( ref TemporaryVBO, ref TemporaryIBO ) );
            front.Dispose();

            SlicedSphere back = new SlicedSphere( radius, offset2, spheresubdivs,
                                                      new SlicedSphere.eDir[] {
                                                          SlicedSphere.eDir.FrontBottomLeft,
                                                          SlicedSphere.eDir.FrontTopLeft,
                                                          SlicedSphere.eDir.BackTopLeft,
                                                          SlicedSphere.eDir.BackBottomLeft },
                                                      false );
            back.GetArraysforVBO( out TemporaryMode, out TemporaryVBO, out TemporaryIBO );
            AllChunks.Add( new Chunk( ref TemporaryVBO, ref TemporaryIBO ) );
            back.Dispose();

            Chunk.GetArray( ref AllChunks, out VertexArray, out IndexArray );
            AllChunks.Clear();
        }
コード例 #5
0
ファイル: SlicedSphere.cs プロジェクト: challal/scallion
        public SlicedSphere( double radius, Vector3d offset, eSubdivisions subdivs, eDir[] sides, bool useDL )
            : base( useDL )
        {
            double Diameter = radius;

            PrimitiveMode = OpenTK.Graphics.OpenGL.BeginMode.Triangles;

            if ( sides[0] == eDir.All )
            {
                sides = new eDir[] {  eDir.FrontTopRight,
            eDir.FrontBottomRight,
            eDir.FrontBottomLeft,
            eDir.FrontTopLeft,
            eDir.BackTopRight,
            eDir.BackBottomRight,
            eDir.BackBottomLeft,
            eDir.BackTopLeft,};
            }

            VertexArray = new VertexT2dN3dV3d[sides.Length * 3];
            IndexArray = new uint[sides.Length * 3];

            uint counter = 0;
            foreach ( eDir s in sides )
            {
                GetDefaultVertices( s, Diameter, out VertexArray[counter + 0], out VertexArray[counter + 1], out VertexArray[counter + 2] );
                IndexArray[counter + 0] = counter + 0;
                IndexArray[counter + 1] = counter + 1;
                IndexArray[counter + 2] = counter + 2;
                counter += 3;
            }

            if ( subdivs != eSubdivisions.Zero )
            {

                for ( int s = 0; s < (int)subdivs; s++ )
                {
                    #region Assemble Chunks and convert to Arrays
                    List<Chunk> AllChunks = new List<Chunk>();
                    for ( uint i = 0; i < IndexArray.Length; i += 3 )
                    {
                        Chunk chu;
                        Subdivide( Diameter,
                                   ref VertexArray[IndexArray[i + 0]],
                                   ref VertexArray[IndexArray[i + 1]],
                                   ref VertexArray[IndexArray[i + 2]],
                                   out chu );
                        AllChunks.Add( chu );
                    }

                    Chunk.GetArray( ref AllChunks, out VertexArray, out IndexArray );
                    AllChunks.Clear();
                    #endregion Assemble Chunks and convert to Arrays
                }
            }

            for (int i=0; i<VertexArray.Length;i++)
            {
                Vector3d.Add(ref VertexArray[i].Position, ref offset, out VertexArray[i].Position);
            }
        }
コード例 #6
0
ファイル: MengerSponge.cs プロジェクト: brezza92/PixelFarm
        public MengerSponge(double scale, eSubdivisions subdivs, bool useDL)
            : base(useDL)
        {
            List <MengerCube> Cubes;

            switch (subdivs)
            {
            case eSubdivisions.None:
                CreateDefaultMengerSponge(scale, out Cubes);
                break;

            case eSubdivisions.One:
            case eSubdivisions.Two:
            case eSubdivisions.Three:
                CreateDefaultMengerSponge(scale, out Cubes);
                for (int i = 0; i < (int)subdivs; i++)
                {
                    List <MengerCube> temp;
                    SubdivideMengerSponge(ref Cubes, out temp);
                    Cubes = temp;
                }
                break;

            default: throw new ArgumentOutOfRangeException("Subdivisions other than contained in the enum cause overflows and are not allowed.");
            }

            PrimitiveMode = OpenTK.Graphics.OpenGL.BeginMode.Triangles;
            uint
                VertexCount = 0,
                IndexCount  = 0;

            foreach (MengerCube c in Cubes)
            {
                uint t1, t2;
                c.GetArraySizes(out t1, out t2);
                VertexCount += t1;
                IndexCount  += t2;
            }

            VertexArray = new VertexT2dN3dV3d[VertexCount];
            IndexArray  = new uint[IndexCount];

            List <Chunk> AllChunks = new List <Chunk>();

            foreach (MengerCube c in Cubes)
            {
                c.GetVboAndIbo(ref AllChunks);
            }

            VertexCount = 0;
            IndexCount  = 0;
            foreach (Chunk ch in AllChunks)
            {
                for (int i = 0; i < ch.Vertices.Length; i++)
                {
                    VertexArray[VertexCount + i] = ch.Vertices[i];
                }

                for (int i = 0; i < ch.Indices.Length; i++)
                {
                    IndexArray[IndexCount + i] = ch.Indices[i] + VertexCount;
                }

                VertexCount += (uint)ch.Vertices.Length;
                IndexCount  += (uint)ch.Indices.Length;
            }


            AllChunks.Clear();
        }
コード例 #7
0
ファイル: MengerSponge.cs プロジェクト: challal/scallion
        public MengerSponge( double scale, eSubdivisions subdivs, bool useDL )
            : base( useDL )
        {
            List<MengerCube> Cubes;
            switch ( subdivs )
            {
            case eSubdivisions.None:
                CreateDefaultMengerSponge( scale, out Cubes );
                break;
            case eSubdivisions.One:
            case eSubdivisions.Two:
            case eSubdivisions.Three:
                CreateDefaultMengerSponge( scale, out Cubes );
                for ( int i = 0; i < (int)subdivs; i++ )
                {
                    List<MengerCube> temp;
                    SubdivideMengerSponge( ref Cubes, out temp );
                    Cubes = temp;
                }
                break;
            default: throw new ArgumentOutOfRangeException( "Subdivisions other than contained in the enum cause overflows and are not allowed." );
            }

            PrimitiveMode = OpenTK.Graphics.OpenGL.BeginMode.Triangles;

            #region Get Array Dimensions
            uint
                VertexCount = 0,
                IndexCount = 0;

            foreach ( MengerCube c in Cubes )
            {
                uint t1, t2;
                c.GetArraySizes( out t1, out t2 );
                VertexCount += t1;
                IndexCount += t2;
            }

            VertexArray = new VertexT2dN3dV3d[VertexCount];
            IndexArray = new uint[IndexCount];
            #endregion Get Array Dimensions

            List<Chunk> AllChunks = new List<Chunk>();

            #region Build a temporary List of all loose pieces
            foreach ( MengerCube c in Cubes )
            {
                c.GetVboAndIbo( ref AllChunks );
            }
            #endregion Build a temporary List of all loose pieces

            #region Assemble pieces into a single VBO and IBO
            VertexCount = 0;
            IndexCount = 0;

            foreach ( Chunk ch in AllChunks )
            {
                for ( int i = 0; i < ch.Vertices.Length; i++ )
                {
                    VertexArray[VertexCount + i] = ch.Vertices[i];
                }

                for ( int i = 0; i < ch.Indices.Length; i++ )
                {
                    IndexArray[IndexCount + i] = ch.Indices[i] + VertexCount;
                }

                VertexCount += (uint)ch.Vertices.Length;
                IndexCount += (uint)ch.Indices.Length;
            }

            #endregion Assemble pieces into a single VBO and IBO

            AllChunks.Clear();
        }
コード例 #8
0
ファイル: Capsule.cs プロジェクト: luislasonbra/PixelFarm
        public Capsule(double radius, double height, eSubdivisions subdivs, bool useDL)
            : base(useDL)
        {
            uint HoseSubDivs = 0;

            SlicedSphere.eSubdivisions spheresubdivs = SlicedSphere.eSubdivisions.Zero;
            switch (subdivs)
            {
            case eSubdivisions.None:
                spheresubdivs = SlicedSphere.eSubdivisions.Zero;
                HoseSubDivs   = 0;
                break;

            case eSubdivisions.One:
                spheresubdivs = SlicedSphere.eSubdivisions.One;
                HoseSubDivs   = 1;
                break;

            case eSubdivisions.Two:
                spheresubdivs = SlicedSphere.eSubdivisions.Two;
                HoseSubDivs   = 3;
                break;

            case eSubdivisions.Three:
                spheresubdivs = SlicedSphere.eSubdivisions.Three;
                HoseSubDivs   = 7;
                break;

            case eSubdivisions.Four:
                spheresubdivs = SlicedSphere.eSubdivisions.Four;
                HoseSubDivs   = 15;
                break;
            }
            PrimitiveMode = OpenTK.Graphics.OpenGL.BeginMode.Triangles;
            OpenTK.Graphics.OpenGL.BeginMode TemporaryMode;
            VertexT2dN3dV3d[] TemporaryVBO;
            uint[]            TemporaryIBO;
            List <Chunk>      AllChunks = new List <Chunk>();
            Vector3d          offset1   = new Vector3d(0.0, 0.0, height),
                              offset2   = new Vector3d(0.0, 0.0, -height);

            for (int i = 0; i < 4; i++)
            {
                SlicedHose.eSide tempSide = SlicedHose.eSide.FrontTop;
                switch (i)
                {
                case 0:
                    tempSide = SlicedHose.eSide.FrontBottom;
                    break;

                case 1:
                    tempSide = SlicedHose.eSide.BackBottom;
                    break;

                case 2:
                    tempSide = SlicedHose.eSide.BackTop;
                    break;

                case 3:
                    tempSide = SlicedHose.eSide.FrontTop;
                    break;
                }
                SlicedHose tempHose = new SlicedHose(tempSide, HoseSubDivs, radius, offset1, offset2, false);
                tempHose.GetArraysforVBO(out TemporaryMode, out TemporaryVBO, out TemporaryIBO);
                tempHose.Dispose();
                AllChunks.Add(new Chunk(ref TemporaryVBO, ref TemporaryIBO));
            }

            SlicedSphere front = new SlicedSphere(radius, offset1, spheresubdivs,
                                                  new SlicedSphere.eDir[] {
                SlicedSphere.eDir.BackBottomRight,
                SlicedSphere.eDir.FrontTopRight,
                SlicedSphere.eDir.BackTopRight,
                SlicedSphere.eDir.FrontBottomRight,
            },
                                                  false);

            front.GetArraysforVBO(out TemporaryMode, out TemporaryVBO, out TemporaryIBO);
            AllChunks.Add(new Chunk(ref TemporaryVBO, ref TemporaryIBO));
            front.Dispose();
            SlicedSphere back = new SlicedSphere(radius, offset2, spheresubdivs,
                                                 new SlicedSphere.eDir[] {
                SlicedSphere.eDir.FrontBottomLeft,
                SlicedSphere.eDir.FrontTopLeft,
                SlicedSphere.eDir.BackTopLeft,
                SlicedSphere.eDir.BackBottomLeft
            },
                                                 false);

            back.GetArraysforVBO(out TemporaryMode, out TemporaryVBO, out TemporaryIBO);
            AllChunks.Add(new Chunk(ref TemporaryVBO, ref TemporaryIBO));
            back.Dispose();
            Chunk.GetArray(ref AllChunks, out VertexArray, out IndexArray);
            AllChunks.Clear();
        }
コード例 #9
0
        public KochTetrahedron(double scale, double extrusionHeight, double extrusionMultiplier, eSubdivisions subdivs, bool useDL)
            : base(useDL)
        {
            TetrahedronFace[] Triangles;

            switch (subdivs)
            {
            case eSubdivisions.Zero:
                SierpinskiTetrahedron.CreateDefaultTetrahedron(scale, out Triangles);
                break;

            case eSubdivisions.One:
            case eSubdivisions.Two:
            case eSubdivisions.Three:
            case eSubdivisions.Four:
            case eSubdivisions.Five:
            case eSubdivisions.Six:
            case eSubdivisions.Seven:
            case eSubdivisions.Eight:
                SierpinskiTetrahedron.CreateDefaultTetrahedron(scale, out Triangles);
                for (int i = 0; i < (int)subdivs; i++)
                {
                    TetrahedronFace[] temp;
                    this.SubdivideKoch(extrusionHeight, ref Triangles, out temp);
                    Triangles        = temp;
                    extrusionHeight *= extrusionMultiplier;
                }
                break;

            default: throw new ArgumentOutOfRangeException("Subdivisions other than contained in the enum cause overflows and are not allowed.");
            }

            PrimitiveMode = PrimitiveType.Triangles;
            SierpinskiTetrahedron.GetVertexArray(ref Triangles, out VertexArray);
            IndexArray = null;
        }
コード例 #10
0
ファイル: Sphere.cs プロジェクト: Sidd710/tempRepo
        public Sphere(float radius, Vector3 offset, eSubdivisions subdivs, eDir[] sides, Vector3Class position, Byte4Class color)
        {
            float Diameter = radius;

            PrimitiveMode = OpenTK.Graphics.OpenGL.PrimitiveType.Triangles;

            if (sides[0] == eDir.All)
            {
                sides = new eDir[] { eDir.FrontTopRight,
                                     eDir.FrontBottomRight,
                                     eDir.FrontBottomLeft,
                                     eDir.FrontTopLeft,
                                     eDir.BackTopRight,
                                     eDir.BackBottomRight,
                                     eDir.BackBottomLeft,
                                     eDir.BackTopLeft, };
            }

            VertexArray = new Vertex[sides.Length * 3];
            IndexArray  = new uint[sides.Length * 3];

            uint counter = 0;

            foreach (eDir s in sides)
            {
                GetDefaultVertices(s, Diameter, out VertexArray[counter + 0], out VertexArray[counter + 1], out VertexArray[counter + 2]);
                IndexArray[counter + 0] = counter + 0;
                IndexArray[counter + 1] = counter + 1;
                IndexArray[counter + 2] = counter + 2;
                counter += 3;
            }

            if (subdivs != eSubdivisions.Zero)
            {
                for (int s = 0; s < (int)subdivs; s++)
                {
                    #region Assemble Chunks and convert to Arrays
                    List <Chunk> AllChunks = new List <Chunk>();
                    for (uint i = 0; i < IndexArray.Length; i += 3)
                    {
                        Chunk chu;
                        Subdivide(Diameter,
                                  ref VertexArray[IndexArray[i + 0]],
                                  ref VertexArray[IndexArray[i + 1]],
                                  ref VertexArray[IndexArray[i + 2]],
                                  out chu);
                        AllChunks.Add(chu);
                    }

                    Chunk.GetArray(ref AllChunks, out VertexArray, out IndexArray);
                    AllChunks.Clear();
                    #endregion Assemble Chunks and convert to Arrays
                }
            }

            this.Triangles = new TriangleInfoList();
            for (int i = 0; i < IndexArray.Length; i += 3)
            {
                //   Vector3.Add(ref VertexArray[i].Position, ref offset, out VertexArray[i].Position);
                // }
                var vertex   = VertexArray[IndexArray[i]];
                var triangle = new Triangle();
                triangle.Vectors[0].Position = new Vector3Class(VertexArray[IndexArray[i]].Position);
                triangle.Vectors[1].Position = new Vector3Class(VertexArray[IndexArray[i + 1]].Position);
                triangle.Vectors[2].Position = new Vector3Class(VertexArray[IndexArray[i + 2]].Position);
                triangle.CalcNormal();
                triangle.Vectors[0].Position += position;
                triangle.Vectors[1].Position += position;
                triangle.Vectors[2].Position += position;
                triangle.Vectors[2].Color     = triangle.Vectors[1].Color = triangle.Vectors[0].Color = color;
                this.Triangles[0].Add(triangle);
            }
        }