コード例 #1
0
        public void GenerateBox(Vector3 position, Vector3 size, Vector3 color)
        {
            if (Mesh != null)
            {
                Mesh.Clear();
            }

            Mesh myMesh = new Mesh();


            Vector3 frontTL = new Vector3(position.X - size.X / 2.0f, position.Y - size.Y / 2.0f, position.Z - size.Z / 2.0f);
            Vector3 frontBL = new Vector3(position.X - size.X / 2.0f, position.Y + size.Y / 2.0f, position.Z - size.Z / 2.0f);
            Vector3 frontTR = new Vector3(position.X + size.X / 2.0f, position.Y - size.Y / 2.0f, position.Z - size.Z / 2.0f);
            Vector3 frontBR = new Vector3(position.X + size.X / 2.0f, position.Y + size.Y / 2.0f, position.Z - size.Z / 2.0f);

            Vector3 backTL = new Vector3(position.X - size.X / 2.0f, position.Y - size.Y / 2.0f, -position.Z + size.Z / 2.0f);
            Vector3 backBL = new Vector3(position.X - size.X / 2.0f, position.Y + size.Y / 2.0f, -position.Z + size.Z / 2.0f);
            Vector3 backTR = new Vector3(position.X + size.X / 2.0f, position.Y - size.Y / 2.0f, -position.Z + size.Z / 2.0f);
            Vector3 backBR = new Vector3(position.X + size.X / 2.0f, position.Y + size.Y / 2.0f, -position.Z + size.Z / 2.0f);

            // Front rect
            Vector3 normal = new Vector3(0, 0, 1);

            MeshUtils.CreateLine(ref myMesh, frontTL, frontTR, color);
            MeshUtils.CreateLine(ref myMesh, frontTR, frontBR, color);
            MeshUtils.CreateLine(ref myMesh, frontBR, frontBL, color);
            MeshUtils.CreateLine(ref myMesh, frontBL, frontTL, color);

            MeshUtils.CreateLine(ref myMesh, frontTL, backTL, color);
            MeshUtils.CreateLine(ref myMesh, frontTR, backTR, color);
            MeshUtils.CreateLine(ref myMesh, frontBR, backBR, color);
            MeshUtils.CreateLine(ref myMesh, frontBL, backBL, color);

            MeshUtils.CreateLine(ref myMesh, backTL, backTR, color);
            MeshUtils.CreateLine(ref myMesh, backTR, backBR, color);
            MeshUtils.CreateLine(ref myMesh, backBR, backBL, color);
            MeshUtils.CreateLine(ref myMesh, backBL, backTL, color);


            Mesh = myMesh;

            Mesh.GenerateVAO();
        }