Esempio n. 1
0
        public static void Init()
        {
            if (s_inited)
            {
                return;
            }


            List <VertexPN> vertList = new List <VertexPN>();


            List <Vector3> spherePositions = new List <Vec3F>();
            List <Vector3> sphereNormals   = new List <Vec3F>();
            List <uint>    sphereIndices   = new List <uint>();

            GeometryHelper.CreateSphere(0.5f, FastSphereSlices, FastSphereStacks, spherePositions
                                        , sphereNormals, null, sphereIndices);


            GeometryHelper.AssembleVertexPN(spherePositions, sphereNormals, vertList);

            s_sphereVertId     = GameEngine.CreateVertexBuffer(vertList.ToArray());
            s_sphereIndexId    = GameEngine.CreateIndexBuffer(sphereIndices.ToArray());
            s_sphereIndexCount = (uint)sphereIndices.Count;

            List <Vec3F> conePos     = new List <Vec3F>();
            List <uint>  coneIndices = new List <uint>();
            List <Vec3F> coneNorms   = new List <Vec3F>();

            GeometryHelper.CreateCylinder(1.0f, 0.0f, 1.0f, 16, 1, conePos, coneNorms, coneIndices);
            s_coneIndexCount = (uint)coneIndices.Count;

            GeometryHelper.AssembleVertexPN(conePos, coneNorms, vertList);
            s_coneVertId  = GameEngine.CreateVertexBuffer(vertList.ToArray());
            s_coneIndexId = GameEngine.CreateIndexBuffer(coneIndices.ToArray());


            // create unit cylinder
            List <Vec3F> cyPos     = new List <Vec3F>();
            List <uint>  cyIndices = new List <uint>();
            List <Vec3F> cyNorms   = new List <Vec3F>();

            GeometryHelper.CreateCylinder(0.5f, 0.5f, 1.0f, 16, 2, cyPos, cyNorms, cyIndices);
            GeometryHelper.AssembleVertexPN(cyPos, cyNorms, vertList);
            s_cylinderVertId     = GameEngine.CreateVertexBuffer(vertList.ToArray());
            s_cylinderIndexId    = GameEngine.CreateIndexBuffer(cyIndices.ToArray());
            s_cylinderIndexCount = (uint)cyIndices.Count;

            // create slim unit torus.
            List <Vec3F> torPos     = new List <Vec3F>();
            List <Vec3F> torNorms   = new List <Vec3F>();
            List <uint>  torIndices = new List <uint>();

            GeometryHelper.CreateTorus(RingInnerRadias, RingOuterRadias, 40, 6, torPos, torNorms, null, torIndices);
            GeometryHelper.AssembleVertexPN(torPos, torNorms, vertList);
            s_torusVertId     = GameEngine.CreateVertexBuffer(vertList.ToArray());
            s_torusIndexId    = GameEngine.CreateIndexBuffer(torIndices.ToArray());
            s_torusIndexCount = (uint)torIndices.Count;



            List <Vector3> cubePos     = new List <Vector3>();
            List <Vector3> cubeNormals = new List <Vector3>();

            List <uint> cubeIndices = new List <uint>();

            GeometryHelper.CreateUnitCube(cubePos, cubeNormals, null, cubeIndices);
            GeometryHelper.AssembleVertexPN(cubePos, cubeNormals, vertList);

            s_cubeVertId     = GameEngine.CreateVertexBuffer(vertList.ToArray());
            s_cubeIndexId    = GameEngine.CreateIndexBuffer(cubeIndices.ToArray());
            s_cubeIndexCount = (uint)cubeIndices.Count;


            var linePos = new List <Vec3F>();

            linePos.Add(new Vector3(0, 0, 0));
            linePos.Add(new Vector3(1, 0, 0));

            linePos.Add(new Vector3(0, 0, 0));
            linePos.Add(new Vector3(0, 1, 0));

            linePos.Add(new Vector3(0, 0, 0));
            linePos.Add(new Vector3(0, 0, 1));

            linePos.Add(new Vector3(0, 0, 0));
            linePos.Add(new Vector3(-1, 0, 0));

            linePos.Add(new Vector3(0, 0, 0));
            linePos.Add(new Vector3(0, -1, 0));

            linePos.Add(new Vector3(0, 0, 0));
            linePos.Add(new Vector3(0, 0, -1));

            s_axisStartVertex = 0;
            s_axisVertexCount = (uint)linePos.Count;

            // rect pos;
            linePos.Add(new Vector3(1, 1, 0));
            linePos.Add(new Vector3(-1, 1, 0));

            linePos.Add(new Vector3(-1, 1, 0));
            linePos.Add(new Vector3(-1, -1, 0));

            linePos.Add(new Vector3(-1, -1, 0));
            linePos.Add(new Vector3(1, -1, 0));

            linePos.Add(new Vector3(1, -1, 0));
            linePos.Add(new Vector3(1, 1, 0));

            s_rectVertexCount = 8;
            s_rectStartVertex = (uint)linePos.Count - s_rectVertexCount;

            // unit square
            linePos.Add(new Vector3(0.5f, 0.5f, 0));
            linePos.Add(new Vector3(-0.5f, 0.5f, 0));

            linePos.Add(new Vector3(-0.5f, 0.5f, 0));
            linePos.Add(new Vector3(-0.5f, -0.5f, 0));

            linePos.Add(new Vector3(-0.5f, -0.5f, 0));
            linePos.Add(new Vector3(0.5f, -0.5f, 0));

            linePos.Add(new Vector3(0.5f, -0.5f, 0));
            linePos.Add(new Vector3(0.5f, 0.5f, 0));

            s_unitSquareVertexCount = 8;
            s_unitSquareStartVertex = (uint)linePos.Count - s_unitSquareVertexCount;

            s_linesVertId = GameEngine.CreateVertexBuffer(linePos.ToArray());

            List <Vec3F> circlePos = new List <Vec3F>();

            GeometryHelper.CreateCircle(1.0f, 32, circlePos);
            s_circleVertexCount = (uint)circlePos.Count;
            s_circleVerts       = GameEngine.CreateVertexBuffer(circlePos.ToArray());

            List <Vec3F> boxVerts   = new List <Vec3F>();
            List <uint>  boxIndices = new List <uint>();

            GeometryHelper.CreateUnitBox(boxVerts, boxIndices);
            s_boxVertsId      = GameEngine.CreateVertexBuffer(boxVerts.ToArray());
            s_boxIndicesId    = GameEngine.CreateIndexBuffer(boxIndices.ToArray());
            s_boxIndicesCount = (uint)boxIndices.Count;

            List <Vec3F> arrowCapVerts   = new List <Vec3F>();
            List <Vec3F> arrowCapNormals = new List <Vec3F>();
            List <uint>  arrowCapIndices = new List <uint>();

            GeometryHelper.CreateArrowCap(arrowCapVerts, arrowCapNormals, arrowCapIndices);
            GeometryHelper.AssembleVertexPN(arrowCapVerts, arrowCapNormals, vertList);
            s_arrowCapVertId     = GameEngine.CreateVertexBuffer(vertList.ToArray());
            s_arrowCapIndexId    = GameEngine.CreateIndexBuffer(arrowCapIndices.ToArray());
            s_arrowCapIndexCount = (uint)arrowCapIndices.Count;

            List <Vec3F> pivotVerts = new List <Vec3F>();

            GeometryHelper.CreateCircle(0.5f, 16, pivotVerts);
            GeometryHelper.CreateCircle(0.375f, 16, pivotVerts);
            GeometryHelper.CreateCircle(0.25f, 16, pivotVerts);
            GeometryHelper.CreateCircle(0.125f, 16, pivotVerts);
            s_pivotVerts       = GameEngine.CreateVertexBuffer(pivotVerts.ToArray());
            s_pivotVertexCount = (uint)pivotVerts.Count;


            s_captionFont = GameEngine.CreateFont("Arial", 14, FontStyle.BOLD);

            s_inited = true;
        }
Esempio n. 2
0
        public static void Init()
        {
            if (s_inited)
            {
                return;
            }

            List <Vector3> sphereVerts   = new List <Vec3F>();
            List <Vector3> sphereNormals = new List <Vec3F>();
            List <uint>    sphereIndices = new List <uint>();

            GeometryHelper.CreateSphere(0.5f, FastSphereSlices, FastSphereStacks, sphereVerts
                                        , sphereNormals, null, sphereIndices);

            s_triLisVbId        = GameEngine.CreateVertexBuffer(sphereVerts.ToArray());
            s_triListIbid       = GameEngine.CreateIndexBuffer(sphereIndices.ToArray());
            s_sphereIndexCount  = (uint)sphereIndices.Count;
            s_sphereStartVertex = 0;
            s_sphereStartVertex = 0;

            List <Vec3F> conePos     = new List <Vec3F>();
            List <uint>  coneIndices = new List <uint>();
            List <Vec3F> coneNorms   = new List <Vec3F>();

            GeometryHelper.CreateCylinder(1.0f, 0.0f, 1.0f, 16, 1, conePos, coneNorms, coneIndices);

            s_coneIndexCount = (uint)coneIndices.Count;

            VertexPN[] conveVB = new VertexPN[conePos.Count];

            for (int i = 0; i < conveVB.Length; i++)
            {
                conveVB[i].Position = conePos[i];
                conveVB[i].Normal   = coneNorms[i];
            }

            s_coneVertId  = GameEngine.CreateVertexBuffer(conveVB);
            s_coneIndexId = GameEngine.CreateIndexBuffer(coneIndices.ToArray());

            List <Vector3> cubePos     = new List <Vector3>();
            List <Vector3> cubeNormals = new List <Vector3>();
            List <Vector2> cubeTex     = new List <Vector2>();
            List <uint>    cubeIndices = new List <uint>();

            GeometryHelper.CreateUnitCube(cubePos, cubeNormals, cubeTex, cubeIndices);
            VertexPN[] cubeVerts = new VertexPN[cubePos.Count];
            for (int i = 0; i < cubeVerts.Length; i++)
            {
                cubeVerts[i].Position = cubePos[i];
                cubeVerts[i].Normal   = cubeNormals[i];
            }
            s_cubeVertId     = GameEngine.CreateVertexBuffer(cubeVerts);
            s_cubeIndexId    = GameEngine.CreateIndexBuffer(cubeIndices.ToArray());
            s_cubeIndexCount = (uint)cubeIndices.Count;


            var linePos = new List <Vec3F>();

            linePos.Add(new Vector3(0, 0, 0));
            linePos.Add(new Vector3(1, 0, 0));

            linePos.Add(new Vector3(0, 0, 0));
            linePos.Add(new Vector3(0, 1, 0));

            linePos.Add(new Vector3(0, 0, 0));
            linePos.Add(new Vector3(0, 0, 1));

            linePos.Add(new Vector3(0, 0, 0));
            linePos.Add(new Vector3(-1, 0, 0));

            linePos.Add(new Vector3(0, 0, 0));
            linePos.Add(new Vector3(0, -1, 0));

            linePos.Add(new Vector3(0, 0, 0));
            linePos.Add(new Vector3(0, 0, -1));

            s_axisStartVertex = 0;
            s_axisVertexCount = (uint)linePos.Count;

            // rect pos;
            linePos.Add(new Vector3(1, 1, 0));
            linePos.Add(new Vector3(-1, 1, 0));

            linePos.Add(new Vector3(-1, 1, 0));
            linePos.Add(new Vector3(-1, -1, 0));

            linePos.Add(new Vector3(-1, -1, 0));
            linePos.Add(new Vector3(1, -1, 0));

            linePos.Add(new Vector3(1, -1, 0));
            linePos.Add(new Vector3(1, 1, 0));

            s_rectVertexCount = 8;
            s_rectStartVertex = (uint)linePos.Count - s_rectVertexCount;

            // unit square
            linePos.Add(new Vector3(0.5f, 0.5f, 0));
            linePos.Add(new Vector3(-0.5f, 0.5f, 0));

            linePos.Add(new Vector3(-0.5f, 0.5f, 0));
            linePos.Add(new Vector3(-0.5f, -0.5f, 0));

            linePos.Add(new Vector3(-0.5f, -0.5f, 0));
            linePos.Add(new Vector3(0.5f, -0.5f, 0));

            linePos.Add(new Vector3(0.5f, -0.5f, 0));
            linePos.Add(new Vector3(0.5f, 0.5f, 0));

            s_unitSquareVertexCount = 8;
            s_unitSquareStartVertex = (uint)linePos.Count - s_unitSquareVertexCount;

            s_linesVertId = GameEngine.CreateVertexBuffer(linePos.ToArray());

            List <Vec3F> circlePos = new List <Vec3F>();

            GeometryHelper.CreateCircle(1.0f, 32, circlePos);
            s_circleVertexCount = (uint)circlePos.Count;
            s_circleVerts       = GameEngine.CreateVertexBuffer(circlePos.ToArray());
            RenderFlag          = BasicRendererFlags.WireFrame;

            List <Vec3F> boxVerts   = new List <Vec3F>();
            List <uint>  boxIndices = new List <uint>();

            GeometryHelper.CreateUnitBox(boxVerts, boxIndices);
            s_boxVertsId      = GameEngine.CreateVertexBuffer(boxVerts.ToArray());
            s_boxIndicesId    = GameEngine.CreateIndexBuffer(boxIndices.ToArray());
            s_boxIndicesCount = (uint)boxIndices.Count;



            List <Vec3F> pivotVerts = new List <Vec3F>();

            GeometryHelper.CreateCircle(1.0f, 16, pivotVerts);
            GeometryHelper.CreateCircle(0.75f, 16, pivotVerts);
            GeometryHelper.CreateCircle(0.5f, 16, pivotVerts);
            GeometryHelper.CreateCircle(0.25f, 16, pivotVerts);
            s_pivotVerts       = GameEngine.CreateVertexBuffer(pivotVerts.ToArray());
            s_pivotVertexCount = (uint)pivotVerts.Count;


            s_captionFont = GameEngine.CreateFont("Arial", 14, FontStyle.BOLD);

            s_inited = true;
        }