Ejemplo n.º 1
0
        /// <summary>
        /// Calculate the angle it needs to rotate fromm the position of picker.
        /// </summary>
        /// <param name="picker">Picker that is grasping the object</param>
        /// <returns>Angle it needs to rotate itself</returns>
        protected float GetAdjustedCurrentAngleFromPicker(IPicker picker)
        {
            // Get picker's current angle of rotation from zero
            float pickerAngle = GetPickerAngleInRotationAxis(picker);
            // Get how much picker has rotated from the start of grasping
            float angleDiff = pickerAngle - PickerAngleOffset;
            // Decide which way to rotate by adjusting the target angle into range of
            // (reference - 180, reference + 180] such that it can be seen from the
            // adjusted angle which side of the reference the angle is. In this case,
            // target angle is PickableAngleOffset + angleDiff. The reference angle
            // is LastPickableAngle.
            float currentAngle = RotationUtils.AdjustAngleByReference(
                PickableAngleOffset + angleDiff, LastPickableAngle);

            // Clamp current angle to angle limit
            currentAngle = UnlimitedRotation
                ? Mathf.Clamp(currentAngle, -360, 360)
                : Mathf.Clamp(currentAngle, 0, _angleLimit);
            return(currentAngle);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Find the target angle of rotation from zero based on current picker's rotation.
        /// </summary>
        /// <remarks>
        /// The picker will maintain a fixed relative rotation with knob since the start of
        /// grasping, so given the current rotation of picker, we can compute the new target
        /// rotation of knob.
        /// </remarks>
        /// <param name="picker">The picker that is grasping it.</param>
        /// <returns>Target angle of rotation of knob based on the picker's rotation.</returns>
        protected override float GetPickerAngleInRotationAxis(IPicker picker)
        {
            PickerDexmo pickerDexmo     = picker as PickerDexmo;
            Transform   pickerReference = pickerDexmo == null ? picker.Transform : pickerDexmo.PalmCenter;
            // Calculate the target rotation of knob based on current rotation of the picker
            Quaternion newKnobTargetRotation = pickerReference.rotation *
                                               Quaternion.Inverse(_pickerRelativeRotationWrtKnob);
            // Convert the current angle reference from world coordinate to parent transform's
            // coordinate. Angle reference is the direction that indicates the current angle
            // of rotation from zero.
            Vector3 newAngleReferenceDirectionInWorld         = newKnobTargetRotation * ZeroReferenceDirection;
            Vector3 pickerRelativeDirectionInParentCoordinate =
                Miscellaneous.InverseTransformDirectionInParentCoordinate(transform,
                                                                          newAngleReferenceDirectionInWorld);
            // Find the target angle of rotation from zero in the plane normal to rotation axis
            float angle = RotationUtils.AngleInPlane(LocalRotationAxisInParentCoordinate,
                                                     ZeroReferenceDirectionInParentCoordinate, pickerRelativeDirectionInParentCoordinate);

            return(angle);
        }
Ejemplo n.º 3
0
    public bool isInAttackArea(float lowAngle, float highAngle, float nearRadius, float farRadius)
    {
        float spriteRadius         = transform.Find("Sprite").GetComponent <SpriteRenderer>().bounds.size.x / 2;
        float distanceToBossActual = Mathf.Max(Vector3.Distance(Vector3.zero, transform.position), 0);
        float distanceToBossFar    = distanceToBossActual + spriteRadius;
        float distanceToBossNear   = distanceToBossActual - spriteRadius;

        RadialPosition radialPosition = RotationUtils.XYToRadialPos(this.transform.position);

        float enemyWidthAngle = Mathf.Rad2Deg * Mathf.Acos(1 - Mathf.Pow(spriteRadius / Mathf.Sqrt(2 * distanceToBossActual), 2));
        float enemyHighAngle  = radialPosition.GetAngle() + enemyWidthAngle;
        float enemyLowAngle   = radialPosition.GetAngle() - enemyWidthAngle;

        bool inHighAngle          = RotationUtils.InCounterClockwiseLimits(enemyHighAngle, lowAngle, highAngle);
        bool inLowAngle           = RotationUtils.InCounterClockwiseLimits(enemyLowAngle, lowAngle, highAngle);
        bool bossLargerThanRadius = RotationUtils.InCounterClockwiseLimits(lowAngle, enemyLowAngle, enemyHighAngle) &&
                                    RotationUtils.InCounterClockwiseLimits(highAngle, enemyLowAngle, enemyHighAngle);
        bool inRadius = distanceToBossNear <= farRadius && distanceToBossFar >= nearRadius;

        return((inLowAngle || inHighAngle || bossLargerThanRadius) && inRadius);
    }
Ejemplo n.º 4
0
    public void UpdateRotation(float newRot)
    {
        transform.parent.eulerAngles = new Vector3(0, 0, newRot);         //Update rotation previous to checking limits

        //Find biggest of low limits and smallest of high limis to create the smallest allowed intervall
        float tmpLowLimit  = RotationUtils.InCounterClockwiseLimits(lowFrameTwistLimit, lowHardTwistLimit, highHardTwistLimit) ? lowFrameTwistLimit : lowHardTwistLimit;
        float tmpHighLimit = RotationUtils.InCounterClockwiseLimits(highFrameTwistLimit, lowHardTwistLimit, highHardTwistLimit) ? highFrameTwistLimit : highHardTwistLimit;

        float rotation = transform.parent.localEulerAngles.z;

        if (RotationUtils.InCounterClockwiseLimits(rotation, tmpLowLimit, tmpHighLimit))
        {
            //Angle in limit
            outHigh = false;
            outLow  = false;
        }
        else
        {
            if (outHigh)             //Rotation is still outside limits to one side
            {
                transform.parent.localEulerAngles = new Vector3(0, 0, tmpHighLimit);
            }
            else if (outLow)             //Rotation is still outside limits to the other side
            {
                transform.parent.localEulerAngles = new Vector3(0, 0, tmpLowLimit);
            }
            // Check to which side rotation has exited the limits intervall.
            // If it is not yet in one of the halves of the outside of the twist limits, wait until it is.
            else if (RotationUtils.InCounterClockwiseLimits(rotation, RotationUtils.MiddleOfRotations(tmpHighLimit, tmpLowLimit), tmpLowLimit))
            {
                outLow = true;
                transform.parent.localEulerAngles = new Vector3(0, 0, tmpLowLimit);
            }
            else if (RotationUtils.InCounterClockwiseLimits(rotation, tmpLowLimit, RotationUtils.MiddleOfRotations(tmpHighLimit, tmpLowLimit)))
            {
                outHigh = true;
                transform.parent.localEulerAngles = new Vector3(0, 0, tmpHighLimit);
            }
        }
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Blends two frames to create a new frame.
    /// </summary>
    /// <returns>The new blended frame.</returns>
    /// <param name="fromFrame">The first frame.</param>
    /// <param name="toFrame">The second frame.</param>
    /// <param name="percentage">The percentage to add from the second frame to the first frame.
    /// At 0 percent, the blended frame is identical to the first, and 100 it is identical to the secont</param>
    public Frame BlendFrames(Frame fromFrame, Frame toFrame, int percentage)
    {
        List <string> bodyPartNames = fromFrame.getBodyPartNames();
        Frame         newFrame      = (Frame)fromFrame.Clone();

        foreach (string name in bodyPartNames)
        {
            float newRotation;
            float fromRot = fromFrame.getRotation(name);
            float toRot   = toFrame.getRotation(name);
            //Make sure rotation around zero does not result in a loop in the wrong direction.
            //Make the angle right of zero (the smaller angle) bigger.
            if (RotationUtils.ZeroInSmallerLimit(fromRot, toRot))
            {
                if (fromRot < toRot)
                {
                    fromRot += 360;
                }
                else if (fromRot > toRot)
                {
                    toRot += 360;
                }
                //Make sure rotation 0 <=> [180-359] does not rotate the wrong way.
            }
            else if (fromRot == 0 && toRot > 180)
            {
                fromRot += 360;
            }
            else if (toRot == 0 && fromRot > 180)
            {
                toRot += 360;
            }
            newRotation = fromRot + (float)percentage / (float)100 * (toRot - fromRot);

            newFrame.AddBodyPartRotation(name, newRotation);
        }
        return(newFrame);
    }
Ejemplo n.º 6
0
    void doAttack()
    {
        Color color = UnityUtils.RecursiveFind(transform, "Image").GetComponent <Image>().color;

        color.a = 0.0f;

        float unitCircleRotation = RotationUtils.MakePositiveAngle(transform.eulerAngles.z + 90);

        Color zeroAlphaColor = color;

        zeroAlphaColor.a = 0.0f;
        object[] obj = GameObject.FindObjectsOfType(typeof(GameObject));
        foreach (Enemy enemy in GameObject.FindObjectsOfType(typeof(Enemy)))
        {
            if (enemy.isInAttackArea(unitCircleRotation - this.currentAttack.angle,
                                     unitCircleRotation + this.currentAttack.angle,
                                     this.currentAttack.closeRadius,
                                     this.currentAttack.farRadius))
            {
                enemy.applyDamageTo(this.currentAttack.damage);
            }
        }

        // For now, change color of boss when he is attacking
        // TODO: Change when areas of damage is implemented
        gameObject.GetComponent <SpriteRenderer>().color = Color.red;

        if (currentCooldownBehaviour != null)
        {
            currentCooldownBehaviour.RestartCooldown();
        }

        this.aimColorModifier.FadeToSelected(this.currentAttack.frequency);

        StartCoroutine(UnityUtils.ChangeToColorAfterTime(gameObject.GetComponent <SpriteRenderer>(), Color.white, 0.5f));
    }
Ejemplo n.º 7
0
 public void MoveTo(RadialPosition radialPosition)
 {
     transform.position = RotationUtils.RadialPosToXY(radialPosition);
 }
Ejemplo n.º 8
0
 public void AddAngle(float addedAngle)
 {
     this.angle += addedAngle;
     this.angle  = RotationUtils.MakePositiveAngle(angle);
 }
Ejemplo n.º 9
0
 public void SetAngle(float angle)
 {
     angle      = RotationUtils.MakePositiveAngle(angle);
     this.angle = angle;
 }