Example #1
0
        public override void Update()
        {
            MSceneObject msp        = (MSceneObject)Parent;
            Vector3d     CurrentPos = msp.transform.Position;
            Quaterniond  CurrentRot = msp.transform.Rotation;

            //CurrentPos = Vector3d.Lerp(CurrentPos, TargetPosition, Time.DeltaTime * Speed);
            Start += Time.DeltaTime * Speed;
            if (Start > 1)
            {
                Start = 1;
            }
            CurrentPos = Extensions.SmoothStep(StartPosition, TargetPosition, Start);

            CurrentRot = Quaterniond.Slerp(StartRotation, TargetRotation, Start);
            msp.SetRotation(CurrentRot);
            msp.SetPosition(CurrentPos);

            //msp.LookAt(TargetPosition);
            double distance = Vector3d.Distance(CurrentPos, TargetPosition);

            if (distance < 1)
            {
                TeleportComplete();
            }
        }
Example #2
0
        public void Stop()
        {
            if (msoParent == null)
            {
                return;
            }
            msoParent.SetPosition(TargetPosition);
            msoParent.SetRotation(TargetRotation, false);

            msoParent = null;
        }
Example #3
0
        public void Complete()
        {
            MSceneObject msp = (MSceneObject)Parent;

            //MPhysicsObject po = (MPhysicsObject)msp.FindModuleByType(EType.PhysicsObject);
            msp.SetPosition(TargetPosition);
            msp.SetRotation(TargetRotation, false);

            Parent.Remove(this);
            Parent = null;
        }
Example #4
0
        public void TeleportComplete()
        {
            MPhysicsObject po  = (MPhysicsObject)Parent.FindModuleByType(EType.PhysicsObject);
            MSceneObject   msp = (MSceneObject)Parent;

            msp.SetPosition(TargetPosition);
            msp.SetRotation(TargetRotation);
            if (po != null)
            {
                po.SetActive(true);
                po.StopAllMotion();
            }

            if (TeleportCompleteHandler != null)
            {
                TeleportCompleteHandler(this, new MoveEvent(Parent.InstanceID, TargetPosition, TargetRotation));
            }

            Parent.Remove(this);
            Dispose();
        }
Example #5
0
        void DoIdle()
        {
            accum += Time.DeltaTime * direction * speed;
            if (accum > 1)
            {
                direction = -direction;
                accum     = 1;
            }
            if (accum <= -1)
            {
                accum     = -1;
                direction = -direction;
            }
            MSceneObject msoParent = (MSceneObject)Parent;

            msoParent.SetRotation(OriginalRotation * Quaterniond.FromEulerAngles(0, accum, 0));

            if (Parent is MAnimatedModel)
            {
                MAnimatedModel m = (MAnimatedModel)Parent;
                m._animationController.PlayAnimation("idle", 1);
            }
        }
Example #6
0
        public override void Update()
        {
            if (Idle == true)
            {
                return;
            }
            if (msoParent == null)
            {
                return;
            }

            if (po == null)
            {
                po = (MPhysicsObject)Parent.FindModuleByType(EType.PhysicsObject);
            }

            MSceneObject msp        = (MSceneObject)Parent;
            Vector3d     CurrentPos = msp.transform.Position;
            Quaterniond  CurrentRot = msp.transform.Rotation;

            //CurrentPos = Vector3d.Lerp(CurrentPos, TargetPosition, Time.DeltaTime * Speed);
            Value += Time.DeltaTime * Speed;
            if (Value > 1)
            {
                Value = 1;
            }
            double dist = (Vector3d.Distance(TargetPosition, CurrentPos));

            if (dist > 1000)
            {
                Start = 0.999;
                if (po != null)
                {
                    po.SetActive(false);
                }
            }
            CurrentPos = Vector3d.Lerp(StartPosition, TargetPosition, Value);
            CurrentRot = Quaterniond.Slerp(CurrentRot, TargetRotation, Value);

            //if ( dist< 0.1)
            if (Value >= 1)
            {
                CurrentPos = TargetPosition;
                CurrentRot = TargetRotation;
                Idle       = true;
                //msp.SetPosition(TargetPosition);
                //msp.SetRotation(TargetRotation, false);
                //Console.WriteLine("idle");
                if (po != null)
                {
                    po.SetActive(true);
                }
                Complete();
            }
            else
            {
                if (po != null)
                {
                    po.SetActive(true);
                }
            }

            msp.SetPosition(CurrentPos);
            msp.SetRotation(CurrentRot, false);
        }
Example #7
0
        /**
         * Creates a copy of an existing object from the TemplateRoot
         * */
        public static MSceneObject Spawn(MServerObject mso,
                                         Vector3d Pos, Quaterniond Rot)
        {
            MSceneObject m = (MSceneObject)MScene.TemplateRoot.FindModuleByInstanceID(mso.TemplateID);

            if (m == null)
            {
                Console.WriteLine("TEMPLATE NOT LOADED INTO MScene.TemplateRoot:" + mso.TemplateID);
                return(null);
            }

            MSceneObject t = null;

            MObject TargetRoot = MScene.ModelRoot;

            if (m.IsTransparent)
            {
                TargetRoot = MScene.Priority2;
            }
            else
            {
                TargetRoot = MScene.Priority1;
            }

            if (m.Type == MObject.EType.PrimitiveCube)
            {
                t = CreateCube(TargetRoot, mso.Name, Pos);
            }
            if (m.Type == MObject.EType.PrimitiveSphere)
            {
                t = CreateSphere(TargetRoot, 2, mso.Name, Pos);
            }
            if (m.Type == MObject.EType.Model)
            {
                t = SpawnModel(TargetRoot, mso.TemplateID, mso.OwnerID, mso.Name, Pos);
            }
            if (m.Type == MObject.EType.AnimatedModel)
            {
                t = SpawnAnimatedModel(TargetRoot, mso.TemplateID, mso.OwnerID, mso.Name, Pos);
            }

            if (m.Type == MObject.EType.InstanceMesh)
            {
                t = SpawnInstanced(TargetRoot, mso.TemplateID, mso.OwnerID, mso.Name, Pos);
            }

            t.transform.Position = Pos;
            t.transform.Rotation = Rot;

            m.CopyTo(t);
            t.OwnerID = mso.OwnerID;
            t.SetPosition(Pos);
            t.SetRotation(Rot);
            t.transform.Position = Pos;
            t.transform.Rotation = Rot;

            t.Tag = mso.Tag;

            MClickHandler ch = (MClickHandler)m.FindModuleByType(MObject.EType.ClickHandler);

            if (ch != null)
            {
                MClickHandler ch2 = new MClickHandler();
                ch2.Clicked       = ch.Clicked;
                ch2.RightClicked  = ch.RightClicked;
                ch2.DoubleClicked = ch.DoubleClicked;
                t.Add(ch2);
            }
            return(t);
        }