public EntityCamera(RegionContextBase rcontext, AssetContextBase acontext)
     : base(rcontext, acontext)
 {
     m_yawFixed = true;
     m_globalPosition = new OMV.Vector3d(40f, 40f, 30f);
     m_heading = new OMV.Quaternion(0f, 1f, 0f);
 }
        public LLRegionContext(RegionContextBase rcontext, AssetContextBase acontext,
                               LLTerrainInfo tinfo, OMV.Simulator sim)
            : base(rcontext, acontext)
        {
            m_terrainInfo = tinfo;

            // until we have a better protocol, we know the sims are a fixed size
            m_size = new OMV.Vector3(256f, 256f, 8000f);

            // believe it or not the world coordinates of a sim are hidden in the handle
            uint x, y;

            OMV.Utils.LongToUInts(sim.Handle, out x, out y);
            m_worldBase = new OMV.Vector3d((double)x, (double)y, 0d);

            m_simulator = sim;

            // this should be more general as "GRID/SIM"
            m_name = new EntityName(sim.Name);

            // a cache of requested localIDs so we don't ask too often
            m_recentLocalIDRequests = new Dictionary <uint, int>();

            this.RegisterInterface <LLRegionContext>(this);
        }
예제 #3
0
 public EntityCamera(RegionContextBase rcontext, AssetContextBase acontext)
     : base(rcontext, acontext)
 {
     m_yawFixed       = true;
     m_globalPosition = new OMV.Vector3d(40f, 40f, 30f);
     m_heading        = new OMV.Quaternion(0f, 1f, 0f);
 }
예제 #4
0
 public CameraControl()
 {
     m_heading        = new OMV.Quaternion(OMV.Vector3.UnitY, 0f);
     m_globalPosition = new OMV.Vector3d(0d, 20d, 30d); // World coordinates (Z up)
     m_zoom           = 1.0f;
     m_far            = 300.0f;
     m_yawFixed       = true;
 }
 public CameraControl()
 {
     m_heading = new OMV.Quaternion(OMV.Vector3.UnitY, 0f);
     m_globalPosition = new OMV.Vector3d(0d, 20d, 30d);   // World coordinates (Z up)
     m_zoom = 1.0f;
     m_far = 300.0f;
     m_yawFixed = true;
 }
예제 #6
0
        /// <summary>
        /// Update both position and heading with one call. Remember that the position
        /// is a global position.
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="heading"></param>
        public void Update(OMV.Vector3d pos, OMV.Quaternion heading)
        {
            bool changed = (m_heading != heading) | (m_globalPosition != pos);

            m_globalPosition = pos;
            m_heading        = heading;
            if (changed && (OnCameraUpdate != null))
            {
                OnCameraUpdate(this);
            }
        }
예제 #7
0
        private bool UI_MouseMoveLater(DoLaterBase qInstance, Object parms)
        {
            Object[] loadParams = (Object[])parms;
            int      param      = (int)loadParams[0];
            float    x          = (float)loadParams[1];
            float    y          = (float)loadParams[2];

            int sinceLastMouse = System.Environment.TickCount - m_lastMouseMoveTime;

            m_lastMouseMoveTime = System.Environment.TickCount;
            // m_log.Log(LogLevel.DVIEWDETAIL, "OnMouseMove: x={0}, y={1}, time since last={2}", x, y, sinceLastMouse);
            if (m_mainCamera != null)
            {
                if (((Renderer.UserInterface.LastKeyCode & Keys.Control) == 0) &&
                    ((Renderer.UserInterface.LastKeyCode & Keys.Alt) != 0))
                {
                    m_log.Log(LogLevel.DVIEWDETAIL, "OnMouseMove: ALT: ");
                }
                else if (((Renderer.UserInterface.LastKeyCode & Keys.Control) != 0) &&
                         ((Renderer.UserInterface.LastKeyCode & Keys.Alt) != 0))
                {
                    // if ALT+CNTL is held down, movement is on view plain
                    float        xMove    = x * m_cameraSpeed;
                    float        yMove    = y * m_cameraSpeed;
                    OMV.Vector3d movement = new OMV.Vector3d(0, xMove, yMove);
                    m_log.Log(LogLevel.DVIEWDETAIL, "OnMouseMove: CNTL-ALT: Move camera x={0}, y={1}", xMove, yMove);
                    m_mainCamera.GlobalPosition -= movement;
                }
                else if ((Renderer.UserInterface.LastKeyCode & Keys.Control) != 0)
                {
                    // if CNTL is held down, movement is on land plane
                    float xMove = x * m_cameraSpeed;
                    float yMove = y * m_cameraSpeed;
                    m_log.Log(LogLevel.DVIEWDETAIL, "OnMouseMove: CNTL: Move camera x={0}, y={1}", xMove, yMove);
                    OMV.Vector3d movement = new OMV.Vector3d(yMove, xMove, 0f);
                    m_mainCamera.GlobalPosition -= movement;
                }
                else if ((Renderer.UserInterface.LastMouseButtons & MouseButtons.Left) != 0)
                {
                    // move the camera around the horizontal (X) and vertical (Z) axis
                    float xMove = (-x * m_cameraRotationSpeed * Constants.DEGREETORADIAN) % Constants.TWOPI;
                    float yMove = (-y * m_cameraRotationSpeed * Constants.DEGREETORADIAN) % Constants.TWOPI;
                    // rotate around local axis
                    // m_log.Log(LogLevel.DVIEWDETAIL, "OnMouseMove: Rotate camera x={0}, y={1}, lmb={2}",
                    //         xMove, yMove, Renderer.UserInterface.LastMouseButtons);
                    m_mainCamera.rotate(yMove, 0f, xMove);
                }
            }
            return(true);
        }
예제 #8
0
        public void StayingStillWithoutYawFor3minutes(int delay)
        {
            //Avatar mobility model for Standing an avatar still in its spawn location for 3 minutes with yaw (no change in the lookat direction)
            //Yaw is the change in the look at direction which is also known as the gaze direction of the avatar
            int    time = 0;
            Random rnd  = new Random();

            Console.WriteLine("*** Standing still without Yaw *** ");
            Client.Self.Chat("*** Standing still without Yaw *** ", 0, ChatType.Normal);
            while (time <= delay)
            {
                OpenMetaverse.Vector3d mycurrentLookAt = Client.Self.LookAt;
                //Client.Self.Chat("*** My Current lookat vector: *** " + mycurrentLookAt, 0, ChatType.Normal);
                //just passing time but you can also use Client.Self.Stand() -> this send packets to server
                //better do it the way it is done here
                Thread.Sleep(1000);
                time += 1000;
            }
        }
예제 #9
0
        private void UpdateMainCameraToAgentTracking()
        {
            try {
                if (m_mainCamera != null && m_mainCamera.AssociatedAgent != null)
                {
                    IAgent agnt = m_mainCamera.AssociatedAgent;

                    /*
                     * // note: coordinates are in LL form: Z up
                     * OMV.Vector3 cameraOffset = new OMV.Vector3(-m_agentCameraBehind, 0, m_agentCameraAbove);
                     * OMV.Quaternion invertHeading = OMV.Quaternion.Inverse(agnt.Heading);
                     * // rotate the vector in the direction the agent is pointing
                     * OMV.Vector3 cameraBehind = cameraOffset * invertHeading;
                     * // create the global offset from the agent's position
                     * OMV.Vector3d globalOffset = new OMV.Vector3d(cameraBehind.X, cameraBehind.Y, cameraBehind.Z);
                     * m_log.Log(LogLevel.DVIEWDETAIL, "OnAgentUpdate: offset={0}, behind={1}, goffset={2}, gpos={3}",
                     *  cameraOffset.ToString(), cameraBehind.ToString(),
                     *  globalOffset.ToString(), agnt.GlobalPosition.ToString());
                     * m_mainCamera.Update(agnt.GlobalPosition + globalOffset, agnt.Heading);
                     */
                    // OMV.Vector3 cameraOffset = new OMV.Vector3(0, m_agentCameraBehind, m_agentCameraAbove);
                    OMV.Vector3 cameraOffset = new OMV.Vector3(m_agentCameraBehind, 0, m_agentCameraAbove);
                    // OMV.Vector3 rotatedOffset = Utilities.RotateVector(agnt.Heading, cameraOffset);
                    OMV.Vector3  rotatedOffset       = cameraOffset * OMV.Quaternion.Inverse(agnt.Heading);
                    OMV.Vector3d globalRotatedOffset = new OMV.Vector3d(-rotatedOffset.X, rotatedOffset.Y, rotatedOffset.Z);
                    // 'kludgeOffset' exists because the above calculation doesn't give the right camera position
                    // Don't know why, but this extra offset is needed
                    // Found out why... EntityBase was defaulting to 10,10,10 which moved the region base
                    // but still some funny offset is needed.
                    // OMV.Vector3d kludgeOffset = new OMV.Vector3d(10d, 10d, 0d);
                    OMV.Vector3d kludgeOffset          = new OMV.Vector3d(0d, 0d, -10d);
                    OMV.Vector3d desiredCameraPosition = agnt.GlobalPosition + globalRotatedOffset + kludgeOffset;

                    m_log.Log(LogLevel.DVIEWDETAIL, "UpdateMainCameraToAgentTracking: offset={0}, goffset={1}, cpos={2}, apos={3}",
                              cameraOffset, globalRotatedOffset, desiredCameraPosition, agnt.GlobalPosition);

                    m_mainCamera.Update(desiredCameraPosition, agnt.Heading);
                }
            }
            catch (Exception e) {
            }
        }
예제 #10
0
        override public bool AfterAllModulesLoaded()
        {
            m_log.Log(LogLevel.DINIT, "entered AfterAllModulesLoaded()");

            Renderer = (IRenderProvider)ModuleManager.Instance.Module(ModuleParams.ParamString(m_moduleName + ".Renderer.Name"));
            if (Renderer == null)
            {
                m_log.Log(LogLevel.DBADERROR, "UNABLE TO FIND RENDERER!!!! ");
                return(false);
            }

            m_cameraSpeed               = ModuleParams.ParamFloat(m_moduleName + ".Camera.Speed");
            m_cameraRotationSpeed       = ModuleParams.ParamFloat(m_moduleName + ".Camera.RotationSpeed");
            m_agentCameraBehind         = ModuleParams.ParamFloat(m_moduleName + ".Camera.BehindAgent");
            m_agentCameraAbove          = ModuleParams.ParamFloat(m_moduleName + ".Camera.AboveAgent");
            m_mainCamera                = new CameraControl();
            m_mainCamera.GlobalPosition = new OMV.Vector3d(1000d, 1000d, 40d); // World coordinates (Z up)
            // camera starts pointing down Y axis
            m_mainCamera.Heading = new OMV.Quaternion(OMV.Vector3.UnitZ, Constants.PI / 2);
            m_mainCamera.Zoom    = 1.0f;
            m_mainCamera.Far     = ModuleParams.ParamFloat(m_moduleName + ".Camera.ServerFar");
            m_cameraMode         = CameraMode.TrackingAgent;
            m_cameraLookAt       = new OMV.Vector3d(0d, 0d, 0d);

            // connect me to the world so I can know when things change in the world
            TheWorld.OnWorldRegionNew     += new WorldRegionNewCallback(World_OnRegionNew);
            TheWorld.OnWorldRegionUpdated += new WorldRegionUpdatedCallback(World_OnRegionUpdated);
            TheWorld.OnWorldRegionRemoved += new WorldRegionRemovedCallback(World_OnRegionRemoved);
            TheWorld.OnWorldEntityNew     += new WorldEntityNewCallback(World_OnEntityNew);
            TheWorld.OnWorldEntityUpdate  += new WorldEntityUpdateCallback(World_OnEntityUpdate);
            TheWorld.OnWorldEntityRemoved += new WorldEntityRemovedCallback(World_OnEntityRemoved);
            TheWorld.OnAgentNew           += new WorldAgentNewCallback(World_OnAgentNew);
            TheWorld.OnAgentUpdate        += new WorldAgentUpdateCallback(World_OnAgentUpdate);
            TheWorld.OnAgentRemoved       += new WorldAgentRemovedCallback(World_OnAgentRemoved);

            m_log.Log(LogLevel.DINIT, "exiting AfterAllModulesLoaded()");
            return(true);
        }
        public LLRegionContext(RegionContextBase rcontext, AssetContextBase acontext, 
                        LLTerrainInfo tinfo, OMV.Simulator sim)
            : base(rcontext, acontext)
        {
            m_terrainInfo = tinfo;

            // until we have a better protocol, we know the sims are a fixed size
            m_size = new OMV.Vector3(256f, 256f, 8000f);

            // believe it or not the world coordinates of a sim are hidden in the handle
            uint x, y;
            OMV.Utils.LongToUInts(sim.Handle, out x, out y);
            m_worldBase = new OMV.Vector3d((double)x, (double)y, 0d);

            m_simulator = sim;

            // this should be more general as "GRID/SIM"
            m_name = new EntityName(sim.Name);

            // a cache of requested localIDs so we don't ask too often
            m_recentLocalIDRequests = new Dictionary<uint, int>();

            this.RegisterInterface<LLRegionContext>(this);
        }
예제 #12
0
        // ==========================================================================
        /// <summary>
        /// Update the camera. The coordinate system from the EntityCamera is LL's
        /// (Z up). We have to convert the rotation and position to Ogre coords
        /// (Y up).
        /// </summary>
        /// <param name="cam"></param>
        // private bool haveAttachedCamera = false;
        public void UpdateCamera(CameraControl cam)
        {
            /* Historical Note: This is part of code to attach the camera to the avatar. When this was written
             * the avatar code was not in place so the actual scene node to attach the camera too is problematic.
             * Fix this when there is an avatar.
            if (!haveAttachedCamera && cam.AssociatedAgent != null && cam.AssociatedAgent.AssociatedAvatar != null) {
            m_log.Log(LogLevel.DVIEWDETAIL, "OnAgentUpdate: Attaching camera with {0}", cam.AssociatedAgent.AssociatedAvatar.Name);
            haveAttachedCamera = Ogr.AttachCamera(cam.AssociatedAgent.AssociatedAvatar.Name.Name, 1.0f, 0.0f, 1.0f, 0f, 0f, 0f, 1f);
            }
             */

            // OMV.Quaternion orient = new OMV.Quaternion(OMV.Vector3.UnitX, -Constants.PI / 2)
                    // * new OMV.Quaternion(OMV.Vector3.UnitZ, -Constants.PI / 2)
                    // * cam.Direction;
            // we need to rotate the camera 90 to make it work out in Ogre. Not sure why.
            // OMV.Quaternion orient = cam.Heading * OMV.Quaternion.CreateFromAxisAngle(OMV.Vector3.UnitZ, -Constants.PI / 2);
            OMV.Quaternion orient = OMV.Quaternion.CreateFromAxisAngle(OMV.Vector3.UnitZ, -Constants.PI / 2) * cam.Heading;
            // OMV.Quaternion orient = cam.Heading;
            orient.Normalize();
            m_lastCameraPosition = cam.GlobalPosition;
            m_lastCameraOrientation = orient;
            // note the conversion from LL coordinates (Z up) to Ogre coordinates (Y up)
            OMV.Vector3d pos = cam.GlobalPosition * m_sceneMagnification;
            Ogr.UpdateCameraBF(pos.X, pos.Z, -pos.Y,
            orient.W, orient.X, orient.Z, -orient.Y,
            1.0f, (float)cam.Far*m_sceneMagnification, 1.0f);

            // m_log.Log(LogLevel.DRENDERDETAIL, "UpdateCamera: Camera to p={0}, r={1}", pos, orient);
            return;
        }
예제 #13
0
        private void UpdateMainCameraToAgentTracking()
        {
            try {
            if (m_mainCamera != null && m_mainCamera.AssociatedAgent != null) {
                IAgent agnt = m_mainCamera.AssociatedAgent;
                /*
                // note: coordinates are in LL form: Z up
                OMV.Vector3 cameraOffset = new OMV.Vector3(-m_agentCameraBehind, 0, m_agentCameraAbove);
                OMV.Quaternion invertHeading = OMV.Quaternion.Inverse(agnt.Heading);
                // rotate the vector in the direction the agent is pointing
                OMV.Vector3 cameraBehind = cameraOffset * invertHeading;
                // create the global offset from the agent's position
                OMV.Vector3d globalOffset = new OMV.Vector3d(cameraBehind.X, cameraBehind.Y, cameraBehind.Z);
                m_log.Log(LogLevel.DVIEWDETAIL, "OnAgentUpdate: offset={0}, behind={1}, goffset={2}, gpos={3}",
                    cameraOffset.ToString(), cameraBehind.ToString(),
                    globalOffset.ToString(), agnt.GlobalPosition.ToString());
                m_mainCamera.Update(agnt.GlobalPosition + globalOffset, agnt.Heading);
                 */
                // OMV.Vector3 cameraOffset = new OMV.Vector3(0, m_agentCameraBehind, m_agentCameraAbove);
                OMV.Vector3 cameraOffset = new OMV.Vector3(m_agentCameraBehind, 0, m_agentCameraAbove);
                // OMV.Vector3 rotatedOffset = Utilities.RotateVector(agnt.Heading, cameraOffset);
                OMV.Vector3 rotatedOffset = cameraOffset * OMV.Quaternion.Inverse(agnt.Heading);
                OMV.Vector3d globalRotatedOffset = new OMV.Vector3d(-rotatedOffset.X, rotatedOffset.Y, rotatedOffset.Z);
                // 'kludgeOffset' exists because the above calculation doesn't give the right camera position
                // Don't know why, but this extra offset is needed
                // Found out why... EntityBase was defaulting to 10,10,10 which moved the region base
                // but still some funny offset is needed.
                // OMV.Vector3d kludgeOffset = new OMV.Vector3d(10d, 10d, 0d);
                OMV.Vector3d kludgeOffset = new OMV.Vector3d(0d, 0d, -10d);
                OMV.Vector3d desiredCameraPosition = agnt.GlobalPosition + globalRotatedOffset + kludgeOffset;

                m_log.Log(LogLevel.DVIEWDETAIL, "UpdateMainCameraToAgentTracking: offset={0}, goffset={1}, cpos={2}, apos={3}",
                    cameraOffset, globalRotatedOffset, desiredCameraPosition, agnt.GlobalPosition);

                m_mainCamera.Update(desiredCameraPosition, agnt.Heading);
            }
            }
            catch (Exception e) {
            }
        }
예제 #14
0
        private bool UI_MouseMoveLater(DoLaterBase qInstance, Object parms)
        {
            Object[] loadParams = (Object[])parms;
            int param = (int)loadParams[0];
            float x = (float)loadParams[1];
            float y = (float)loadParams[2];

            int sinceLastMouse = System.Environment.TickCount - m_lastMouseMoveTime;
            m_lastMouseMoveTime = System.Environment.TickCount;
            // m_log.Log(LogLevel.DVIEWDETAIL, "OnMouseMove: x={0}, y={1}, time since last={2}", x, y, sinceLastMouse);
            if (m_mainCamera != null) {
            if (((Renderer.UserInterface.LastKeyCode & Keys.Control) == 0)
                    && ((Renderer.UserInterface.LastKeyCode & Keys.Alt) != 0)) {
                m_log.Log(LogLevel.DVIEWDETAIL, "OnMouseMove: ALT: ");
            }
            else if ( ((Renderer.UserInterface.LastKeyCode & Keys.Control) != 0)
                    && ((Renderer.UserInterface.LastKeyCode & Keys.Alt) != 0) ) {
                // if ALT+CNTL is held down, movement is on view plain
                float xMove = x * m_cameraSpeed;
                float yMove = y * m_cameraSpeed;
                OMV.Vector3d movement = new OMV.Vector3d( 0, xMove, yMove);
                m_log.Log(LogLevel.DVIEWDETAIL, "OnMouseMove: CNTL-ALT: Move camera x={0}, y={1}", xMove, yMove);
                m_mainCamera.GlobalPosition -= movement;
            }
            else if ((Renderer.UserInterface.LastKeyCode & Keys.Control) != 0) {
                // if CNTL is held down, movement is on land plane
                float xMove = x * m_cameraSpeed;
                float yMove = y * m_cameraSpeed;
                m_log.Log(LogLevel.DVIEWDETAIL, "OnMouseMove: CNTL: Move camera x={0}, y={1}", xMove, yMove);
                OMV.Vector3d movement = new OMV.Vector3d( yMove, xMove, 0f);
                m_mainCamera.GlobalPosition -= movement;
            }
            else if ((Renderer.UserInterface.LastMouseButtons & MouseButtons.Left) != 0) {
                    // move the camera around the horizontal (X) and vertical (Z) axis
                    float xMove = (-x * m_cameraRotationSpeed * Constants.DEGREETORADIAN) % Constants.TWOPI;
                    float yMove = (-y * m_cameraRotationSpeed * Constants.DEGREETORADIAN) % Constants.TWOPI;
                    // rotate around local axis
                    // m_log.Log(LogLevel.DVIEWDETAIL, "OnMouseMove: Rotate camera x={0}, y={1}, lmb={2}",
                    //         xMove, yMove, Renderer.UserInterface.LastMouseButtons);
                    m_mainCamera.rotate(yMove, 0f, xMove);
            }
            }
            return true;
        }
예제 #15
0
        public override bool AfterAllModulesLoaded()
        {
            m_log.Log(LogLevel.DINIT, "entered AfterAllModulesLoaded()");

            Renderer = (IRenderProvider)ModuleManager.Instance.Module(ModuleParams.ParamString(m_moduleName + ".Renderer.Name"));
            if (Renderer == null) {
            m_log.Log(LogLevel.DBADERROR, "UNABLE TO FIND RENDERER!!!! ");
            return false;
            }

            m_cameraSpeed = ModuleParams.ParamFloat(m_moduleName + ".Camera.Speed");
            m_cameraRotationSpeed = ModuleParams.ParamFloat(m_moduleName + ".Camera.RotationSpeed");
            m_agentCameraBehind = ModuleParams.ParamFloat(m_moduleName + ".Camera.BehindAgent");
            m_agentCameraAbove = ModuleParams.ParamFloat(m_moduleName + ".Camera.AboveAgent");
            m_mainCamera = new CameraControl();
            m_mainCamera.GlobalPosition = new OMV.Vector3d(1000d, 1000d, 40d);   // World coordinates (Z up)
            // camera starts pointing down Y axis
            m_mainCamera.Heading = new OMV.Quaternion(OMV.Vector3.UnitZ, Constants.PI/2);
            m_mainCamera.Zoom = 1.0f;
            m_mainCamera.Far = ModuleParams.ParamFloat(m_moduleName + ".Camera.ServerFar");
            m_cameraMode = CameraMode.TrackingAgent;
            m_cameraLookAt = new OMV.Vector3d(0d, 0d, 0d);

            // connect me to the world so I can know when things change in the world
            TheWorld.OnWorldRegionNew += new WorldRegionNewCallback(World_OnRegionNew);
            TheWorld.OnWorldRegionUpdated += new WorldRegionUpdatedCallback(World_OnRegionUpdated);
            TheWorld.OnWorldRegionRemoved += new WorldRegionRemovedCallback(World_OnRegionRemoved);
            TheWorld.OnWorldEntityNew += new WorldEntityNewCallback(World_OnEntityNew);
            TheWorld.OnWorldEntityUpdate += new WorldEntityUpdateCallback(World_OnEntityUpdate);
            TheWorld.OnWorldEntityRemoved += new WorldEntityRemovedCallback(World_OnEntityRemoved);
            TheWorld.OnAgentNew += new WorldAgentNewCallback(World_OnAgentNew);
            TheWorld.OnAgentUpdate += new WorldAgentUpdateCallback(World_OnAgentUpdate);
            TheWorld.OnAgentRemoved += new WorldAgentRemovedCallback(World_OnAgentRemoved);

            m_log.Log(LogLevel.DINIT, "exiting AfterAllModulesLoaded()");
            return true;
        }
예제 #16
0
 public Vector3(OMV_Vector3d vector)
 {
     x = vector.X;
     y = vector.Y;
     z = vector.Z;
 }
 /// <summary>
 /// Update both position and heading with one call. Remember that the position
 /// is a global position.
 /// </summary>
 /// <param name="pos"></param>
 /// <param name="heading"></param>
 public void Update(OMV.Vector3d pos, OMV.Quaternion heading)
 {
     bool changed = (m_heading != heading) | (m_globalPosition != pos);
     m_globalPosition = pos;
     m_heading = heading;
     if (changed && (OnCameraUpdate != null)) OnCameraUpdate(this);
 }