Example #1
0
 //this waits for the server to respond before actually moving the object.
 //another strategy might be to move the object, then correct
 private void Network_PositionChangeHandler(object sender, Massive.Events.MoveEvent e)
 {
     //throw new NotImplementedException();
     if (!e.InstanceID.Equals(Globals.UserAccount.UserID))
     {
         MSceneObject mo = (MSceneObject)MScene.ModelRoot.FindModuleByInstanceID(e.InstanceID);
         if (mo != null)
         {
             //movesync smoothly moves an object into position
             MMoveSync ms = (MMoveSync)mo.FindModuleByType(MObject.EType.MoveSync);
             if (ms == null)
             {
                 ms = new MMoveSync(mo, e.Position, e.Rotation);
                 mo.Add(ms);
             }
             else
             {
                 ms.SetTarget(e.Position, e.Rotation);
             }
         }
     }
     else
     {
         MMessageBus.AvatarMoved(this, e.InstanceID, e.Position, e.Rotation);
     }
     //Console.WriteLine(e.Position);
 }
Example #2
0
        private void MMessageBus_AvatarMovedEvent(object sender, MoveEvent e)
        {
            MLight light = (MLight)MScene.UtilityRoot.FindModuleByType(MObject.EType.DirectionalLight);

            if (light == null)
            {
                return;
            }

            if (Sun == null)
            {
                Sun = (MSceneObject)MScene.AstroRoot.FindModuleByName("Sol");
                if (Sun == null)
                {
                    return;
                }
            }

            Vector3d dir = Sun.transform.Position - e.Position;

            dir.Normalize();

            Vector3d TargetPos = e.Position + dir * 20;


            MMoveSync ms  = null;
            MObject   ms0 = light.FindModuleByType(MObject.EType.MoveSync);

            if (ms == null)
            {
                // ms = new MMoveSync(light, e.Position
                // + Globals.LocalUpVector * 5
                //+ Globals.LocalUpRotation() * new Vector3d(10, 10, 0), Quaterniond.Identity);
                ms       = new MMoveSync(light, TargetPos, Quaterniond.Identity);
                ms.Speed = 1;
                light.Add(ms);
            }
            else
            {
                ms = (MMoveSync)ms0;
                ms.SetTarget(TargetPos, Quaterniond.Identity);
            }


            /*
             * light.transform.Position = e.Position
             + Globals.LocalUpVector * 5
             + Globals.LocalUpRotation() * new Vector3d(10, 10, 0);
             */
            light.LookAt(e.Position);
            //light.DebugDepth = true;
        }
Example #3
0
        void MoveSelection(double x, double y, double z)
        {
            if (SelectedItem == null)
            {
                return;
            }
            double mult = MKeyboardHandler.GetMinifier();

            // complete any pending transitions
            MMoveSync ms = (MMoveSync)SelectedItem.FindModuleByType(MObject.EType.MoveSync);

            if (ms != null)
            {
                ms.Complete();
            }

            Vector3d v = SelectedItem.transform.Position
                         + SelectedItem.transform.Right() * x * mult
                         + SelectedItem.transform.Forward() * y * mult
                         + SelectedItem.transform.Up() * z * mult;

            MMessageBus.MoveRequest(this, SelectedItem.InstanceID, v, SelectedItem.transform.Rotation);
        }
Example #4
0
        void RotateSelection(double x, double y, double z)
        {
            if (SelectedItem == null)
            {
                return;
            }
            double mult = MKeyboardHandler.GetRotationMinifier();

            x = MathHelper.DegreesToRadians(x * mult);
            y = MathHelper.DegreesToRadians(y * mult);
            z = MathHelper.DegreesToRadians(z * mult);

            // complete any pending transitions
            MMoveSync ms = (MMoveSync)SelectedItem.FindModuleByType(MObject.EType.MoveSync);

            if (ms != null)
            {
                ms.Complete();
            }

            Quaterniond rot = SelectedItem.transform.Rotation * Quaterniond.FromEulerAngles(x, y, z);

            MMessageBus.MoveRequest(this, SelectedItem.InstanceID, SelectedItem.transform.Position, rot);
        }