public void Draw(Matrix world, BoundingMetaMesh bounding, Color color)
        {
            var text = View.Content.Peek <SlimDX.Direct3D9.Texture>(new Content.TextureConcretizer
            {
                TextureDescription = new Software.Textures.SingleColorTexture(color)
            });

            View.Device9.SetTexture(0, text);
            if (bounding.Mesh != null)
            {
                View.Device9.SetTransform(TransformState.World, bounding.Transformation * world);
                var mesh = View.Content.Peek <SlimDX.Direct3D9.Mesh>(bounding.Mesh);
                mesh.DrawSubset(0);
            }
            else if (bounding.SkinnedMeshInstance != null)
            {
                var sm = View.Content.Peek <Renderer.Renderer.EntityAnimation>(bounding.SkinnedMeshInstance);
                foreach (var v in sm.StoredFrameMatrices)
                {
                    int i = 0;
                    foreach (var m in v.Value)
                    {
                        View.Device9.SetTransform(TransformState.World, m[0]);
                        v.Key.DrawSubset(i);
                        i++;
                    }
                }
            }
            else if (bounding.XMesh != null)
            {
                View.Device9.SetTransform(TransformState.World, bounding.Transformation * world);
                bounding.XMesh.DrawSubset(0);
            }
        }
Beispiel #2
0
        // ----------------------------------------------------------------------------------------------
        // -- BoundingMetaMesh --------------------------------------------------------------------------
        // ----------------------------------------------------------------------------------------------

        public static bool Intersect(Ray a, BoundingMetaMesh b, out object intersection)
        {
            var r = new Common.RayIntersection();

            intersection = r;
            Matrix invTransformation = Matrix.Invert(b.Transformation);
            var    newRay            = new Ray(
                Vector3.TransformCoordinate(a.Position, invTransformation),
                Vector3.Normalize(Vector3.TransformNormal(a.Direction, invTransformation)));

            if (b.XMesh != null)
            {
#if BOUNDING_META_MESH_REAQUIRE_ON_DISPOSED
                if (b.XMesh.Disposed)
                {
                    b.Init(content);
                }
#endif
                if (!b.XMesh.Intersects(newRay, out r.Distance))
                {
                    return(false);
                }
            }
            else if (b.Mesh != null)
            {
                var mesh = content.Peek <SlimDX.Direct3D9.Mesh>(b.Mesh);
                if (!mesh.Intersects(newRay, out r.Distance))
                {
                    return(false);
                }
            }
            else if (b.SoftwareMesh != null)
            {
                Vector2 uv;
                Graphics.Software.Triangle triangle;
                if (!b.SoftwareMesh.Intersect(newRay, false, out triangle, out r.Distance, out uv))
                {
                    return(false);
                }
            }
            else if (b.SkinnedMeshInstance != null)
            {
                newRay = a;
                var    sm = content.Peek <Renderer.Renderer.EntityAnimation>(b.SkinnedMeshInstance);
                object o;
                if (!Intersect(newRay, sm, out o))
                {
                    return(false);
                }
                r = (Common.RayIntersection)o;
            }

            var newPos = Vector3.TransformCoordinate(newRay.Position + newRay.Direction * r.Distance,
                                                     b.Transformation);
            r.Distance = (newPos - a.Position).Length();
            return(true);
        }
 public static BoundingMetaMesh Transform(BoundingMetaMesh bounding, Matrix transformation)
 {
     return new BoundingMetaMesh
     {
         Mesh = bounding.Mesh,
         Transformation = bounding.Transformation * transformation,
         SkinnedMeshInstance = bounding.SkinnedMeshInstance,
         SoftwareMesh = bounding.SoftwareMesh,
         XMesh = bounding.XMesh
     };
 }
 public static BoundingMetaMesh Transform(BoundingMetaMesh bounding, Matrix transformation)
 {
     return(new BoundingMetaMesh
     {
         Mesh = bounding.Mesh,
         Transformation = bounding.Transformation * transformation,
         SkinnedMeshInstance = bounding.SkinnedMeshInstance,
         SoftwareMesh = bounding.SoftwareMesh,
         XMesh = bounding.XMesh
     });
 }
Beispiel #5
0
        public static bool Intersect(Common.Bounding.Line a, BoundingMetaMesh b, out object intersection)
        {
            // not sure what this is supposed to return yet so I'll postpone it until it is needed
            intersection = null;

            Vector3 v = a.P1 - a.P0;
            Ray     r = new Ray(a.P0, Vector3.Normalize(v));

            object obj;
            bool   hit = Intersect(r, b, out obj);

            if (hit)
            {
                return(((Common.RayIntersection)obj).Distance <= v.Length());
            }
            return(false);
        }
 public static bool Intersect(Common.Bounding.Cylinder a, BoundingMetaMesh b, out object intersection)
 {
     // Hack! Only compares position
     return Common.Intersection.Intersect(a, Common.Boundings.Translation(b), out intersection);
 }
        public static bool Intersect(Common.Bounding.Line a, BoundingMetaMesh b, out object intersection)
        {
            // not sure what this is supposed to return yet so I'll postpone it until it is needed
            intersection = null;

            Vector3 v = a.P1 - a.P0;
            Ray r = new Ray(a.P0, Vector3.Normalize(v));

            object obj;
            bool hit = Intersect(r, b, out obj);
            if (hit)
                return ((Common.RayIntersection)obj).Distance <= v.Length();
            return false;
        }
        // ----------------------------------------------------------------------------------------------
        // -- BoundingMetaMesh --------------------------------------------------------------------------
        // ----------------------------------------------------------------------------------------------

        public static bool Intersect(Ray a, BoundingMetaMesh b, out object intersection)
        {
            var r = new Common.RayIntersection();
            intersection = r;
            Matrix invTransformation = Matrix.Invert(b.Transformation);
            var newRay = new Ray(
                Vector3.TransformCoordinate(a.Position, invTransformation),
                Vector3.Normalize(Vector3.TransformNormal(a.Direction, invTransformation)));

            if (b.XMesh != null)
            {
#if BOUNDING_META_MESH_REAQUIRE_ON_DISPOSED
                if (b.XMesh.Disposed)
                    b.Init(content);
#endif
                if (!b.XMesh.Intersects(newRay, out r.Distance)) return false;
            }
            else if (b.Mesh != null)
            {
                var mesh = content.Peek<SlimDX.Direct3D9.Mesh>(b.Mesh);
                if (!mesh.Intersects(newRay, out r.Distance)) return false;
            }
            else if (b.SoftwareMesh != null)
            {
                Vector2 uv;
                Graphics.Software.Triangle triangle;
                if (!b.SoftwareMesh.Intersect(newRay, false, out triangle, out r.Distance, out uv)) return false;
            }
            else if (b.SkinnedMeshInstance != null)
            {
                newRay = a;
                var sm = content.Peek<Renderer.Renderer.EntityAnimation>(b.SkinnedMeshInstance);
                object o;
                if (!Intersect(newRay, sm, out o)) return false;
                r = (Common.RayIntersection)o;
            }

            var newPos = Vector3.TransformCoordinate(newRay.Position + newRay.Direction * r.Distance, 
                b.Transformation);
            r.Distance = (newPos - a.Position).Length();
            return true;
        }
        protected virtual void OnHitsObject(Common.IMotion.IObject obj, Vector3 intersection)
        {
            if (IsRemoved) return;

            Translation = intersection;
            if (obj.Tag is GroundPiece)
            {
                CreateGroundBulletHole(intersection);
            }
            else if (obj.Tag is Props.Prop)
            {
                var prop = obj.Tag as Props.Prop;
                if (prop.MainGraphic != null)
                {
                    var dir = Vector3.Normalize(velocity);
                    var dirLeft = Vector3.TransformNormal(dir, Matrix.RotationZ(0.1f));
                    var dirUp = dir;
                    dirUp.Z = 0.1f;
                    var mesh = new BoundingMetaMesh
                    {
                        Mesh = ((MetaModel)prop.MainGraphic).XMesh,
                        Transformation = ((MetaModel)prop.MainGraphic).World * prop.WorldMatrix
                    };
                    var p = intersection - dir;
                    var rayForward = new Ray(p, dir);
                    object distForward, distLeft, distUp;
                    var h1 = global::Graphics.Intersection.Intersect(rayForward, mesh, out distForward);
                    if (!h1) return;

                    var point = rayForward.Position + rayForward.Direction * ((Common.RayIntersection)distForward).Distance;
                    p = point - dir;
                    var rayLeft = new Ray(p, dirLeft);
                    var rayUp = new Ray(p, dirUp);

                    var h2 = global::Graphics.Intersection.Intersect(rayLeft, mesh, out distLeft);
                    var h3 = global::Graphics.Intersection.Intersect(rayUp, mesh, out distUp);
                    var pointLeft = rayLeft.Position + rayLeft.Direction * ((Common.RayIntersection)distLeft).Distance;
                    var pointUp = rayUp.Position + rayUp.Direction * ((Common.RayIntersection)distUp).Distance;

                    var vUp = Vector3.Normalize(pointUp - point);
                    var vLeft = Vector3.Normalize(pointLeft - point);

                    var forward = Vector3.Cross(vUp, vLeft);
                    var up = Vector3.Cross(vLeft, forward);
                    var left = vLeft;

                    Matrix rot = Common.Math.MatrixFromVectors(-left, up, forward, point);
                    CreateWallBulletHole(rot);
                }
            }
            /*Game.Instance.Scene.Add(new Props.Stone3
            {
                Translation = intersection,
                Scale = new Vector3(0.05f, 0.05f, 0.05f),
                PhysicsLocalBounding = null
            });*/
        }
 public static Vector3 Translation(BoundingMetaMesh bounding)
 {
     return Common.Math.Position(bounding.Transformation);
 }
 public static Vector3 Translation(BoundingMetaMesh bounding)
 {
     return(Common.Math.Position(bounding.Transformation));
 }
Beispiel #12
0
 public static bool Intersect(Common.Bounding.Frustum a, BoundingMetaMesh b, out object intersection)
 {
     intersection = null;
     // Hack! Never actually compares against bounding meta meshes.
     return(true);
 }
Beispiel #13
0
 public static bool Intersect(Common.Bounding.Cylinder a, BoundingMetaMesh b, out object intersection)
 {
     // Hack! Only compares position
     return(Common.Intersection.Intersect(a, Common.Boundings.Translation(b), out intersection));
 }
 public void Draw(Matrix world, BoundingMetaMesh bounding, Color color)
 {
     var text = View.Content.Peek<SlimDX.Direct3D9.Texture>(new Content.TextureConcretizer
     {
         TextureDescription = new Software.Textures.SingleColorTexture(color)
     });
     View.Device9.SetTexture(0, text);
     if (bounding.Mesh != null)
     {
         View.Device9.SetTransform(TransformState.World, bounding.Transformation * world);
         var mesh = View.Content.Peek<SlimDX.Direct3D9.Mesh>(bounding.Mesh);
         mesh.DrawSubset(0);
     }
     else if (bounding.SkinnedMeshInstance != null)
     {
         var sm = View.Content.Peek<Renderer.Renderer.EntityAnimation>(bounding.SkinnedMeshInstance);
         foreach (var v in sm.StoredFrameMatrices)
         {
             int i = 0;
             foreach (var m in v.Value)
             {
                 View.Device9.SetTransform(TransformState.World, m[0]);
                 v.Key.DrawSubset(i);
                 i++;
             }
         }
     }
     else if (bounding.XMesh != null)
     {
         View.Device9.SetTransform(TransformState.World, bounding.Transformation * world);
         bounding.XMesh.DrawSubset(0);
     }
 }
 public static BoundingBox BoundingToBox(BoundingMetaMesh bounding)
 {
     return(content.Peek <Content.StructBoxer <BoundingBox> >(bounding.Mesh).Value);
 }
 public static bool Intersect(Common.Bounding.Frustum a, BoundingMetaMesh b, out object intersection)
 {
     intersection = null;
     // Hack! Never actually compares against bounding meta meshes.
     return true;
 }
        protected object CreatePhysicsMeshBounding(MetaModel model, Matrix transformation)
        {
            BoundingMetaMesh boundingMetaMesh = new BoundingMetaMesh();
            BoundingBox boundingBox = new Graphics.MetaBoundingBox
            {
                Mesh = model.XMesh ?? model.SkinnedMesh,
                Transformation = model.World
            }.GetBoundingBox(ContentPool).Value;

            if (Program.Settings != null && Program.Settings.MotionSettings.UseSoftwareMeshes)
            {
                boundingMetaMesh.SoftwareMesh = Program.Instance.Content.Acquire<global::Graphics.Software.Mesh>(model.XMesh);
            }
            else
            {
                //if (model.XMesh is Graphics.Content.MeshFromFile)
                //    ((Graphics.Content.MeshFromFile)model.XMesh).Flags = SlimDX.Direct3D9.MeshFlags.Software;
                boundingMetaMesh.Mesh = model.XMesh ?? model.SkinnedMesh;
            }
            if(model.SkinnedMesh != null)
                boundingMetaMesh.SkinnedMeshInstance = MetaEntityAnimation;
            boundingMetaMesh.Transformation = model.World * transformation;

            boundingMetaMesh.Init(ContentPool);

            return new Common.Bounding.Chain
            {
                Boundings = new object[]
                {
                    boundingBox,
                    boundingMetaMesh
                },
                Shallow = true
            };
        }
 public static BoundingBox BoundingToBox(BoundingMetaMesh bounding)
 {
     return content.Peek<Content.StructBoxer<BoundingBox>>(bounding.Mesh).Value;
 }