Beispiel #1
0
        public SlicedSphere(double radius, Vector3d offset, eSubdivisions subdivs, eDir[] sides)
            : base(  )
        {
            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);
            }
        }
Beispiel #2
0
        public Capsule(double radius, double height, eSubdivisions subdivs)
            : base( )
        {
            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);
                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,
            });

            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
            });

            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();
        }
Beispiel #3
0
        public ChamferCube(double Width, double Height, double Length, SubDivs subdivs, double radius)
            : base(  )
        {
            SlicedSphere.eSubdivisions sphereSubDivs = SlicedSphere.eSubdivisions.Zero;
            uint hoseSubDivs = 0;

            switch (subdivs)
            {
            case SubDivs.Zero:
                sphereSubDivs = SlicedSphere.eSubdivisions.Zero;
                hoseSubDivs   = 0;
                break;

            case SubDivs.One:
                sphereSubDivs = SlicedSphere.eSubdivisions.One;
                hoseSubDivs   = 1;
                break;

            case SubDivs.Two:
                sphereSubDivs = SlicedSphere.eSubdivisions.Two;
                hoseSubDivs   = 3;
                break;

            case SubDivs.Three:
                sphereSubDivs = SlicedSphere.eSubdivisions.Three;
                hoseSubDivs   = 7;
                break;

            case SubDivs.Four:
                sphereSubDivs = SlicedSphere.eSubdivisions.Four;
                hoseSubDivs   = 15;
                break;
            }

            #region Temporary Storage

            List <Chunk> AllChunks = new List <Chunk>();
            OpenTK.Graphics.OpenGL.BeginMode TemporaryMode;
            VertexT2dN3dV3d[] TemporaryVBO;
            uint[]            TemporaryIBO;

            #endregion Temporary Storage

            Vector3d FrontTopRightEdge    = new Vector3d(+Width - radius, +Height - radius, +Length - radius);
            Vector3d FrontTopLeftEdge     = new Vector3d(+Width - radius, +Height - radius, -Length + radius);
            Vector3d FrontBottomRightEdge = new Vector3d(+Width - radius, -Height + radius, +Length - radius);
            Vector3d FrontBottomLeftEdge  = new Vector3d(+Width - radius, -Height + radius, -Length + radius);
            Vector3d BackTopRightEdge     = new Vector3d(-Width + radius, +Height - radius, +Length - radius);
            Vector3d BackTopLeftEdge      = new Vector3d(-Width + radius, +Height - radius, -Length + radius);
            Vector3d BackBottomRightEdge  = new Vector3d(-Width + radius, -Height + radius, +Length - radius);
            Vector3d BackBottomLeftEdge   = new Vector3d(-Width + radius, -Height + radius, -Length + radius);

            #region 8 sliced Spheres
            SlicedSphere        tempSphere;
            Vector3d            tempVector = Vector3d.Zero;
            SlicedSphere.eDir[] tempEdge   = new SlicedSphere.eDir[1];

            for (int i = 0; i < 8; i++)
            {
                switch (i)
                {
                case 0:
                    tempVector = FrontTopRightEdge;
                    tempEdge   = new SlicedSphere.eDir[] { SlicedSphere.eDir.FrontTopRight };
                    break;

                case 1:
                    tempVector = FrontTopLeftEdge;
                    tempEdge   = new SlicedSphere.eDir[] { SlicedSphere.eDir.FrontTopLeft };
                    break;

                case 2:
                    tempVector = FrontBottomRightEdge;
                    tempEdge   = new SlicedSphere.eDir[] { SlicedSphere.eDir.FrontBottomRight };
                    break;

                case 3:
                    tempVector = FrontBottomLeftEdge;
                    tempEdge   = new SlicedSphere.eDir[] { SlicedSphere.eDir.FrontBottomLeft };
                    break;

                case 4:
                    tempVector = BackBottomRightEdge;
                    tempEdge   = new SlicedSphere.eDir[] { SlicedSphere.eDir.BackBottomRight };
                    break;

                case 5:
                    tempVector = BackBottomLeftEdge;
                    tempEdge   = new SlicedSphere.eDir[] { SlicedSphere.eDir.BackBottomLeft };
                    break;

                case 6:
                    tempVector = BackTopRightEdge;
                    tempEdge   = new SlicedSphere.eDir[] { SlicedSphere.eDir.BackTopRight };
                    break;

                case 7:
                    tempVector = BackTopLeftEdge;
                    tempEdge   = new SlicedSphere.eDir[] { SlicedSphere.eDir.BackTopLeft };
                    break;
                }
                tempSphere = new SlicedSphere(radius,
                                              tempVector,
                                              sphereSubDivs,
                                              tempEdge);
                tempSphere.GetArraysforVBO(out TemporaryMode, out TemporaryVBO, out TemporaryIBO);
                tempSphere.Dispose();
                AllChunks.Add(new Chunk(ref TemporaryVBO, ref TemporaryIBO));
            }
            #endregion 8 sliced Spheres

            #region 12 sliced Hoses

            SlicedHose       tempHose;
            SlicedHose.eSide tempSide      = SlicedHose.eSide.BackBottom;
            Vector3d         tempHoseStart = Vector3d.Zero;
            Vector3d         tempHoseEnd   = Vector3d.Zero;

            for (int i = 0; i < 12; i++)
            {
                switch (i)
                {
                    #region Around X Axis
                case 0:
                    tempSide      = SlicedHose.eSide.BottomRight;
                    tempHoseStart = BackBottomRightEdge;
                    tempHoseEnd   = FrontBottomRightEdge;
                    break;

                case 1:
                    tempSide      = SlicedHose.eSide.TopRight;
                    tempHoseStart = BackTopRightEdge;
                    tempHoseEnd   = FrontTopRightEdge;
                    break;

                case 2:
                    tempSide      = SlicedHose.eSide.TopLeft;
                    tempHoseStart = BackTopLeftEdge;
                    tempHoseEnd   = FrontTopLeftEdge;
                    break;

                case 3:
                    tempSide      = SlicedHose.eSide.BottomLeft;
                    tempHoseStart = BackBottomLeftEdge;
                    tempHoseEnd   = FrontBottomLeftEdge;
                    break;

                    #endregion Around X Axis
                    #region Around Y Axis
                case 4:
                    tempSide      = SlicedHose.eSide.FrontRight;
                    tempHoseStart = FrontBottomRightEdge;
                    tempHoseEnd   = FrontTopRightEdge;
                    break;

                case 5:
                    tempSide      = SlicedHose.eSide.BackRight;
                    tempHoseStart = BackBottomRightEdge;
                    tempHoseEnd   = BackTopRightEdge;
                    break;

                case 6:
                    tempSide      = SlicedHose.eSide.BackLeft;
                    tempHoseStart = BackBottomLeftEdge;
                    tempHoseEnd   = BackTopLeftEdge;
                    break;

                case 7:
                    tempSide      = SlicedHose.eSide.FrontLeft;
                    tempHoseStart = FrontBottomLeftEdge;
                    tempHoseEnd   = FrontTopLeftEdge;
                    break;

                    #endregion Around Y Axis
                    #region Around Z Axis
                case 8:
                    tempSide      = SlicedHose.eSide.FrontTop;
                    tempHoseStart = FrontTopRightEdge;
                    tempHoseEnd   = FrontTopLeftEdge;
                    break;

                case 9:
                    tempSide      = SlicedHose.eSide.BackTop;
                    tempHoseStart = BackTopRightEdge;
                    tempHoseEnd   = BackTopLeftEdge;
                    break;

                case 10:
                    tempSide      = SlicedHose.eSide.BackBottom;
                    tempHoseStart = BackBottomRightEdge;
                    tempHoseEnd   = BackBottomLeftEdge;
                    break;

                case 11:
                    tempSide      = SlicedHose.eSide.FrontBottom;
                    tempHoseStart = FrontBottomRightEdge;
                    tempHoseEnd   = FrontBottomLeftEdge;
                    break;
                    #endregion Around Z Axis
                }
                tempHose = new SlicedHose(tempSide,
                                          hoseSubDivs,
                                          radius,
                                          tempHoseStart,
                                          tempHoseEnd);
                tempHose.GetArraysforVBO(out TemporaryMode, out TemporaryVBO, out TemporaryIBO);
                tempHose.Dispose();
                AllChunks.Add(new Chunk(ref TemporaryVBO, ref TemporaryIBO));
            }
            #endregion 12 sliced Hoses

            #region 6 quads for the sides

            VertexT2dN3dV3d[] tempVBO = new VertexT2dN3dV3d[4];
            uint[]            tempIBO = new uint[6] {
                0, 1, 2, 0, 2, 3
            };                                                 // all quads share this IBO

            // all quads use the same texcoords
            tempVBO[0].TexCoord = new OpenTK.Vector2d(0.0, 1.0);
            tempVBO[1].TexCoord = new OpenTK.Vector2d(0.0, 0.0);
            tempVBO[2].TexCoord = new OpenTK.Vector2d(1.0, 0.0);
            tempVBO[3].TexCoord = new OpenTK.Vector2d(1.0, 1.0);

            // front face
            tempVBO[0].Normal   = tempVBO[1].Normal = tempVBO[2].Normal = tempVBO[3].Normal = Vector3d.UnitX;
            tempVBO[0].Position = FrontTopRightEdge + new Vector3d(radius, 0.0, 0.0);
            tempVBO[1].Position = FrontBottomRightEdge + new Vector3d(radius, 0.0, 0.0);
            tempVBO[2].Position = FrontBottomLeftEdge + new Vector3d(radius, 0.0, 0.0);
            tempVBO[3].Position = FrontTopLeftEdge + new Vector3d(radius, 0.0, 0.0);
            AllChunks.Add(new Chunk(ref tempVBO, ref tempIBO));

            // back face
            tempVBO[0].Normal   = tempVBO[1].Normal = tempVBO[2].Normal = tempVBO[3].Normal = -Vector3d.UnitX;
            tempVBO[0].Position = BackTopLeftEdge - new Vector3d(radius, 0.0, 0.0);
            tempVBO[1].Position = BackBottomLeftEdge - new Vector3d(radius, 0.0, 0.0);
            tempVBO[2].Position = BackBottomRightEdge - new Vector3d(radius, 0.0, 0.0);
            tempVBO[3].Position = BackTopRightEdge - new Vector3d(radius, 0.0, 0.0);
            AllChunks.Add(new Chunk(ref tempVBO, ref tempIBO));

            // top face
            tempVBO[0].Normal   = tempVBO[1].Normal = tempVBO[2].Normal = tempVBO[3].Normal = Vector3d.UnitY;
            tempVBO[0].Position = BackTopRightEdge + new Vector3d(0.0, radius, 0.0);
            tempVBO[1].Position = FrontTopRightEdge + new Vector3d(0.0, radius, 0.0);
            tempVBO[2].Position = FrontTopLeftEdge + new Vector3d(0.0, radius, 0.0);
            tempVBO[3].Position = BackTopLeftEdge + new Vector3d(0.0, radius, 0.0);
            AllChunks.Add(new Chunk(ref tempVBO, ref tempIBO));

            // bottom face
            tempVBO[0].Normal   = tempVBO[1].Normal = tempVBO[2].Normal = tempVBO[3].Normal = -Vector3d.UnitY;
            tempVBO[0].Position = BackBottomLeftEdge - new Vector3d(0.0, radius, 0.0);
            tempVBO[1].Position = FrontBottomLeftEdge - new Vector3d(0.0, radius, 0.0);
            tempVBO[2].Position = FrontBottomRightEdge - new Vector3d(0.0, radius, 0.0);
            tempVBO[3].Position = BackBottomRightEdge - new Vector3d(0.0, radius, 0.0);
            AllChunks.Add(new Chunk(ref tempVBO, ref tempIBO));

            // right face
            tempVBO[0].Normal   = tempVBO[1].Normal = tempVBO[2].Normal = tempVBO[3].Normal = Vector3d.UnitZ;
            tempVBO[0].Position = BackTopRightEdge + new Vector3d(0.0, 0.0, radius);
            tempVBO[1].Position = BackBottomRightEdge + new Vector3d(0.0, 0.0, radius);
            tempVBO[2].Position = FrontBottomRightEdge + new Vector3d(0.0, 0.0, radius);
            tempVBO[3].Position = FrontTopRightEdge + new Vector3d(0.0, 0.0, radius);
            AllChunks.Add(new Chunk(ref tempVBO, ref tempIBO));

            // left face
            tempVBO[0].Normal   = tempVBO[1].Normal = tempVBO[2].Normal = tempVBO[3].Normal = -Vector3d.UnitZ;
            tempVBO[0].Position = FrontTopLeftEdge - new Vector3d(0.0, 0.0, radius);
            tempVBO[1].Position = FrontBottomLeftEdge - new Vector3d(0.0, 0.0, radius);
            tempVBO[2].Position = BackBottomLeftEdge - new Vector3d(0.0, 0.0, radius);
            tempVBO[3].Position = BackTopLeftEdge - new Vector3d(0.0, 0.0, radius);
            AllChunks.Add(new Chunk(ref tempVBO, ref tempIBO));


            #endregion 6 quads for the sides

            #region Final Assembly of Chunks
            PrimitiveMode = OpenTK.Graphics.OpenGL.BeginMode.Triangles;
            Chunk.GetArray(ref AllChunks, out VertexArray, out IndexArray);
            AllChunks.Clear();
            #endregion Final Assembly of Chunks
        }