Ejemplo n.º 1
0
        public static DrawModel CreateFloor(float geometryScale, float uvScale, Vector4 offset)
        {
            var   drawSys = DrawSystem.GetInstance();
            var   d3d     = drawSys.D3D;
            float gs      = geometryScale;
            float us      = uvScale;

            var vertices = new _VertexCommon[]
            {
                new _VertexCommon()
                {
                    Position = new Vector4(-gs, 0, gs, 1), Texcoord = new Vector2(0, 0), Normal = Vector3.UnitY
                },
                new _VertexCommon()
                {
                    Position = new Vector4(gs, 0, gs, 1), Texcoord = new Vector2(us, 0), Normal = Vector3.UnitY
                },
                new _VertexCommon()
                {
                    Position = new Vector4(gs, 0, -gs, 1), Texcoord = new Vector2(us, us), Normal = Vector3.UnitY
                },
                new _VertexCommon()
                {
                    Position = new Vector4(-gs, 0, gs, 1), Texcoord = new Vector2(0, 0), Normal = Vector3.UnitY
                },
                new _VertexCommon()
                {
                    Position = new Vector4(gs, 0, -gs, 1), Texcoord = new Vector2(us, us), Normal = Vector3.UnitY
                },
                new _VertexCommon()
                {
                    Position = new Vector4(-gs, 0, -gs, 1), Texcoord = new Vector2(0, us), Normal = Vector3.UnitY
                },
            };

            Aabb aabb = Aabb.Invalid();

            for (int i = 0; i < vertices.Length; ++i)
            {
                vertices[i].Position  += offset;
                vertices[i].Position.W = 1;
                aabb.ExtendByPoint(MathUtil.ToVector3(vertices[i].Position));
            }

            var model = new DrawModel("");
            var mesh  = DrawUtil.CreateMeshData <_VertexCommon>(d3d, PrimitiveTopology.TriangleList, vertices);

            model.m_nodeList.Add(new Node()
            {
                Mesh = mesh, Material = DebugMaterial.Create(), IsDebug = false, HasBone = false
            });
            model.m_bb = aabb;

            return(model);
        }
Ejemplo n.º 2
0
        public static DrawModel CreateFrustum(String uid, Matrix viewProjectionMatrix, Color4 color)
        {
            var drawSys = DrawSystem.GetInstance();
            var d3d     = drawSys.D3D;

            viewProjectionMatrix.Invert();

            var points = new Vector4[8];

            points[0] = Vector3.Transform(new Vector3(-1, -1, 0), viewProjectionMatrix);
            points[1] = Vector3.Transform(new Vector3(1, -1, 0), viewProjectionMatrix);
            points[2] = Vector3.Transform(new Vector3(-1, 1, 0), viewProjectionMatrix);
            points[3] = Vector3.Transform(new Vector3(1, 1, 0), viewProjectionMatrix);
            points[4] = Vector3.Transform(new Vector3(-1, -1, 1), viewProjectionMatrix);
            points[5] = Vector3.Transform(new Vector3(1, -1, 1), viewProjectionMatrix);
            points[6] = Vector3.Transform(new Vector3(-1, 1, 1), viewProjectionMatrix);
            points[7] = Vector3.Transform(new Vector3(1, 1, 1), viewProjectionMatrix);

            var vertices = new _VertexDebug[]
            {
                new _VertexDebug()
                {
                    Position = points[0]
                },
                new _VertexDebug()
                {
                    Position = points[1]
                },
                new _VertexDebug()
                {
                    Position = points[1]
                },
                new _VertexDebug()
                {
                    Position = points[3]
                },
                new _VertexDebug()
                {
                    Position = points[3]
                },
                new _VertexDebug()
                {
                    Position = points[2]
                },
                new _VertexDebug()
                {
                    Position = points[2]
                },
                new _VertexDebug()
                {
                    Position = points[0]
                },

                new _VertexDebug()
                {
                    Position = points[4]
                },
                new _VertexDebug()
                {
                    Position = points[5]
                },
                new _VertexDebug()
                {
                    Position = points[5]
                },
                new _VertexDebug()
                {
                    Position = points[7]
                },
                new _VertexDebug()
                {
                    Position = points[7]
                },
                new _VertexDebug()
                {
                    Position = points[6]
                },
                new _VertexDebug()
                {
                    Position = points[6]
                },
                new _VertexDebug()
                {
                    Position = points[4]
                },

                new _VertexDebug()
                {
                    Position = points[0]
                },
                new _VertexDebug()
                {
                    Position = points[4]
                },
                new _VertexDebug()
                {
                    Position = points[1]
                },
                new _VertexDebug()
                {
                    Position = points[5]
                },
                new _VertexDebug()
                {
                    Position = points[2]
                },
                new _VertexDebug()
                {
                    Position = points[6]
                },
                new _VertexDebug()
                {
                    Position = points[3]
                },
                new _VertexDebug()
                {
                    Position = points[7]
                },
            };

            Aabb aabb = Aabb.Invalid();

            for (int i = 0; i < vertices.Length; ++i)
            {
                vertices[i].Position.X /= vertices[i].Position.W;
                vertices[i].Position.Y /= vertices[i].Position.W;
                vertices[i].Position.Z /= vertices[i].Position.W;
                vertices[i].Position.W  = 1;
                vertices[i].Color       = color;
                aabb.ExtendByPoint(MathUtil.ToVector3(vertices[i].Position));
            }

            var model = new DrawModel(uid);

            model.m_nodeList.Add(new Node()
            {
                Mesh     = DrawUtil.CreateMeshData <_VertexDebug>(d3d, PrimitiveTopology.LineList, vertices),
                Material = DebugMaterial.Create(),
                IsDebug  = true,
                HasBone  = false,
            });
            model.m_bb = aabb;

            return(model);
        }
Ejemplo n.º 3
0
        public static DrawModel CreateBox(String uid, Aabb box, Color4 color)
        {
            var drawSys = DrawSystem.GetInstance();
            var d3d     = drawSys.D3D;

            Vector3 min      = box.Min;
            Vector3 max      = box.Max;
            var     vertices = new _VertexDebug[]
            {
                new _VertexDebug()
                {
                    Position = new Vector4(min.X, min.Y, min.Z, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(max.X, min.Y, min.Z, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(max.X, min.Y, min.Z, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(max.X, min.Y, max.Z, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(max.X, min.Y, max.Z, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(min.X, min.Y, max.Z, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(min.X, min.Y, max.Z, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(min.X, min.Y, min.Z, 1)
                },

                new _VertexDebug()
                {
                    Position = new Vector4(min.X, min.Y, min.Z, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(min.X, max.Y, min.Z, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(max.X, min.Y, min.Z, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(max.X, max.Y, min.Z, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(max.X, min.Y, max.Z, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(max.X, max.Y, max.Z, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(min.X, min.Y, max.Z, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(min.X, max.Y, max.Z, 1)
                },

                new _VertexDebug()
                {
                    Position = new Vector4(min.X, max.Y, min.Z, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(max.X, max.Y, min.Z, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(max.X, max.Y, min.Z, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(max.X, max.Y, max.Z, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(max.X, max.Y, max.Z, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(min.X, max.Y, max.Z, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(min.X, max.Y, max.Z, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(min.X, max.Y, min.Z, 1)
                },
            };

            Aabb aabb = Aabb.Invalid();

            for (int i = 0; i < vertices.Length; ++i)
            {
                vertices[i].Position.W = 1;
                vertices[i].Color      = color;
                aabb.ExtendByPoint(MathUtil.ToVector3(vertices[i].Position));
            }

            var model = new DrawModel(uid);

            model.m_nodeList.Add(new Node()
            {
                Mesh     = DrawUtil.CreateMeshData <_VertexDebug>(d3d, PrimitiveTopology.LineList, vertices),
                Material = DebugMaterial.Create(),
                IsDebug  = true,
                HasBone  = false,
            });
            model.m_bb = aabb;

            return(model);
        }
Ejemplo n.º 4
0
        public static DrawModel CreateBone(String uid, float length, Color4 color, Vector4 offset)
        {
            var   drawSys = DrawSystem.GetInstance();
            var   d3d     = drawSys.D3D;
            float w       = 0.1f * length;
            float L       = length;

            var vertices = new _VertexDebug[]
            {
                // bottom pyramid
                new _VertexDebug()
                {
                    Position = new Vector4(0, 0, 0, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(-w, -w, w, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(0, 0, 0, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(-w, w, w, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(0, 0, 0, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(w, -w, w, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(0, 0, 0, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(w, w, w, 1)
                },

                // middle plane
                new _VertexDebug()
                {
                    Position = new Vector4(w, w, w, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(-w, w, w, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(-w, w, w, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(-w, -w, w, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(-w, -w, w, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(w, -w, w, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(w, -w, w, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(w, w, w, 1)
                },

                // top pyramid
                new _VertexDebug()
                {
                    Position = new Vector4(0, 0, L, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(-w, -w, w, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(0, 0, L, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(w, -w, w, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(0, 0, L, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(-w, w, w, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(0, 0, L, 1)
                },
                new _VertexDebug()
                {
                    Position = new Vector4(w, w, w, 1)
                },
            };

            Aabb aabb = Aabb.Invalid();

            for (int i = 0; i < vertices.Length; ++i)
            {
                vertices[i].Position  += offset;
                vertices[i].Position.W = 1;
                vertices[i].Color      = color;
                aabb.ExtendByPoint(MathUtil.ToVector3(vertices[i].Position));
            }

            var model = new DrawModel(uid);

            model.m_nodeList.Add(new Node()
            {
                Mesh     = DrawUtil.CreateMeshData <_VertexDebug>(d3d, PrimitiveTopology.LineList, vertices),
                Material = DebugMaterial.Create(),
                IsDebug  = true,
                HasBone  = false,
            });
            model.m_bb = aabb;

            return(model);
        }