Example #1
0
        static public VertexDeclarations.PositionNormalVertex[] BuildSphere(float radius, List <float> setkaXAngle, List <float> setkaYAngle, float offset)
        {
            VertexDeclarations.PositionNormalVertex[] result = new VertexDeclarations.PositionNormalVertex[setkaXAngle.Count * setkaYAngle.Count];

            int countY = 0;

            foreach (float yAngle in setkaYAngle)
            {
                int countX = 0;
                foreach (float xAngle in setkaXAngle)
                {
                    float add_x = offset * (float)Math.Sin(yAngle);
                    float add_z = -offset * (float)Math.Cos(yAngle);

                    Vector3 normal   = new Vector3((float)(radius * Math.Sin(xAngle) * Math.Sin(yAngle)), (float)(radius * Math.Cos(xAngle)), (float)(-radius * Math.Sin(xAngle) * Math.Cos(yAngle)));
                    Vector3 position = normal + new Vector3(add_x, 0, add_z);
                    normal.Normalize();

                    //position -= new Vector3(0, (float)(radius * Math.Cos(setkaXAngle[setkaXAngle.Count / 2])), (float)(-radius * Math.Sin(setkaXAngle[setkaXAngle.Count / 2])));

                    //result[count] = new VertexDeclarations.PositionNormalVertex(position, normal);
                    //count++;

                    result[(setkaYAngle.Count - 1 - countY) * setkaXAngle.Count + countX] = new VertexDeclarations.PositionNormalVertex(position, normal);

                    countX++;
                }
                countY++;
            }

            return(result);
        }
Example #2
0
        static public VertexDeclarations.PositionNormalVertex[] BuildConus(float conusAngle, float sizeX, float startX, List <float> setkaX, List <float> setkaYAngle)
        {
            VertexDeclarations.PositionNormalVertex[] result = new VertexDeclarations.PositionNormalVertex[setkaX.Count * setkaYAngle.Count];

            //float sizeX = setkaX[setkaX.Count - 1] - setkaX[0];
            //float startX = setkaX[0];

            int countY = 0;

            foreach (float yAngle in setkaYAngle)
            {
                int countX = 0;
                foreach (float x in setkaX)
                {
                    float   radiusY  = (float)(x * Math.Sin(conusAngle));
                    Vector3 position = new Vector3((float)(x * Math.Cos(conusAngle)), (float)(radiusY * Math.Cos(yAngle)), (float)(radiusY * Math.Sin(-yAngle)));
                    Vector3 center   = new Vector3((float)(position.X + radiusY * Math.Tan(conusAngle)), 0, 0);
                    Vector3 normal   = position - center;
                    normal.Normalize();
                    position.X -= (startX + sizeX / 2);

                    result[(setkaYAngle.Count - 1 - countY) * setkaX.Count + countX] = new VertexDeclarations.PositionNormalVertex(position, normal);

                    countX++;
                }
                countY++;
            }

            return(result);
        }
Example #3
0
        static public VertexDeclarations.PositionNormalVertex[] BuildCylinder(float sizeX, float radiusY, float sizeYAngle, List <float> setkaX, List <float> setkaYAngle)
        {
            VertexDeclarations.PositionNormalVertex[] result = new VertexDeclarations.PositionNormalVertex[setkaX.Count * setkaYAngle.Count];

            int countY = 0;

            foreach (float yAngle in setkaYAngle)
            {
                int countX = 0;
                foreach (float x in setkaX)
                {
                    Vector3 position = new Vector3(x, (float)(radiusY * Math.Cos(yAngle)), (float)(radiusY * Math.Sin(-yAngle)));
                    Vector3 normal   = position;
                    normal.X = 0;
                    normal.Normalize();
                    position.Y -= radiusY;
                    position.X -= (sizeX / 2);

                    result[(setkaYAngle.Count - 1 - countY) * setkaX.Count + countX] = new VertexDeclarations.PositionNormalVertex(position, normal);

                    countX++;
                }
                countY++;
            }

            return(result);
        }
Example #4
0
        static public VertexDeclarations.PositionNormalVertex[] ApplyProgib(VertexDeclarations.PositionNormalVertex[] surface, float[] progibs, float add)
        {
            VertexDeclarations.PositionNormalVertex[] result = new VertexDeclarations.PositionNormalVertex[surface.Length];

            for (int i = 0; i < result.Length; i++)
            {
                result[i] = new VertexDeclarations.PositionNormalVertex(surface[i].position + surface[i].normal * (progibs[i] + add), surface[i].normal);
            }

            return(result);
        }
Example #5
0
        static public VertexDeclarations.PositionNormalVertex[] MoveAlongNormal(VertexDeclarations.PositionNormalVertex[] surface, float move, bool invert_normal)
        {
            VertexDeclarations.PositionNormalVertex[] result = new VertexDeclarations.PositionNormalVertex[surface.Length];

            for (int i = 0; i < result.Length; i++)
            {
                if (invert_normal)
                {
                    result[i] = new VertexDeclarations.PositionNormalVertex(surface[i].position + surface[i].normal * move, -surface[i].normal);
                }
                else
                {
                    result[i] = new VertexDeclarations.PositionNormalVertex(surface[i].position + surface[i].normal * move, surface[i].normal);
                }
            }

            return(result);
        }
Example #6
0
        static public VertexDeclarations.PositionNormalVertex[] BuildEdgeY(VertexDeclarations.PositionNormalVertex[] surfaceTop, VertexDeclarations.PositionNormalVertex[] surfaceBottom, int stackY, int stacksX, int stacksY, int stacksZ)
        {
            VertexDeclarations.PositionNormalVertex[] result = new VertexDeclarations.PositionNormalVertex[stacksX * stacksZ];

            int index = 0;

            for (int stackX = 0; stackX < stacksX; stackX++)
            {
                Vector3 direction = surfaceTop[stackY * stacksX + stackX].position - surfaceBottom[stackY * stacksX + stackX].position;
                float   H         = direction.Length();
                direction.Normalize();
                for (int stackZ = 0; stackZ < stacksZ; stackZ++)
                {
                    result[index] = new VertexDeclarations.PositionNormalVertex(surfaceBottom[stackY * stacksX + stackX].position + direction * H * stackZ / (stacksZ - 1), Vector3.Zero);
                    index++;
                }
            }

            return(result);
        }
Example #7
0
        static public VertexDeclarations.PositionNormalVertex[] BuildFromTorus(float radiusX, float sizeX, float radiusY, float sizeY, List <float> setkaX, List <float> setkaY)
        {
            VertexDeclarations.PositionNormalVertex[] result = new VertexDeclarations.PositionNormalVertex[setkaX.Count * setkaY.Count];

            List <float> psi_angles = new List <float>();
            List <float> phi_angles = new List <float>();

            float r        = radiusX;
            float r_length = sizeX;
            int   r_stacks = setkaX.Count;
            float R        = radiusY - radiusX;
            float R_length = sizeY;
            int   R_stacks = setkaY.Count;

            float psi_start = (float)(R_length / (2 * (R + r)));

            for (int i = 0; i < setkaY.Count; i++)
            {
                float psi = setkaY[i] / (R + r) - psi_start;
                psi_angles.Add(psi);
            }
            float phi_start = (float)(r_length / (2 * r));

            for (int i = 0; i < setkaX.Count; i++)
            {
                float phi = phi_start - setkaX[i] / r;
                phi_angles.Add(phi);
            }

            if (radiusX >= radiusY)
            {
                r        = radiusY;
                r_length = sizeY;
                r_stacks = setkaY.Count;
                R        = radiusX - radiusY;
                R_length = sizeX;
                R_stacks = setkaX.Count;

                psi_angles.Clear();
                psi_start = (float)(R_length / (2 * (R + r)));
                for (int i = 0; i < setkaX.Count; i++)
                {
                    float psi = psi_start - setkaX[i] / (R + r);
                    psi_angles.Add(psi);
                }
                phi_start = (float)(r_length / (2 * r));
                phi_angles.Clear();
                for (int i = 0; i < setkaY.Count; i++)
                {
                    float phi = phi_start - setkaY[i] / r;
                    phi_angles.Add(phi);
                }
            }

            for (int slice = 0; slice < psi_angles.Count; slice++)
            {
                float psi = psi_angles[slice];

                float   x        = (float)((R + r) * Math.Cos(psi));
                float   y        = 0;
                float   z        = (float)((R + r) * Math.Sin(psi));
                Vector3 r_center = new Vector3(x, y, z);
                r_center.Normalize();
                r_center *= R;

                for (int stack = 0; stack < phi_angles.Count; stack++)
                {
                    float phi = phi_angles[stack];

                    x = (float)((R + r * Math.Cos(phi)) * Math.Cos(psi));
                    y = (float)(r * Math.Sin(phi));
                    z = (float)((R + r * Math.Cos(phi)) * Math.Sin(psi));

                    Vector3 point = new Vector3(x, y, z);

                    Vector3 normal = point - r_center;
                    normal.Normalize();

                    if (radiusX < radiusY)
                    {
                        result[slice * r_stacks + stack] = new VertexDeclarations.PositionNormalVertex(point, normal);
                    }
                    else
                    {
                        result[stack * R_stacks + slice] = new VertexDeclarations.PositionNormalVertex(point, normal);
                    }
                }
            }

            for (int i = 0; i < result.Length; i++)
            {
                result[i].position.X -= (R + r);

                float temp = result[i].position.X;
                result[i].position.X = -result[i].position.Y;
                result[i].position.Y = temp;
                temp = result[i].normal.X;
                result[i].normal.X = -result[i].normal.Y;
                result[i].normal.Y = temp;

                if (radiusX >= radiusY)
                {
                    temp = result[i].position.X;
                    result[i].position.X = -result[i].position.Z;
                    result[i].position.Z = temp;
                    temp = result[i].normal.X;
                    result[i].normal.X = -result[i].normal.Z;
                    result[i].normal.Z = temp;
                }
            }

            return(result);
        }