OpenSim.Region.ScriptEngine.Shared.Api.LSL_Api.llSetCameraParams C# (CSharp) Method

llSetCameraParams() public method

public llSetCameraParams ( OpenSim.Region.ScriptEngine.Shared.LSL_Types.list rules ) : void
rules OpenSim.Region.ScriptEngine.Shared.LSL_Types.list
return void
        public void llSetCameraParams(LSL_List rules)
        {
            m_host.AddScriptLPS(1);

            // the object we are in
            UUID objectID = m_host.ParentUUID;
            if (objectID == UUID.Zero)
                return;

            // we need the permission first, to know which avatar we want to set the camera for
            UUID agentID = m_item.PermsGranter;

            if (agentID == UUID.Zero)
                return;

            if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
                return;

            ScenePresence presence = World.GetScenePresence(agentID);

            // we are not interested in child-agents
            if (presence.IsChildAgent) return;

            SortedDictionary<int, float> parameters = new SortedDictionary<int, float>();
            object[] data = rules.Data;
            for (int i = 0; i < data.Length; ++i)
            {
                int type;
                try
                {
                    type = Convert.ToInt32(data[i++].ToString());
                }
                catch
                {
                    Error("llSetCameraParams", string.Format("Invalid camera param type {0}", data[i - 1]));
                    return;
                }
                if (i >= data.Length) break; // odd number of entries => ignore the last

                // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3)
                switch (type)
                {
                case ScriptBaseClass.CAMERA_FOCUS:
                case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
                case ScriptBaseClass.CAMERA_POSITION:
                    LSL_Vector v = (LSL_Vector)data[i];
                    try
                    {
                        parameters.Add(type + 1, (float)v.x);
                    }
                    catch
                    {
                        switch(type)
                        {
                            case ScriptBaseClass.CAMERA_FOCUS:
                                Error("llSetCameraParams", "CAMERA_FOCUS: Parameter x is invalid");
                                return;
                            case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
                                Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter x is invalid");
                                return;
                            case ScriptBaseClass.CAMERA_POSITION:
                                Error("llSetCameraParams", "CAMERA_POSITION: Parameter x is invalid");
                                return;
                        }
                    }
                    try
                    {
                        parameters.Add(type + 2, (float)v.y);
                    }
                    catch
                    {
                        switch(type)
                        {
                            case ScriptBaseClass.CAMERA_FOCUS:
                                Error("llSetCameraParams", "CAMERA_FOCUS: Parameter y is invalid");
                                return;
                            case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
                                Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter y is invalid");
                                return;
                            case ScriptBaseClass.CAMERA_POSITION:
                                Error("llSetCameraParams", "CAMERA_POSITION: Parameter y is invalid");
                                return;
                        }
                    }
                    try
                    {
                        parameters.Add(type + 3, (float)v.z);
                    }
                    catch
                    {
                        switch(type)
                        {
                            case ScriptBaseClass.CAMERA_FOCUS:
                                Error("llSetCameraParams", "CAMERA_FOCUS: Parameter z is invalid");
                                return;
                            case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
                                Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter z is invalid");
                                return;
                            case ScriptBaseClass.CAMERA_POSITION:
                                Error("llSetCameraParams", "CAMERA_POSITION: Parameter z is invalid");
                                return;
                        }
                    }
                    break;
                default:
                    // TODO: clean that up as soon as the implicit casts are in
                    if (data[i] is LSL_Float)
                        parameters.Add(type, (float)((LSL_Float)data[i]).value);
                    else if (data[i] is LSL_Integer)
                        parameters.Add(type, (float)((LSL_Integer)data[i]).value);
                    else
                    {
                        try
                        {
                            parameters.Add(type, Convert.ToSingle(data[i]));
                        }
                        catch
                        {
                            Error("llSetCameraParams", string.Format("{0}: Parameter is invalid", type));
                        }
                    }
                    break;
                }
            }
            if (parameters.Count > 0) presence.ControllingClient.SendSetFollowCamProperties(objectID, parameters);
        }
LSL_Api