Example #1
0
        //Metoda vracejici vytvoreny cylinder
        private TVMesh Cylinder(float Radius, float Height, int Sides, float xm, float ym, float zm, int textureVyskaNasobek, int textureSirkaNasobek)
        {
            TVMesh p = new TVMesh();
            p = Scene.CreateMeshBuilder();
            //Scene.SetRenderMode(CONST_TV_RENDERMODE.TV_LINE);

            double Theta;
            float Inc;
            float x, y, z;
            TV_3DVECTOR n;
            float tu, tv;
            float UStep;
            int sign;

            p.SetPrimitiveType(CONST_TV_PRIMITIVETYPE.TV_TRIANGLESTRIP);
            Inc = (float)((2 * Math.PI) / Sides);
            Theta = 0;
            UStep = (float)(1 / (float)Sides);
            tu = 0;
            sign = -1;

            //Making bottom cap
            for (int i = 1; i <= Sides; i++)
            {
                x = Radius * (float)Math.Cos(sign * Theta);
                y = Height;
                z = Radius * (float)Math.Sin(sign * Theta);

                tu = 0.5f * (float)Math.Cos(sign * Theta) + 0.5f;
                tv = 0.5f * (float)Math.Sin(sign * Theta) + 0.5f;

                p.AddVertex(x - xm, 0 - ym, z - zm, 0, -1, 0, tu, tv);

                if (sign == 1)
                    sign = -1;
                else
                {
                    sign = 1;
                    Theta = Theta + Inc;
                }

            }

            // Making cylinder
            for (int i = 0; i <= Sides; i++)
            {
                x = Radius * (float)Math.Cos(Theta);
                y = Height;
                z = Radius * (float)Math.Sin(Theta);

                n = new TV_3DVECTOR(x, 0, y);
                p.AddVertex(x - xm, 0 - ym, z - zm, n.x, n.y, n.z, 0, 0);
                p.AddVertex(x - xm, y - ym, z - zm, n.x, n.y, n.z, 0, 0);
                Theta = Theta + Inc;

                tu = tu + UStep * textureSirkaNasobek;

            }

            Theta = Math.PI;
            sign = 1;
            //Making top cap
            for (int i = 1; i <= Sides; i++)
            {
                x = Radius * (float)Math.Cos(sign * Theta);
                y = Height;
                z = Radius * (float)Math.Sin(sign * Theta);

                tu = 0.5f * (float)Math.Cos(sign * Theta) + 0.5f;
                tv = 0.5f * (float)Math.Sin(sign * Theta) + 0.5f;

                p.AddVertex(x - xm, y - ym, z - zm, 0, 1, 0, tu, tv);

                if (sign == 1)
                {
                    sign = -1;
                    Theta = Theta + Inc;
                }
                else
                    sign = 1;

            }

            return p;
        }