Base class for all scene objects
Inheritance: IComparable, IDisposable
示例#1
0
        void Objects_TerseObjectUpdate(object sender, TerseObjectUpdateEventArgs e)
        {
            if (e.Simulator.Handle != Client.Network.CurrentSim.Handle) return;
            if (e.Prim.ID == Client.Self.AgentID)
            {
                trackedObject = myself;
            }

            //If it is an avatar, we don't need to deal with the terse update stuff, unless it sends textures to us
            if (e.Prim.PrimData.PCode == PCode.Avatar && e.Update.Textures == null)
                return;

            UpdatePrimBlocking(e.Prim);
        }
示例#2
0
        private void glControl_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                dragging = true;
                downX = dragX = e.X;
                downY = dragY = e.Y;

                if (ModifierKeys == Keys.None)
                {
                    object picked;
                    int LeftclickedFaceID;
                    if (TryPick(e.X, e.Y, out picked, out LeftclickedFaceID))
                    {
                        if (picked is RenderPrimitive)
                        {
                            TryTouchObject((RenderPrimitive)picked);
                        }
                    }
                }
                else if (ModifierKeys == Keys.Alt)
                {
                    object picked;
                    int LeftclickedFaceID;
                    Vector3 worldPosition;
                    if (TryPick(e.X, e.Y, out picked, out LeftclickedFaceID, out worldPosition))
                    {
                        trackedObject = null;
                        Camera.FocalPoint = worldPosition;
                        Point screenCenter = new Point(glControl.Width / 2, glControl.Height / 2);
                        Cursor.Position = glControl.PointToScreen(screenCenter);
                        downX = dragX = screenCenter.X;
                        downY = dragY = screenCenter.Y;
                        Cursor.Hide();
                    }
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                object picked;
                RightclickedObject = null;
                if (TryPick(e.X, e.Y, out picked, out RightclickedFaceID))
                {
                    if (picked is SceneObject)
                    {
                        RightclickedObject = (SceneObject)picked;
                    }
                }
                ctxMenu.Show(glControl, e.X, e.Y);
            }
        }
示例#3
0
        void RenderBoundingBox(SceneObject prim)
        {
            Vector3 scale = prim.BasePrim.Scale;

            GL.PushMatrix();
            GL.MultMatrix(Math3D.CreateSRTMatrix(scale, prim.RenderRotation, prim.RenderPosition));

            if (RenderSettings.UseVBO && !occludedVBOFailed)
            {
                GL.DrawElements(BeginMode.Quads, RHelp.CubeIndices.Length, DrawElementsType.UnsignedShort, IntPtr.Zero);
            }
            else
            {
                GL.VertexPointer(3, VertexPointerType.Float, 0, RHelp.CubeVertices);
                GL.DrawElements(BeginMode.Quads, RHelp.CubeIndices.Length, DrawElementsType.UnsignedShort, RHelp.CubeIndices);
            }
            GL.PopMatrix();
        }
示例#4
0
        void CheckKeyboard(float time)
        {
            if (ModifierKeys == Keys.None)
            {
                // Movement forwards and backwards and body rotation
                Client.Self.Movement.AtPos = Instance.Keyboard.IsKeyDown(Keys.Up);
                Client.Self.Movement.AtNeg = Instance.Keyboard.IsKeyDown(Keys.Down);
                Client.Self.Movement.TurnLeft = Instance.Keyboard.IsKeyDown(Keys.Left);
                Client.Self.Movement.TurnRight = Instance.Keyboard.IsKeyDown(Keys.Right);

                if (Client.Self.Movement.Fly)
                {
                    //Find whether we are going up or down
                    Client.Self.Movement.UpPos = Instance.Keyboard.IsKeyDown(Keys.PageUp);
                    Client.Self.Movement.UpNeg = Instance.Keyboard.IsKeyDown(Keys.PageDown);
                    //The nudge positions are required to land (at least Neg is, unclear whether we should send Pos)
                    Client.Self.Movement.NudgeUpPos = Client.Self.Movement.UpPos;
                    Client.Self.Movement.NudgeUpNeg = Client.Self.Movement.UpNeg;
                    if (Client.Self.Velocity.Z > 0 && Client.Self.Movement.UpNeg)//HACK: Sometimes, stop fly fails
                        Client.Self.Fly(false);//We've hit something, stop flying
                }
                else
                {
                    //Don't send the nudge pos flags, we don't need them
                    Client.Self.Movement.NudgeUpPos = false;
                    Client.Self.Movement.NudgeUpNeg = false;
                    Client.Self.Movement.UpPos = Instance.Keyboard.IsKeyDown(Keys.PageUp);
                    Client.Self.Movement.UpNeg = Instance.Keyboard.IsKeyDown(Keys.PageDown);
                }
                if (Instance.Keyboard.IsKeyDown(Keys.Home))//Flip fly settings
                {
                    //Holding the home key only makes it change once, 
                    // not flip over and over, so keep track of it
                    if (!isHoldingHome)
                    {
                        Client.Self.Movement.Fly = !Client.Self.Movement.Fly;
                        isHoldingHome = true;
                    }
                }
                else
                    isHoldingHome = false;

                if (!Client.Self.Movement.Fly &&
                    Instance.Keyboard.IsKeyDown(Keys.PageUp))
                {
                    upKeyHeld += time;
                    if (upKeyHeld > upKeyHeldBeforeFly)//Wait for a bit before we fly, they may be trying to jump
                        Client.Self.Movement.Fly = true;
                }
                else
                    upKeyHeld = 0;//Reset the count


                if (Client.Self.Movement.TurnLeft)
                {
                    Client.Self.Movement.BodyRotation = Client.Self.Movement.BodyRotation * Quaternion.CreateFromAxisAngle(Vector3.UnitZ, time);
                }
                else if (client.Self.Movement.TurnRight)
                {
                    Client.Self.Movement.BodyRotation = Client.Self.Movement.BodyRotation * Quaternion.CreateFromAxisAngle(Vector3.UnitZ, -time);
                }

                if (Instance.Keyboard.IsKeyDown(Keys.Escape))
                {
                    InitCamera();
                    Camera.Manual = false;
                    trackedObject = myself;
                }
            }
            else if (ModifierKeys == Keys.Shift)
            {
                // Strafe
                Client.Self.Movement.LeftNeg = Instance.Keyboard.IsKeyDown(Keys.Right);
                Client.Self.Movement.LeftPos = Instance.Keyboard.IsKeyDown(Keys.Left);
            }
            else if (ModifierKeys == Keys.Alt)
            {
                // Camera horizontal rotation
                if (Instance.Keyboard.IsKeyDown(Keys.Left))
                {
                    Camera.Rotate(-time, true);
                }
                else if (Instance.Keyboard.IsKeyDown(Keys.Right))
                {
                    Camera.Rotate(time, true);
                } // Camera vertical rotation
                else if (Instance.Keyboard.IsKeyDown(Keys.PageDown))
                {
                    Camera.Rotate(-time, false);
                }
                else if (Instance.Keyboard.IsKeyDown(Keys.PageUp))
                {
                    Camera.Rotate(time, false);
                } // Camera zoom
                else if (Instance.Keyboard.IsKeyDown(Keys.Down))
                {
                    Camera.MoveToTarget(time);
                }
                else if (Instance.Keyboard.IsKeyDown(Keys.Up))
                {
                    Camera.MoveToTarget(-time);
                }
            }
            else if (ModifierKeys == (Keys.Alt | Keys.Control))
            {
                // Camera horizontal rotation
                if (Instance.Keyboard.IsKeyDown(Keys.Left))
                {
                    Camera.Rotate(-time, true);
                }
                else if (Instance.Keyboard.IsKeyDown(Keys.Right))
                {
                    Camera.Rotate(time, true);
                } // Camera vertical rotation
                else if (Instance.Keyboard.IsKeyDown(Keys.Down))
                {
                    Camera.Rotate(-time, false);
                }
                else if (Instance.Keyboard.IsKeyDown(Keys.Up))
                {
                    Camera.Rotate(time, false);
                }
            }
            else if (ModifierKeys == Keys.Control)
            {
                // Camera pan
                float timeFactor = 3f;

                if (Instance.Keyboard.IsKeyDown(Keys.Left))
                {
                    Camera.Pan(time * timeFactor, 0f);
                }
                else if (Instance.Keyboard.IsKeyDown(Keys.Right))
                {
                    Camera.Pan(-time * timeFactor, 0f);
                }
                else if (Instance.Keyboard.IsKeyDown(Keys.Up))
                {
                    Camera.Pan(0f, time * timeFactor);
                }
                else if (Instance.Keyboard.IsKeyDown(Keys.Down))
                {
                    Camera.Pan(0f, -time * timeFactor);
                }
            }
        }
示例#5
0
        /// <summary>
        /// Finds the closest distance between the given pos and an object
        /// (Assumes that the object is a box slightly)
        /// </summary>
        /// <param name="vector3"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        private float FindClosestDistanceSquared(Vector3 calcPos, SceneObject p)
        {
            if (p.BoundingVolume == null
                || !RenderSettings.HeavierDistanceChecking
                || p.BoundingVolume.ScaledR < 10f
                )
                return Vector3.DistanceSquared(calcPos, p.RenderPosition);

            Vector3 posToCheckFrom = Vector3.Zero;
            //Get the bounding boxes for this prim
            Vector3 boundingBoxMin = p.RenderPosition + p.BoundingVolume.ScaledMin;
            Vector3 boundingBoxMax = p.RenderPosition + p.BoundingVolume.ScaledMax;
            posToCheckFrom.X = (calcPos.X < boundingBoxMin.X) ? boundingBoxMin.X : (calcPos.X > boundingBoxMax.X) ? boundingBoxMax.X : calcPos.X;
            posToCheckFrom.Y = (calcPos.Y < boundingBoxMin.Y) ? boundingBoxMin.Y : (calcPos.Y > boundingBoxMax.Y) ? boundingBoxMax.Y : calcPos.Y;
            posToCheckFrom.Z = (calcPos.Z < boundingBoxMin.Z) ? boundingBoxMin.Z : (calcPos.Z > boundingBoxMax.Z) ? boundingBoxMax.Z : calcPos.Z;
            return Vector3.DistanceSquared(calcPos, posToCheckFrom);
        }
示例#6
0
        /// <summary>
        /// Calculates finar rendering position for objects on the scene
        /// </summary>
        /// <param name="obj">SceneObject whose position is calculated</param>
        /// <param name="pos">Rendering position</param>
        /// <param name="rot">Rendering rotation</param>
        void PrimPosAndRot(SceneObject obj, out Vector3 pos, out Quaternion rot)
        {
            // Sanity check
            if (obj == null)
            {
                pos = RHelp.InvalidPosition;
                rot = Quaternion.Identity;
                return;
            }

            if (obj.BasePrim.ParentID == 0)
            {
                // We are the root prim, return our interpolated position
                pos = obj.InterpolatedPosition;
                rot = obj.InterpolatedRotation;
                return;
            }
            else
            {
                pos = RHelp.InvalidPosition;
                rot = Quaternion.Identity;

                // Not root, find our parent
                SceneObject p = GetSceneObject(obj.BasePrim.ParentID);
                if (p == null) return;

                // If we don't know parent position, recursively find out
                if (!p.PositionCalculated)
                {
                    PrimPosAndRot(p, out p.RenderPosition, out p.RenderRotation);
                    p.DistanceSquared = Vector3.DistanceSquared(Camera.RenderPosition, p.RenderPosition);
                    p.PositionCalculated = true;
                }

                Vector3 parentPos = p.RenderPosition;
                Quaternion parentRot = p.RenderRotation;

                if (p is RenderPrimitive)
                {
                    // Child prim (our parent is another prim here)
                    pos = parentPos + obj.InterpolatedPosition * parentRot;
                    rot = parentRot * obj.InterpolatedRotation;
                }
                else if (p is RenderAvatar)
                {
                    // Calculating position and rotation of the root prim of an attachment here
                    // (our parent is an avatar here)
                    RenderAvatar parentav = (RenderAvatar)p;

                    // Check for invalid attachment point
                    int attachment_index = (int)obj.BasePrim.PrimData.AttachmentPoint;
                    if (attachment_index >= GLAvatar.attachment_points.Count()) return;
                    attachment_point apoint = GLAvatar.attachment_points[attachment_index];
                    skeleton skel = parentav.glavatar.skel;
                    if (!skel.mBones.ContainsKey(apoint.joint)) return;

                    // Bone position and rotation
                    Bone bone = skel.mBones[apoint.joint];
                    Vector3 bpos = bone.getTotalOffset();
                    Quaternion brot = bone.getTotalRotation();

                    // Start with avatar positon
                    pos = parentPos;
                    rot = parentRot;

                    // Move by pelvis offset
                    pos -= parentav.glavatar.skel.getOffset("mPelvis") * rot;
                    //rot = parentav.glavatar.skel.getRotation("mPelvis") * rot;

                    // Translate and rotate to the joint calculated position
                    pos += bpos * rot;
                    rot *= brot;

                    // Translate and rotate built in joint offset
                    pos += apoint.position * rot;
                    rot *= apoint.rotation;

                    // Translate and rotate from the offset from the attachment point
                    // set in teh appearance editor
                    pos += obj.BasePrim.Position * rot;
                    rot *= obj.BasePrim.Rotation;

                }
                return;
            }
        }
示例#7
0
 private void glControl_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         dragging = true;
         downX = dragX = e.X;
         downY = dragY = e.Y;
     }
     else if (e.Button == MouseButtons.Right)
     {
         object picked;
         RightclickedObject = null;
         if (TryPick(e.X, e.Y, out picked, out RightclickedFaceID))
         {
             if (picked is SceneObject)
             {
                 RightclickedObject = (SceneObject)picked;
             }
         }
         ctxMenu.Show(glControl, e.X, e.Y);
     }
 }