コード例 #1
0
 private void OnRotate(MatrixRotationInfo info)
 {
     if (info.IsEnding || info.IsObjectBeingRegistered)
     {
         RotationOffset = info.RotationOffsetFromInitial;
         Logger.LogTraceFormat("{0} layer redrawing with offset {1}", Category.Matrix, info.MatrixMove, RotationOffset);
         tilemap.RefreshAllTiles();
     }
 }
コード例 #2
0
 private void OnRotationEnd(RotationOffset fromCurrent, bool isInitialRotation)
 {
     //ignore the initial rotation message because we determine initial rotation from the
     //currentBodyDirection syncvar in playerSprites
     if (!isInitialRotation)
     {
         LocalFaceDirection(destinationOrientation);
         isMatrixRotating = false;
     }
 }
コード例 #3
0
        private void Update(EvaluationContext context)
        {
            Reference.DirtyFlag.Clear();
            LastObjectToWorld = context.ObjectToWorld;

            var fov         = MathUtil.DegreesToRadians(Fov.GetValue(context));
            var aspectRatio = AspectRatio.GetValue(context);

            if (aspectRatio < 0.0001f)
            {
                aspectRatio = (float)context.RequestedResolution.Width / context.RequestedResolution.Height;
            }
            System.Numerics.Vector2 clip = NearFarClip.GetValue(context);
            CameraToClipSpace = Matrix.PerspectiveFovRH(fov, aspectRatio, clip.X, clip.Y);

            var positionValue     = Position.GetValue(context);
            var eye               = new Vector3(positionValue.X, positionValue.Y, positionValue.Z);
            var targetValue       = Target.GetValue(context);
            var target            = new Vector3(targetValue.X, targetValue.Y, targetValue.Z);
            var upValue           = Up.GetValue(context);
            var up                = new Vector3(upValue.X, upValue.Y, upValue.Z);
            var worldToCameraRoot = Matrix.LookAtRH(eye, target, up);

            var rollRotation = Matrix.RotationAxis(new Vector3(0, 0, 1), -(float)Roll.GetValue(context));

            var pOffset = PositionOffset.GetValue(context);
            var additionalTranslation = Matrix.Translation(pOffset.X, pOffset.Y, pOffset.Z);

            var rOffset            = RotationOffset.GetValue(context);
            var additionalRotation = Matrix.RotationYawPitchRoll(MathUtil.DegreesToRadians(rOffset.Y),
                                                                 MathUtil.DegreesToRadians(rOffset.X),
                                                                 MathUtil.DegreesToRadians(rOffset.Z));

            WorldToCamera = worldToCameraRoot * rollRotation * additionalTranslation * additionalRotation;


            if (context.BypassCameras)
            {
                Command.GetValue(context);
                Log.Debug($"Bypassing {SymbolChildId}", SymbolChildId);
                return;
            }

            // Set properties and evaluate sub tree
            var prevWorldToCamera     = context.WorldToCamera;
            var prevCameraToClipSpace = context.CameraToClipSpace;

            context.WorldToCamera     = WorldToCamera;
            context.CameraToClipSpace = CameraToClipSpace;

            Command.GetValue(context);

            context.CameraToClipSpace = prevCameraToClipSpace;
            context.WorldToCamera     = prevWorldToCamera;
        }
コード例 #4
0
        /// <summary>
        /// Adds rotation offset to a body part. Rotation offsets add to the targets in VRIK
        /// </summary>
        public void AddRotationOffset(RotationOffset rotationOffset, Quaternion value)
        {
            switch (rotationOffset)
            {
            case RotationOffset.Pelvis: spine.pelvisRotationOffset = value * spine.pelvisRotationOffset; return;

            case RotationOffset.Chest: spine.chestRotationOffset = value * spine.chestRotationOffset; return;

            case RotationOffset.Head: spine.headRotationOffset = value * spine.headRotationOffset; return;
            }
        }
コード例 #5
0
 public void InitFromMatrix()
 {
     RotationOffset = RotationOffset.Same;
     matrixMove     = transform.root.GetComponent <MatrixMove>();
     if (matrixMove != null)
     {
         Logger.LogTraceFormat("{0} layer initializing from matrix", Category.Matrix, matrixMove);
         matrixMove.MatrixMoveEvents.OnRotate.AddListener(OnRotate);
         //initialize from current rotation
         OnRotate(MatrixRotationInfo.FromInitialRotation(matrixMove, NetworkSide.Client, RotationEvent.Register));
     }
 }
コード例 #6
0
    protected override void OnRotationEnd(RotationOffset fromCurrent, bool isInitialRotation)
    {
        base.OnRotationEnd(fromCurrent, isInitialRotation);

        //add additional rotation to remain sideways if we are down
        if (isDown)
        {
            foreach (SpriteRenderer spriteRenderer in spriteRenderers)
            {
                spriteRenderer.transform.Rotate(0, 0, -90);
            }
        }
    }
コード例 #7
0
    /// Called when MatrixMoveMessage is received
    public void UpdateClientState(MatrixState newState)
    {
        var oldState = clientState;

        clientState       = newState;
        clientTargetState = newState;

        if (!Equals(oldState.orientation, newState.orientation) || !ReceivedInitialRotation)
        {
            if (!ReceivedInitialRotation)
            {
                //this is the first state, so set initial rotation based on offset from initial position
                previousRotation          = newState.RotationOffset;
                performingInitialRotation = true;
            }
            else
            {
                //update based on offset from old state
                previousRotation = oldState.orientation.OffsetTo(newState.orientation);
            }
            OnRotateStart.Invoke(previousRotation, !ReceivedInitialRotation);

            //This is ok for occasional state changes like beginning of rot:
            gameObject.BroadcastMessage("MatrixMoveStartRotation", null, SendMessageOptions.DontRequireReceiver);
            monitorOnRot = true;
        }

        if (!ReceivedInitialRotation)
        {
            ReceivedInitialRotation = true;
        }

        if (!oldState.IsMoving && newState.IsMoving)
        {
            OnStart.Invoke();
        }

        if (oldState.IsMoving && !newState.IsMoving)
        {
            OnStop.Invoke();
        }

        if ((int)oldState.Speed != (int)newState.Speed)
        {
            OnSpeedChange.Invoke(oldState.Speed, newState.Speed);
        }
    }
コード例 #8
0
    /// <summary>
    /// Returns the degree of rotation between 2 rotation offsets. Order matters.
    /// </summary>
    /// <param name="from">offset from</param>
    /// <param name="to">offset to</param>
    /// <returns>positive difference between offsets if from has a greater clockwise degree than
    /// to, otherwise negative. Value will always be between -360 and 360</returns>
    public static int DegreeBetween(RotationOffset from, RotationOffset to)
    {
        int beforeDegree = from.Degree;
        int afterDegree  = to.Degree;

        if (from.Degree == 0 && to.Degree == 270)
        {
            beforeDegree = 360;
        }

        if (from.Degree == 270 && to.Degree == 0)
        {
            afterDegree = 360;
        }

        return(afterDegree - beforeDegree);
    }
コード例 #9
0
ファイル: Camera.cs プロジェクト: still-scene/Operators
        private void Update(EvaluationContext context)
        {
            float fov         = MathUtil.DegreesToRadians(Fov.GetValue(context));
            float aspectRatio = AspectRatio.GetValue(context);

            if (aspectRatio < 0.0001f)
            {
                aspectRatio = (float)context.RequestedResolution.Width / context.RequestedResolution.Height;
            }
            System.Numerics.Vector2 clip = NearFarClip.GetValue(context);
            Matrix cameraToClipSpace     = Matrix.PerspectiveFovRH(fov, aspectRatio, clip.X, clip.Y);

            var     positionValue = Position.GetValue(context);
            Vector3 eye           = new Vector3(positionValue.X, positionValue.Y, positionValue.Z);
            var     targetValue   = Target.GetValue(context);
            Vector3 target        = new Vector3(targetValue.X, targetValue.Y, targetValue.Z);
            var     upValue       = Up.GetValue(context);
            Vector3 up            = new Vector3(upValue.X, upValue.Y, upValue.Z);
            Matrix  worldToCamera = Matrix.LookAtRH(eye, target, up);

            //var worldToCamera = Matrix.LookAtLH(position, target, new Vector3(0, 1, 0));
            var rollRotation = Matrix.RotationAxis(new Vector3(0, 0, 1), -(float)Roll.GetValue(context));

            var pOffset = PositionOffset.GetValue(context);
            var additionalTranslation = Matrix.Translation(pOffset.X, pOffset.Y, pOffset.Z);

            var rOffset            = RotationOffset.GetValue(context);
            var additionalRotation = Matrix.RotationYawPitchRoll(MathUtil.DegreesToRadians(rOffset.Y),
                                                                 MathUtil.DegreesToRadians(rOffset.X),
                                                                 MathUtil.DegreesToRadians(rOffset.Z));


            var worldToCamera2 = worldToCamera * rollRotation * additionalTranslation * additionalRotation;

            var prevWorldToCamera     = context.WorldToCamera;
            var prevCameraToClipSpace = context.CameraToClipSpace;

            context.WorldToCamera     = worldToCamera2;
            context.CameraToClipSpace = cameraToClipSpace;

            Command.GetValue(context);

            context.CameraToClipSpace = prevCameraToClipSpace;
            context.WorldToCamera     = prevWorldToCamera;
        }
コード例 #10
0
    protected override void OnRotationEnd(RotationOffset fromCurrent, bool isInitialRotation)
    {
        base.OnRotationEnd(fromCurrent, isInitialRotation);

        if (!isInitialRotation)
        {
            //stop reorienting to face upright
            UpdateManager.Instance.Remove(RemainUpright);
        }

        //add extra rotation to ensure we are sideways
        if (isDown)
        {
            foreach (SpriteRenderer spriteRenderer in spriteRenderers)
            {
                spriteRenderer.transform.Rotate(0, 0, -90);
            }
        }
    }
コード例 #11
0
    private void OnRotationStart(RotationOffset fromCurrent, bool isInitialRotation)
    {
        //ignore the initial rotation message because we determine initial rotation from the
        //currentBodyDirection syncvar in playerSprites
        if (!isInitialRotation)
        {
            //determine our destination rotation
            if (playerMove.isGhost)
            {
                destinationOrientation = currentGhostDirection.Rotate(fromCurrent);
            }
            else
            {
                destinationOrientation = currentBodyDirection.Rotate(fromCurrent);
            }

            isMatrixRotating = true;
        }
    }
コード例 #12
0
    public bool Push(Vector2Int direction, float speed = Single.NaN, bool followMode = false)
    {     //player speed change not implemented yet
        if (direction == Vector2Int.zero)
        {
            return(false);
        }

        Vector3Int origin   = Vector3Int.RoundToInt((Vector2)serverState.WorldPosition);
        Vector3Int pushGoal = origin + Vector3Int.RoundToInt((Vector2)direction);

        if (!MatrixManager.IsPassableAt(origin, pushGoal, !followMode))
        {
            return(false);
        }

        if (followMode)
        {
            SendMessage("FaceDirection", RotationOffset.From(direction), SendMessageOptions.DontRequireReceiver);
        }

        Logger.LogTraceFormat("Server push to {0}", Category.PushPull, pushGoal);
        ClearQueueServer();
        MatrixInfo newMatrix = MatrixManager.AtPoint(pushGoal);
        //Note the client queue reset
        var newState = new PlayerState {
            MoveNumber            = 0,
            Impulse               = direction,
            MatrixId              = newMatrix.Id,
            WorldPosition         = pushGoal,
            ImportantFlightUpdate = true,
            ResetClientQueue      = true,
            IsFollowUpdate        = followMode
        };

        serverLastDirection = direction;
        serverState         = newState;
        SyncMatrix();
        OnStartMove().Invoke(origin, pushGoal);
        NotifyPlayers();

        return(true);
    }
コード例 #13
0
 public void OnRotation(RotationOffset fromCurrent)
 {
     orientation = orientation.Rotate(fromCurrent);
     if (orientation == Orientation.Up)
     {
         spriteRenderer.sprite = s_up;
     }
     else if (orientation == Orientation.Down)
     {
         spriteRenderer.sprite = s_down;
     }
     else if (orientation == Orientation.Left)
     {
         spriteRenderer.sprite = s_left;
     }
     else
     {
         spriteRenderer.sprite = s_right;
     }
 }
コード例 #14
0
    public void OnRotate(RotationOffset fromCurrent, bool isInitialRotation)
    {
        orientation = orientation.Rotate(fromCurrent);
        if (orientation == Orientation.Up)
        {
            spriteRenderer.sprite = s_up;
        }
        else if (orientation == Orientation.Down)
        {
            spriteRenderer.sprite = s_down;
        }
        else if (orientation == Orientation.Left)
        {
            spriteRenderer.sprite = s_left;
        }
        else
        {
            spriteRenderer.sprite = s_right;
        }

        EnsureSpriteLayer();
    }
コード例 #15
0
        private void CalculateOffset()
        {
            var actualTheta   = Math.Atan2(SecondLocated.Y - FirstLocated.Y, SecondLocated.X - FirstLocated.X);
            var expectedTheta = Math.Atan2(SecondExpected.Y - FirstLocated.Y, SecondExpected.X - FirstLocated.X);

            RotationOffset = expectedTheta - actualTheta;

            var deltaX = FirstLocated.X - _boardManager.FirstFiducial.X;
            var deltaY = FirstLocated.Y - _boardManager.FirstFiducial.Y;
            /* Based on the board being perfectly level find where teh origin is based on absolute position */
            var initial = new Point2D <double>(deltaX, deltaY);

            /* Apply rotation offset based on actual board rotation */
            OffsetPoint = initial.Rotate(FirstLocated, RotationOffset.ToDegrees());

            BoardOriginPoint = new Point2D <double>()
            {
                X = FirstLocated.X - deltaX,
                Y = FirstLocated.Y - deltaY
            };

            HasCalculatedOffset = true;
        }
コード例 #16
0
ファイル: MCollider.cs プロジェクト: dr-iskandar/MOSIM_Core
 public void Write(TProtocol oprot)
 {
     oprot.IncrementRecursionDepth();
     try
     {
         TStruct struc = new TStruct("MCollider");
         oprot.WriteStructBegin(struc);
         TField field = new TField();
         if (ID == null)
         {
             throw new TProtocolException(TProtocolException.INVALID_DATA, "required field ID not set");
         }
         field.Name = "ID";
         field.Type = TType.String;
         field.ID   = 1;
         oprot.WriteFieldBegin(field);
         oprot.WriteString(ID);
         oprot.WriteFieldEnd();
         field.Name = "Type";
         field.Type = TType.I32;
         field.ID   = 2;
         oprot.WriteFieldBegin(field);
         oprot.WriteI32((int)Type);
         oprot.WriteFieldEnd();
         if (BoxColliderProperties != null && __isset.BoxColliderProperties)
         {
             field.Name = "BoxColliderProperties";
             field.Type = TType.Struct;
             field.ID   = 3;
             oprot.WriteFieldBegin(field);
             BoxColliderProperties.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (SphereColliderProperties != null && __isset.SphereColliderProperties)
         {
             field.Name = "SphereColliderProperties";
             field.Type = TType.Struct;
             field.ID   = 4;
             oprot.WriteFieldBegin(field);
             SphereColliderProperties.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (CapsuleColliderProperties != null && __isset.CapsuleColliderProperties)
         {
             field.Name = "CapsuleColliderProperties";
             field.Type = TType.Struct;
             field.ID   = 5;
             oprot.WriteFieldBegin(field);
             CapsuleColliderProperties.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (ConeColliderProperties != null && __isset.ConeColliderProperties)
         {
             field.Name = "ConeColliderProperties";
             field.Type = TType.Struct;
             field.ID   = 6;
             oprot.WriteFieldBegin(field);
             ConeColliderProperties.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (CylinderColliderProperties != null && __isset.CylinderColliderProperties)
         {
             field.Name = "CylinderColliderProperties";
             field.Type = TType.Struct;
             field.ID   = 7;
             oprot.WriteFieldBegin(field);
             CylinderColliderProperties.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (MeshColliderProperties != null && __isset.MeshColliderProperties)
         {
             field.Name = "MeshColliderProperties";
             field.Type = TType.Struct;
             field.ID   = 8;
             oprot.WriteFieldBegin(field);
             MeshColliderProperties.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (PositionOffset != null && __isset.PositionOffset)
         {
             field.Name = "PositionOffset";
             field.Type = TType.Struct;
             field.ID   = 9;
             oprot.WriteFieldBegin(field);
             PositionOffset.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (RotationOffset != null && __isset.RotationOffset)
         {
             field.Name = "RotationOffset";
             field.Type = TType.Struct;
             field.ID   = 10;
             oprot.WriteFieldBegin(field);
             RotationOffset.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (Colliders != null && __isset.Colliders)
         {
             field.Name = "Colliders";
             field.Type = TType.List;
             field.ID   = 11;
             oprot.WriteFieldBegin(field);
             {
                 oprot.WriteListBegin(new TList(TType.Struct, Colliders.Count));
                 foreach (MCollider _iter111 in Colliders)
                 {
                     _iter111.Write(oprot);
                 }
                 oprot.WriteListEnd();
             }
             oprot.WriteFieldEnd();
         }
         if (Properties != null && __isset.Properties)
         {
             field.Name = "Properties";
             field.Type = TType.Map;
             field.ID   = 12;
             oprot.WriteFieldBegin(field);
             {
                 oprot.WriteMapBegin(new TMap(TType.String, TType.String, Properties.Count));
                 foreach (string _iter112 in Properties.Keys)
                 {
                     oprot.WriteString(_iter112);
                     oprot.WriteString(Properties[_iter112]);
                 }
                 oprot.WriteMapEnd();
             }
             oprot.WriteFieldEnd();
         }
         oprot.WriteFieldStop();
         oprot.WriteStructEnd();
     }
     finally
     {
         oprot.DecrementRecursionDepth();
     }
 }
コード例 #17
0
 private void OnRotation(RotationOffset fromCurrent)
 {
     playerSprites.ChangePlayerDirection(fromCurrent);
 }
コード例 #18
0
ファイル: MCollider.cs プロジェクト: dr-iskandar/MOSIM_Core
        public override string ToString()
        {
            StringBuilder __sb = new StringBuilder("MCollider(");

            __sb.Append(", ID: ");
            __sb.Append(ID);
            __sb.Append(", Type: ");
            __sb.Append(Type);
            if (BoxColliderProperties != null && __isset.BoxColliderProperties)
            {
                __sb.Append(", BoxColliderProperties: ");
                __sb.Append(BoxColliderProperties == null ? "<null>" : BoxColliderProperties.ToString());
            }
            if (SphereColliderProperties != null && __isset.SphereColliderProperties)
            {
                __sb.Append(", SphereColliderProperties: ");
                __sb.Append(SphereColliderProperties == null ? "<null>" : SphereColliderProperties.ToString());
            }
            if (CapsuleColliderProperties != null && __isset.CapsuleColliderProperties)
            {
                __sb.Append(", CapsuleColliderProperties: ");
                __sb.Append(CapsuleColliderProperties == null ? "<null>" : CapsuleColliderProperties.ToString());
            }
            if (ConeColliderProperties != null && __isset.ConeColliderProperties)
            {
                __sb.Append(", ConeColliderProperties: ");
                __sb.Append(ConeColliderProperties == null ? "<null>" : ConeColliderProperties.ToString());
            }
            if (CylinderColliderProperties != null && __isset.CylinderColliderProperties)
            {
                __sb.Append(", CylinderColliderProperties: ");
                __sb.Append(CylinderColliderProperties == null ? "<null>" : CylinderColliderProperties.ToString());
            }
            if (MeshColliderProperties != null && __isset.MeshColliderProperties)
            {
                __sb.Append(", MeshColliderProperties: ");
                __sb.Append(MeshColliderProperties == null ? "<null>" : MeshColliderProperties.ToString());
            }
            if (PositionOffset != null && __isset.PositionOffset)
            {
                __sb.Append(", PositionOffset: ");
                __sb.Append(PositionOffset == null ? "<null>" : PositionOffset.ToString());
            }
            if (RotationOffset != null && __isset.RotationOffset)
            {
                __sb.Append(", RotationOffset: ");
                __sb.Append(RotationOffset == null ? "<null>" : RotationOffset.ToString());
            }
            if (Colliders != null && __isset.Colliders)
            {
                __sb.Append(", Colliders: ");
                __sb.Append(Colliders);
            }
            if (Properties != null && __isset.Properties)
            {
                __sb.Append(", Properties: ");
                __sb.Append(Properties);
            }
            __sb.Append(")");
            return(__sb.ToString());
        }
コード例 #19
0
 /// <summary>
 /// Return the rotation that would be reached by rotating according to the specified offset.
 ///
 /// For example, if Orientation is Right and offset is Backwards, will return Orientation.Left
 /// </summary>
 /// <param name="offset">offset to rotate by</param>
 /// <returns>the rotation that would be reached by rotating according to the specified offset.</returns>
 public Orientation Rotate(RotationOffset offset)
 {
     return(Rotate(offset.Degree / 90));
 }
コード例 #20
0
        public static void DrawAddons(bool portrait, Pawn pawn, Vector3 vector)
        {
            if (pawn.def is ThingDef_AlienRace alienProps)
            {
                List <BodyAddon> addons    = alienProps.alienRace.generalSettings.alienPartGenerator.bodyAddons;
                AlienComp        alienComp = pawn.GetComp <AlienComp>();
                for (int i = 0; i < addons.Count; i++)
                {
                    BodyAddon ba = addons[i];


                    if (ba.CanDrawAddon(pawn))
                    {
                        Mesh mesh = portrait ? ba.addonPortraitMeshFlipped : ba.addonMesh;

                        Rot4 rotation = pawn.Rotation;
                        if (portrait)
                        {
                            rotation = Rot4.South;
                        }
                        RotationOffset offset = rotation == Rot4.South
                                                    ? ba.offsets.front
                                                    : rotation == Rot4.North
                                                        ? ba.offsets.back
                                                        : ba.offsets.side;

                        // Log.Message("front: " + (offset == ba.offsets.front).ToString() + "\nback: " + (offset == ba.offsets.back).ToString() + "\nside :" + (offset == ba.offsets.side).ToString());
                        Vector2 bodyOffset = offset?.bodyTypes?.FirstOrDefault(to => to.BodyTypeDef == pawn.story.bodyType)
                                             ?.offset ?? Vector2.zero;
                        Vector2 crownOffset =
                            offset?.crownTypes?.FirstOrDefault(to => to.crownType == alienComp.crownType)?.offset
                            ?? Vector2.zero;

                        // front 0.42f, -0.3f, -0.22f
                        // back     0f,  0.3f, -0.55f
                        // side -0.42f, -0.3f, -0.22f
                        float MoffsetX = 0.42f;
                        float MoffsetZ = -0.22f;
                        float MoffsetY = ba.inFrontOfBody ? 0.3f : -0.3f;
                        float num      = ba.angle;

                        if (rotation == Rot4.North)
                        {
                            MoffsetX = 0f;
                            MoffsetY = !ba.inFrontOfBody ? 0.3f : -0.3f;
                            MoffsetZ = -0.55f;
                            num      = 0;
                        }

                        MoffsetX += bodyOffset.x + crownOffset.x;
                        MoffsetZ += bodyOffset.y + crownOffset.y;

                        if (rotation == Rot4.East)
                        {
                            MoffsetX = -MoffsetX;
                            num      = -num; // Angle
                            mesh     = ba.addonMeshFlipped;
                        }

                        Vector3 scaleVector = new Vector3(MoffsetX, MoffsetY, MoffsetZ);
                        scaleVector.x *= 1f + (1f - (portrait
                                                         ? alienProps.alienRace.generalSettings.alienPartGenerator
                                                     .customPortraitDrawSize
                                                         : alienProps.alienRace.generalSettings.alienPartGenerator
                                                     .customDrawSize).x);
                        scaleVector.z *= 1f + (1f - (portrait
                                                         ? alienProps.alienRace.generalSettings.alienPartGenerator
                                                     .customPortraitDrawSize
                                                         : alienProps.alienRace.generalSettings.alienPartGenerator
                                                     .customDrawSize).y);

                        GenDraw.DrawMeshNowOrLater(
                            mesh,
                            vector + scaleVector,
                            Quaternion.AngleAxis(num, Vector3.up),
                            alienComp.addonGraphics[i].MatAt(rotation),
                            portrait);
                    }
                }
            }
        }
コード例 #21
0
 /// <summary>
 /// Adds rotation offset to a body part. Rotation offsets add to the targets in VRIK
 /// </summary>
 public void AddRotationOffset(RotationOffset rotationOffset, Vector3 value)
 {
     AddRotationOffset(rotationOffset, Quaternion.Euler(value));
 }
コード例 #22
0
    //Rotates FX as ship rotates
    public void RotateFX(RotationOffset newRotationOffset, bool isInitialRotation)
    {
        var mainFX = particleFX.main;

        //mainFX.startRotation = newRotationOffset.Degree * Mathf.Deg2Rad;
    }
コード例 #23
0
ファイル: RandomCamera.cs プロジェクト: still-scene/Operators
        private void Update(EvaluationContext context)
        {
            float fov         = MathUtil.DegreesToRadians(Fov.GetValue(context));
            float aspectRatio = AspectRatio.GetValue(context);

            if (aspectRatio < 0.0001f)
            {
                aspectRatio = (float)context.RequestedResolution.Width / context.RequestedResolution.Height;
            }
            System.Numerics.Vector2 clip = NearFarClip.GetValue(context);

            Matrix cameraToClipSpace = Matrix.PerspectiveFovRH(fov, aspectRatio, clip.X, clip.Y);

            // var pos = Position.GetValue(context);
            // Vector3 eye = new Vector3(pos.X, pos.Y, pos.Z);

            Vector3 p                = new Vector3(0, 0, Radius.GetValue(context));
            var     seed             = Seed.GetValue(context);
            var     wobbleSpeed      = WobbleSpeed.GetValue(context);
            var     wobbleComplexity = (int)MathUtils.Clamp(WobbleComplexity.GetValue(context), 1, 8);

            //var offset =
            var rotOffset = RotationOffset.GetValue(context);

            // Orbit rotation
            System.Numerics.Vector3 t = Center.GetValue(context);
            Vector3 target            = new Vector3(t.X, t.Y, t.Z);

            var rot = Matrix.RotationYawPitchRoll(
                ComputeAngle(SpinAngleAndWobble, 1)
                + MathUtil.DegreesToRadians((float)(SpinRate.GetValue(context)
                                                    * (EvaluationContext.BeatTime + SpinOffset.GetValue(context)) * 360
                                                    + MathUtils.PerlinNoise(0, 1, 6, seed) * 360))
                ,
                -ComputeAngle(OrbitAngleAndWobble, 2),
                0);
            var p2  = Vector3.Transform(p, rot);
            var eye = new Vector3(p2.X, p2.Y, p2.Z);

            // View rotation
            var viewDirection = target - eye;

            var rotateAim = Matrix.RotationYawPitchRoll(
                ComputeAngle(AimYawAngleAndWobble, 3) + rotOffset.X * MathUtils.ToRad,
                ComputeAngle(AimPitchAngleAndWobble, 4) + rotOffset.Y * MathUtils.ToRad,
                rotOffset.Z * MathUtils.ToRad);


            var adjustedViewDirection = Vector3.TransformNormal(viewDirection, rotateAim);

            target = eye + adjustedViewDirection;


            // Computing matrix
            var     u  = Up.GetValue(context);
            Vector3 up = new Vector3(u.X, u.Y, u.Z);

            var roll = ComputeAngle(AimRollAngleAndWobble, 5);
            var rotateAroundViewDirection = Matrix.RotationAxis(adjustedViewDirection, roll);

            up = Vector3.TransformNormal(up, rotateAroundViewDirection);

            Matrix worldToCamera = Matrix.LookAtRH(eye, target, up);

            var prevCameraToClipSpace = context.CameraToClipSpace;

            context.CameraToClipSpace = cameraToClipSpace;

            var prevWorldToCamera = context.WorldToCamera;

            context.WorldToCamera = worldToCamera;
            Command.GetValue(context);

            context.CameraToClipSpace = prevCameraToClipSpace;
            context.WorldToCamera     = prevWorldToCamera;


            float ComputeAngle(Slot <Vector2> angleAndWobbleInput, int seedIndex)
            {
                var angleAndWobble = angleAndWobbleInput.GetValue(context);
                var wobble         = Math.Abs(angleAndWobble.Y) < 0.001f
                                 ? 0
                                 : (MathUtils.PerlinNoise((float)EvaluationContext.BeatTime * wobbleSpeed,
                                                          1, wobbleComplexity, seed - 123 * seedIndex) - 0.5f) * 2 * angleAndWobble.Y;

                return(MathUtil.DegreesToRadians(angleAndWobble.X + wobble));
            }
        }
コード例 #24
0
ファイル: MatrixMove.cs プロジェクト: Venseer/unitystation
    /// Clientside movement routine
    private void CheckMovement()
    {
        if (Equals(clientState, MatrixState.Invalid))
        {
            return;
        }

        if (IsRotatingClient)
        {
            RotationOffset targetOffset  = clientState.RotationOffset;
            bool           needsRotation = clientState.RotationTime != 0 &&
                                           !Mathf.Approximately(Quaternion.Angle(transform.rotation, targetOffset.Quaternion), 0);
            if (needsRotation)
            {
                transform.rotation =
                    Quaternion.RotateTowards(transform.rotation,
                                             targetOffset.Quaternion,
                                             Time.deltaTime * clientState.RotationTime);
            }
            else
            {
                // Finishes the job of Lerp and straightens the ship with exact angle value
                transform.rotation = targetOffset.Quaternion;
            }
        }
        else if (isMovingClient)
        {
            //Only move target if rotation is finished
            SimulateStateMovement();
        }

        if (!IsRotatingClient && monitorOnRot)
        {
            monitorOnRot = false;
            //This is ok for occasional state changes like end of rot:
            gameObject.BroadcastMessage("MatrixMoveStopRotation", null, SendMessageOptions.DontRequireReceiver);
        }

        //Lerp
        if (clientState.Position != transform.position)
        {
            float distance   = Vector3.Distance(clientState.Position, transform.position);
            bool  shouldWarp = distance > 2 || IsRotatingClient;

            //Teleport (Greater then 30 unity meters away from server target):
            if (distance > 30f)
            {
                clampedPosition = clientState.Position;
                return;
            }

            //FIXME Remove this once lerping has been properly fixed with Pixel Perfect movement:
            //If stopped then lerp to target
            if (!clientState.IsMoving && distance > 0f)
            {
                transform.position = Vector3.MoveTowards(transform.position, clientState.Position,
                                                         clientState.Speed * Time.deltaTime * (shouldWarp ? (distance * 2) : 1));
                mPreviousPosition         = transform.position;
                mPreviousFilteredPosition = transform.position;
                return;
            }

            //FIXME: We need to use MoveTowards or some other lerp function as ClientState is like server waypoints and does not contain lerp positions
            //FIXME: Currently shuttles teleport to each position received via server instead of lerping towards them
            clampedPosition = clientState.Position;

            // Activate warp speed if object gets too far away or have to rotate
            //Vector3.MoveTowards( transform.position, clientState.Position, clientState.Speed * Time.deltaTime * ( shouldWarp ? (distance * 2) : 1 ) );
        }
    }
コード例 #25
0
 public bool Equals(RotationOffset other)
 {
     return(Degree == other.Degree);
 }
コード例 #26
0
ファイル: PlayerSprites.cs プロジェクト: grigb/unitystation
 /// <summary>
 /// Cause player to rotate from their current direction according to fromCurrnet
 /// </summary>
 /// <param name="fromCurrent">offset to rotate from current facing</param>
 public void ChangePlayerDirection(RotationOffset fromCurrent)
 {
     ChangePlayerDirection(currentDirection.Rotate(fromCurrent));
 }
コード例 #27
0
 private void OnRotationEnd(RotationOffset arg0, bool arg1)
 {
     //reset orientation to upright
     transform.rotation = Quaternion.identity;
 }
コード例 #28
0
 private void OnRotation(RotationOffset fromCurrent)
 {
     //fixme: doesn't seem to change orientation for clients from their point of view
     playerSprites.ChangePlayerDirection(fromCurrent);
 }
コード例 #29
0
ファイル: ShipThruster.cs プロジェクト: grigb/unitystation
    //Rotates FX as ship rotates
    public void RotateFX(RotationOffset newRotationOffset)
    {
        var mainFX = particleFX.main;

        mainFX.startRotation = newRotationOffset.Degree * Mathf.Deg2Rad;
    }
コード例 #30
0
 private void OnRotate(RotationOffset fromCurrent, bool isInitialRotation)
 {
     RotationOffset = RotationOffset.Rotate(fromCurrent);
     tilemap.RefreshAllTiles();
 }