예제 #1
0
    private void getScreenPos(ScriptEventData gotScreenPos)
    {
        Log.Write("SCREEN EVENT RECIEVED");
        Log.Write("In getScreenPos");
        if (gotScreenPos.Data == null)
        {
            return;
        }
        SendScreenPos sendScreenPos = gotScreenPos.Data.AsInterface <SendScreenPos>();

        if (sendScreenPos == null)
        {
            Log.Write(LogLevel.Error, Script.ID.ToString(), "Unable to create interface, check logs for missing member(s)");
            return;
        }
        XScreenPos = float.Parse(sendScreenPos.SetScreenPos[0]);
        Log.Write("XScreenPos: " + XScreenPos);
        YScreenPos = float.Parse(sendScreenPos.SetScreenPos[1]);
        ZScreenPos = float.Parse(sendScreenPos.SetScreenPos[2]);
        XScreenRot = float.Parse(sendScreenPos.SetScreenPos[3]);
        YScreenRot = float.Parse(sendScreenPos.SetScreenPos[4]);
        ZScreenRot = float.Parse(sendScreenPos.SetScreenPos[5]);
        ScreenPos  = new Vector(XScreenPos, YScreenPos, ZScreenPos);
        Vector ScreenRot = new Vector(XScreenRot * pi / 180, YScreenRot * pi / 180, ZScreenRot * pi / 180);

        ScreenQuat = Quaternion.FromEulerAngles(ScreenRot).Normalized();
        CurQuat    = RigidBody.GetOrientation();
        CurPos     = RigidBody.GetPosition();
        SlideMass  = RigidBody.GetMass();
    }
예제 #2
0
        void Move()
        {
            if (MoveDuration < timestep)
            {
                RigidBody.SetOrientation(movedRotation, (e) =>
                {
                    SetPositionOfCOM(movedPosition);
                });
                state = State.Moved;
                return;
            }
            state = State.Moving;
            Vector     fromPosition = GetPositionOfCOM();
            Quaternion fromRotation = RigidBody.GetOrientation();

            float fromAngle = GetAngleFromZero(fromRotation) + turnDirection * turnCount * TwoPI;
            float toAngle   = GetAngleFromZero(movedRotation) + turnDirection * numTurns * TwoPI;

            bool translateDone      = false;
            bool rotateDone         = false;
            bool rotateWillComplete = false;

            if (__SimpleDebugging)
            {
                Log.Write("Open, " + Mathf.DegreesPerRadian * fromAngle + " -> " + Mathf.DegreesPerRadian * toAngle + " axis " + worldRotationAxis + " speed " + rotateSpeed);
            }

            SendToAll(MoveBegan, thisObjectData);

            while (state == State.Moving)
            {
                if (!translateDone)
                {
                    ApplyTranslation(fromPosition, movedPosition, translateSpeed, ref translateDone);
                }
                if (!rotateDone)
                {
                    ApplyRotation(fromAngle, toAngle, movedRotation, rotateSpeed, ref rotateDone, ref rotateWillComplete);
                }

                if (translateDone && rotateDone)
                {
                    RigidBody.SetOrientation(movedRotation, (e) =>
                    {
                        SetPositionOfCOM(movedPosition);
                    });
                    state = State.Moved;
                    break;
                }
                Wait(TimeSpan.FromSeconds(timestep));
            }
        }
예제 #3
0
    // Override Init to set up event handlers and start coroutines.
    public override void Init()
    {
        // Sensible default setting values
        if (OpenAngleDegrees == 0)
        {
            OpenAngleDegrees = 90;
        }
        if (Channel == 0)
        {
            Channel = 1000;
        }
        if (SecondsToOpen == 0)
        {
            SecondsToOpen = 1;
        }
        if (SecondsBeforeClose == 0)
        {
            SecondsBeforeClose = 5;
        }

        // Parse the pipe-delimited sensor names into a clean list
        if (SensorNames != null)
        {
            foreach (string Name in SensorNames.Split(','))
            {
                if (Name.Trim() == "")
                {
                    continue;
                }
                SensorNameList.Add(Name.Trim());
            }
        }

        // Find the door we'll manipulate.
        if (DoorBody == null)
        {
            ObjectPrivate.TryGetFirstComponent(out DoorBody);
        }

        // Compute some basics
        OpenAngle         = OpenAngleDegrees / Mathf.DegreesPerRadian;
        ClosedOrientation = DoorBody.GetOrientation();
        HingeOffset       = new Vector(HingeOffsetX, HingeOffsetY, 0, 0).Rotate(ref ClosedOrientation);
        ClosedPosition    = DoorBody.GetPosition() + HingeOffset;

        // Only subscribe to collision events if the experience creator requested it
        if (OpenOnCollision)
        {
            DoorBody.Subscribe(CollisionEventType.CharacterContact, Collide);
        }

        // Only listen for chat if the experience creator wants outside sensors to trip this
        if (SensorNames != null)
        {
            ScenePrivate.Chat.Subscribe(Channel, null, ChatMessage);
        }

        // Start a continuous loop updating the door's position and orientation
        StartCoroutine(UpdateLoop);
    }
예제 #4
0
 public override void Init()
 {
     if (RigidBody == null)
     {
         if (!ObjectPrivate.TryGetFirstComponent(out RigidBody))
         {
             return;
         }
     }
     lightPositionOffset = new Sansar.Vector(0, 0, 2);
     startRot            = RigidBody.GetOrientation();
     //we want this to float
     RigidBody.SetMass(0);
     //the default light when you add it is off by -90 degrees
     lightOnObjectDirection = Quaternion.FromEulerAngles(new Sansar.Vector(0, 0, (float)(Math.PI / -2.0), 0));
     StartCoroutine(UpdateLoop);
 }
    public override void Init()
    {
        Script.UnhandledException += UnhandledException; // Catch errors and keep running unless fatal

        if (RigidBody == null)
        {
            if (!ObjectPrivate.TryGetFirstComponent(out RigidBody))
            {
                // Since object scripts are initialized when the scene loads, no one will actually see this message.
                ScenePrivate.Chat.MessageAllUsers("There is no RigidBodyComponent attached to this object.");
                return;
            }
        }

        CurPos = RigidBody.GetPosition();
        Log.Write("CurPos: " + CurPos);
        ZRotation = RigidBody.GetOrientation().GetEulerAngles().Z * 57.2958;
        Log.Write("Zrotation: " + ZRotation);

        int cntr = 0;

        if (ControlSurface1.Length > 0)
        {
            LoadControlSurfaces(ControlSurface1, cntr);
            cntr++;
        }
        if (ControlSurface2.Length > 0)
        {
            LoadControlSurfaces(ControlSurface2, cntr);
            cntr++;
        }
        if (ControlSurface3.Length > 0)
        {
            LoadControlSurfaces(ControlSurface3, cntr);
            cntr++;
        }
        if (ControlSurface4.Length > 0)
        {
            LoadControlSurfaces(ControlSurface4, cntr);
            cntr++;
        }
        if (ControlSurface5.Length > 0)
        {
            LoadControlSurfaces(ControlSurface5, cntr);
            cntr++;
        }
        if (ControlSurface6.Length > 0)
        {
            LoadControlSurfaces(ControlSurface6, cntr);
            cntr++;
        }
        if (ControlSurface7.Length > 0)
        {
            LoadControlSurfaces(ControlSurface7, cntr);
            cntr++;
        }
        if (ControlSurface8.Length > 0)
        {
            LoadControlSurfaces(ControlSurface8, cntr);
            cntr++;
        }
        if (ControlSurface9.Length > 0)
        {
            LoadControlSurfaces(ControlSurface9, cntr);
            cntr++;
        }
        if (ControlSurface10.Length > 0)
        {
            LoadControlSurfaces(ControlSurface10, cntr);
            cntr++;
        }
        if (ControlSurface11.Length > 0)
        {
            LoadControlSurfaces(ControlSurface11, cntr);
            cntr++;
        }
        if (ControlSurface12.Length > 0)
        {
            LoadControlSurfaces(ControlSurface12, cntr);
            cntr++;
        }
        if (ControlSurface13.Length > 0)
        {
            LoadControlSurfaces(ControlSurface13, cntr);
            cntr++;
        }
        if (ControlSurface14.Length > 0)
        {
            LoadControlSurfaces(ControlSurface14, cntr);
            cntr++;
        }
        if (ControlSurface15.Length > 0)
        {
            LoadControlSurfaces(ControlSurface15, cntr);
            cntr++;
        }
        if (ControlSurface16.Length > 0)
        {
            LoadControlSurfaces(ControlSurface16, cntr);
            cntr++;
        }
        if (ControlSurface17.Length > 0)
        {
            LoadControlSurfaces(ControlSurface17, cntr);
            cntr++;
        }
        if (ControlSurface18.Length > 0)
        {
            LoadControlSurfaces(ControlSurface18, cntr);
            cntr++;
        }
        if (ControlSurface19.Length > 0)
        {
            LoadControlSurfaces(ControlSurface19, cntr);
            cntr++;
        }
        if (ControlSurface20.Length > 0)
        {
            LoadControlSurfaces(ControlSurface20, cntr);
            cntr++;
        }
        if (ControlSurface21.Length > 0)
        {
            LoadControlSurfaces(ControlSurface21, cntr);
            cntr++;
        }
        if (ControlSurface22.Length > 0)
        {
            LoadControlSurfaces(ControlSurface22, cntr);
            cntr++;
        }
        if (ControlSurface23.Length > 0)
        {
            LoadControlSurfaces(ControlSurface23, cntr);
            cntr++;
        }
        if (ControlSurface24.Length > 0)
        {
            LoadControlSurfaces(ControlSurface24, cntr);
            cntr++;
        }
        if (ControlSurface25.Length > 0)
        {
            LoadControlSurfaces(ControlSurface25, cntr);
            cntr++;
        }
        if (ControlSurface26.Length > 0)
        {
            LoadControlSurfaces(ControlSurface26, cntr);
            cntr++;
        }
        if (ControlSurface27.Length > 0)
        {
            LoadControlSurfaces(ControlSurface27, cntr);
            cntr++;
        }
        if (ControlSurface28.Length > 0)
        {
            LoadControlSurfaces(ControlSurface28, cntr);
            cntr++;
        }
        if (ControlSurface29.Length > 0)
        {
            LoadControlSurfaces(ControlSurface29, cntr);
            cntr++;
        }
        if (ControlSurface30.Length > 0)
        {
            LoadControlSurfaces(ControlSurface30, cntr);
            cntr++;
        }
        NumOfControlSurfaces = cntr;
        ComplexInteractionHandler();
    }
    private void InitializeComplexInteraction(ScriptEventData data)
    {
        CurPos = RigidBody.GetPosition();
        Log.Write("CurPos: " + CurPos);
        ZRotation = RigidBody.GetOrientation().GetEulerAngles().Z * 57.2958;
        Log.Write("Zrotation: " + ZRotation);

        int cntr = 0;

        if (ControlSurface1.Length > 0)
        {
            LoadControlSurfaces(ControlSurface1, cntr);
            cntr++;
        }
        if (ControlSurface2.Length > 0)
        {
            LoadControlSurfaces(ControlSurface2, cntr);
            cntr++;
        }
        if (ControlSurface3.Length > 0)
        {
            LoadControlSurfaces(ControlSurface3, cntr);
            cntr++;
        }
        if (ControlSurface4.Length > 0)
        {
            LoadControlSurfaces(ControlSurface4, cntr);
            cntr++;
        }
        if (ControlSurface5.Length > 0)
        {
            LoadControlSurfaces(ControlSurface5, cntr);
            cntr++;
        }
        if (ControlSurface6.Length > 0)
        {
            LoadControlSurfaces(ControlSurface6, cntr);
            cntr++;
        }
        if (ControlSurface7.Length > 0)
        {
            LoadControlSurfaces(ControlSurface7, cntr);
            cntr++;
        }
        if (ControlSurface8.Length > 0)
        {
            LoadControlSurfaces(ControlSurface8, cntr);
            cntr++;
        }
        if (ControlSurface9.Length > 0)
        {
            LoadControlSurfaces(ControlSurface9, cntr);
            cntr++;
        }
        if (ControlSurface10.Length > 0)
        {
            LoadControlSurfaces(ControlSurface10, cntr);
            cntr++;
        }
        if (ControlSurface11.Length > 0)
        {
            LoadControlSurfaces(ControlSurface11, cntr);
            cntr++;
        }
        if (ControlSurface12.Length > 0)
        {
            LoadControlSurfaces(ControlSurface12, cntr);
            cntr++;
        }
        if (ControlSurface13.Length > 0)
        {
            LoadControlSurfaces(ControlSurface13, cntr);
            cntr++;
        }
        if (ControlSurface14.Length > 0)
        {
            LoadControlSurfaces(ControlSurface14, cntr);
            cntr++;
        }
        if (ControlSurface15.Length > 0)
        {
            LoadControlSurfaces(ControlSurface15, cntr);
            cntr++;
        }
        if (ControlSurface16.Length > 0)
        {
            LoadControlSurfaces(ControlSurface16, cntr);
            cntr++;
        }
        if (ControlSurface17.Length > 0)
        {
            LoadControlSurfaces(ControlSurface17, cntr);
            cntr++;
        }
        NumOfControlSurfaces = cntr;
        ComplexInteractionHandler();
    }