Ejemplo n.º 1
0
 public static void AssembleVertexPN(List<Vec3F> pos, List<Vec3F> norm,
     List<VertexPN> outVertList)
 {
     if (pos.Count != norm.Count)
         throw new ArgumentException("pos count not equal norm count");
     outVertList.Clear();
     VertexPN vertex = new VertexPN();
     for(int k = 0; k < pos.Count; k++)
     {
         vertex.Position = pos[k];
         vertex.Normal = norm[k];
         outVertList.Add(vertex);
     }
 }
Ejemplo n.º 2
0
        public static void AssembleVertexPN(List <Vec3F> pos, List <Vec3F> norm,
                                            List <VertexPN> outVertList)
        {
            if (pos.Count != norm.Count)
            {
                throw new ArgumentException("pos count not equal norm count");
            }
            outVertList.Clear();
            VertexPN vertex = new VertexPN();

            for (int k = 0; k < pos.Count; k++)
            {
                vertex.Position = pos[k];
                vertex.Normal   = norm[k];
                outVertList.Add(vertex);
            }
        }
Ejemplo n.º 3
0
        // create vertex buffer with given vertex format from user data.
        public static ulong CreateVertexBuffer(VertexPN[] buffer)
        {
            if (buffer == null || buffer.Length < 2)
                return 0;

            ulong vbId = 0;
            fixed (float* ptr = &buffer[0].Position.X)
            {
                vbId = NativeCreateVertexBuffer(VertexFormat.VF_PN, ptr, (uint)buffer.Length);
            }
            return vbId;
        }
Ejemplo n.º 4
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;
        }
Ejemplo n.º 5
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;
        }