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 }); }
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 * });*/ }