Пример #1
0
        /// <summary>
        // Given arbitrary point Point will return the nearest point on the surface
        /// </summary>
        /// <param name="Point"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public Vector3d GetNearestPointOnSurface(Vector3d Point, double offset = 1)
        {
            Vector3d dir = Point - Position;

            dir.Normalize();

            Vector3d Result = Point;

            if (Tag != null)
            {
                MModel         model = (MModel)Tag;
                MPhysicsObject ph    = (MPhysicsObject)model.FindModuleByType(EType.PhysicsObject);

                bool Success = false;

                MPhysics.Instance.RayCastRequest(Point, Position, this, (result) =>
                {
                    Vector3d pt = result.Hitpoint;
                    if (Success)
                    {
                        Result = pt + dir * offset;
                    }
                    else
                    {
                        Result = Position + dir * (Radius.X + offset);
                    }
                });
            }
            return(Result);
        }
Пример #2
0
        void CreateTest()
        {
            for (int i = 0; i < 1000; i++)
            {
                Vector3d pos = Globals.Avatar.Target.transform.Position + Globals.LocalUpVector * i;

                MCube          c  = (MCube)Helper.CreateCube(MScene.ModelRoot, "Cube" + i, pos);
                MPhysicsObject po = new MPhysicsObject(c, "cube", 0.1, MPhysicsObject.EShape.Box, false, Vector3d.One);
            }
        }
Пример #3
0
        private void MMessageBus_DeleteObjectRequestHandler(object sender, DeleteRequestEvent e)
        {
            MSceneObject o = e.TargetObject;

            if (o == null)
            {
                return;
            }

            MPhysicsObject po = (MPhysicsObject)o.FindModuleByType(MObject.EType.PhysicsObject);

            MScene.Physics.Remove(po);

            MScene.ModelRoot.Remove(o);
            MScene.Priority1.Remove(o);
            MScene.Priority2.Remove(o);
            MScene.SelectedObject = null;
        }
Пример #4
0
        private void MMessageBus_ObjectDeletedEvent(object sender, DeleteEvent e)
        {
            MSceneObject o = (MSceneObject)MScene.ModelRoot.FindModuleByInstanceID(e.InstanceID);

            if (o == null)
            {
                return;
            }

            MPhysicsObject po = (MPhysicsObject)o.FindModuleByType(MObject.EType.PhysicsObject);

            MScene.Physics.Remove(po);

            MScene.ModelRoot.Remove(o);
            MScene.Priority1.Remove(o);
            MScene.Priority2.Remove(o);
            MScene.SelectedObject = null;

            //o.Dispose(); //don't dispose, it disposes templates, let GC pick up unallocated objects
        }
Пример #5
0
        public static MSceneObject LoadTemplate(string TemplateID)
        {
            MBuildingBlock bb = MBuildParts.GetBlock(TemplateID);

            if (bb == null)
            {
                Console.WriteLine("WARNING: MSpawnHandler.LoadTemplate " + TemplateID + " not found in blocks");
                return(null);
            }

            MSceneObject o = null;

            if (bb.Type == MBuildParts.MAnimatedModel)
            {
                o = Helper.CreateAnimatedModel(MScene.TemplateRoot, TemplateID, bb.Model, Vector3d.Zero);
                MAnimatedModel man = (MAnimatedModel)o;
                man.BoneOffset = MassiveTools.VectorFromArray(bb.BoneOffset);
            }

            if (bb.Type == MBuildParts.MModel)
            {
                o = Helper.CreateModel(MScene.TemplateRoot, TemplateID, bb.Model, Vector3d.Zero);
            }

            MMaterial mat = (MMaterial)MScene.MaterialRoot.FindModuleByName(bb.MaterialID);

            if (mat == null)
            {
                Console.WriteLine("MSpawnHandler.LoadTemplate " + bb.MaterialID + " was null");
            }
            o.SetMaterial(mat);

            Vector3d size = MassiveTools.VectorFromArray(bb.Size);

            MPhysicsObject.EShape shape = GetShape(bb.PhysicsShape);
            if (shape != MPhysicsObject.EShape.NULL)
            {
                MPhysicsObject mpo = new MPhysicsObject(o, TemplateID + "_physics", bb.Weight, shape,
                                                        true, size);
                mpo.SetSleep(5);
                mpo.SetFriction(0.5);
                if (shape != MPhysicsObject.EShape.Sphere)
                {
                    mpo.SetAngularFactor(0.0, 0.0, 0.0);
                    mpo.SetDamping(0.5, 0.5);
                    mpo.SetRestitution(0.5);
                }
                else
                {
                    mpo.SetDamping(0.1, 0.1);
                    mpo.SetRestitution(0.8);
                }
            }

            o.TemplateID               = TemplateID;
            o.InstanceID               = TemplateID;
            o.IsTransparent            = bb.IsTransparent;
            o.transform.RotationOffset = Quaterniond.FromEulerAngles(MassiveTools.VectorFromArray(bb.RotationOffset));
            o.Setup();

            AddSubmodules(bb, o);

            return(o);
        }