UnityEngine.Quaternion.Dot(UnityEngine.Quaternion, UnityEngine.Quaternion)

Here are the examples of the csharp api UnityEngine.Quaternion.Dot(UnityEngine.Quaternion, UnityEngine.Quaternion) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

14 Examples 7

19 View Source File : Quaternion.cs
License : MIT License
Project Creator : AnotherEnd15

private static float Angle(Quaternion a, Quaternion b)
        {
            return (float) (Math.Acos((double) Math.Min(Math.Abs(Quaternion.Dot(a, b)), 1f)) * 2.0 * 57.2957801818848);
        }

19 View Source File : Quaternion.cs
License : MIT License
Project Creator : AnotherEnd15

private static void Angle(ref Quaternion a, ref Quaternion b, out float result)
        {
            result = (float) (Math.Acos((double) Math.Min(Math.Abs(Quaternion.Dot(a, b)), 1f)) * 2.0 * 57.2957801818848);
        }

19 View Source File : Interpolator.cs
License : MIT License
Project Creator : dag10

public void SetTargetRotation(Quaternion target)
        {
            bool wasRunning = Running;

            targetRotation = target;

            if (Quaternion.Dot(transform.rotation, target) < 1.0f)
            {
                AnimatingRotation = true;
                enabled = true;

                if (InterpolationStarted != null && !wasRunning)
                {
                    InterpolationStarted();
                }
            }
            else
            {
                // Set immediately to prevent acreplacedulation of error.
                transform.rotation = target;
                AnimatingRotation = false;
            }
        }

19 View Source File : Interpolator.cs
License : MIT License
Project Creator : dag10

public void SetTargetLocalRotation(Quaternion target)
        {
            bool wasRunning = Running;

            targetLocalRotation = target;

            if (Quaternion.Dot(transform.localRotation, target) < 1.0f)
            {
                AnimatingLocalRotation = true;
                enabled = true;

                if (InterpolationStarted != null && !wasRunning)
                {
                    InterpolationStarted();
                }
            }
            else
            {
                // Set immediately to prevent acreplacedulation of error.
                transform.localRotation = target;
                AnimatingLocalRotation = false;
            }
        }

19 View Source File : Quaternion.cs
License : MIT License
Project Creator : NathanWarden

public static float Angle (Quaternion a, Quaternion b)
		{
			float f = Quaternion.Dot (a, b);
			return Mathf.Acos (Mathf.Min (Mathf.Abs (f), 1f)) * 2f * 57.29578f;
		}

19 View Source File : Quaternion.cs
License : MIT License
Project Creator : Viagi

static Quaternion _Slerp(Quaternion q1, Quaternion q2, float t)
        {
            float dot = Dot(q1, q2);

            // dot = cos(theta)
            // if (dot < 0), q1 and q2 are more than 90 degrees apart,
            // so we can invert one to reduce spinning
            Quaternion tmpQuat = new Quaternion();
            if (dot < 0.0f)
            {
                dot = -dot;
                tmpQuat.Set(-q2.x,
                    -q2.y,
                    -q2.z,
                    -q2.w);
            }
            else
                tmpQuat = q2;


            if (dot < 0.95f)
            {
                float angle = Mathf.Acos(dot);
                float sinadiv, sinat, sinaomt;
                sinadiv = 1.0f / Mathf.Sin(angle);
                sinat = Mathf.Sin(angle * t);
                sinaomt = Mathf.Sin(angle * (1.0f - t));
                tmpQuat.Set((q1.x * sinaomt + tmpQuat.x * sinat) * sinadiv,
                    (q1.y * sinaomt + tmpQuat.y * sinat) * sinadiv,
                    (q1.z * sinaomt + tmpQuat.z * sinat) * sinadiv,
                    (q1.w * sinaomt + tmpQuat.w * sinat) * sinadiv);
                return tmpQuat;

            }
            // if the angle is small, use linear interpolation
            else
            {
                return _Lerp(q1, tmpQuat, t);
            }

        }

19 View Source File : Quaternion.cs
License : MIT License
Project Creator : Viagi

static Quaternion _Lerp(Quaternion q1, Quaternion q2, float t)
        {
            Quaternion tmpQuat = new Quaternion();
            // if (dot < 0), q1 and q2 are more than 360 deg apart.
            // The problem is that quaternions are 720deg of freedom.
            // so we - all components when lerping
            if (Dot(q1, q2) < 0.0F)
            {
                tmpQuat.Set(q1.x + t * (-q2.x - q1.x),
                    q1.y + t * (-q2.y - q1.y),
                    q1.z + t * (-q2.z - q1.z),
                    q1.w + t * (-q2.w - q1.w));
            }
            else
            {
                tmpQuat.Set(q1.x + t * (q2.x - q1.x),
                    q1.y + t * (q2.y - q1.y),
                    q1.z + t * (q2.z - q1.z),
                    q1.w + t * (q2.w - q1.w));
            }
            return Normalize(tmpQuat);
        }

19 View Source File : Quaternion.cs
License : MIT License
Project Creator : Viagi

static float AngularDistance(Quaternion lhs, Quaternion rhs)
        {
            float dot = Dot(lhs, rhs);
            if (dot < 0.0f)
                dot = -dot;
            return Mathf.Acos(Mathf.Min(1.0F, dot)) * 2.0F;
        }

19 View Source File : Quaternion.cs
License : MIT License
Project Creator : Viagi

static float SqrMagnitude(Quaternion q)
        {
            return Dot(q, q);
        }

19 View Source File : Quaternion.cs
License : MIT License
Project Creator : Viagi

static public float Angle(Quaternion a, Quaternion b)
        {
            float dot = Dot(a, b);
            return Mathf.Acos(Mathf.Min(Mathf.Abs(dot), 1.0F)) * 2.0F * Mathf.Rad2Deg;
        }

19 View Source File : Quaternion.cs
License : MIT License
Project Creator : wqaetly

private static float Angle(Quaternion a, Quaternion b)
        {
            return (float)(Math.Acos((double)Math.Min(Math.Abs(Quaternion.Dot(a, b)), 1f)) * 2.0 * 57.2957801818848);
        }

19 View Source File : Quaternion.cs
License : MIT License
Project Creator : wqaetly

private static void Angle(ref Quaternion a, ref Quaternion b, out float result)
        {
            result = (float)(Math.Acos((double)Math.Min(Math.Abs(Quaternion.Dot(a, b)), 1f)) * 2.0 * 57.2957801818848);
        }

19 View Source File : Dot.cs
License : MIT License
Project Creator : XINCGer

public override TaskStatus OnUpdate()
        {
            storeResult.Value = Quaternion.Dot(leftRotation.Value, rightRotation.Value);
            return TaskStatus.Success;
        }

19 View Source File : AIVehicle.cs
License : MIT License
Project Creator : XINCGer

void AICarControl()
    {


        if (AIControl.manage.firstAINode == wrongNode && !getLap)
        {
            currentLap++;
            playerLastTime = playerCurrentTime;

            if (currentLap == 1) GameUI.manage.gameFinished = true;

            if (playerBestTime == 0.0f || playerBestTime > playerCurrentTime) playerBestTime = playerCurrentTime;

            playerCurrentTime = 0.0f;
            getLap = true;
        }
        else if (AIControl.manage.startPoint != currentNode)
        {
            getLap = false;
        }

        //////////////////////////////////////////////////////////////////////////////////////////////////	

        Vector3 CurrentNodeForward = currentNode.TransformDirection(Vector3.forward);
        Vector3 CurrentNodetoOther = currentNode.position - frontPoint.position;

        Vector3 NextNodeForward = nextNode.TransformDirection(Vector3.forward);
        Vector3 NextNodetoOther = nextNode.position - frontPoint.position;

        carPreviousNodes = Mathf.Clamp(carPreviousNodes, 0, 6);


        if (Mathf.Abs(Quaternion.Dot(nextNode.rotation, frontPoint.rotation)) < 0.5f && !GameUI.manage.gameFinished)
            GameUI.manage.carWrongWay = true;
        else
            GameUI.manage.carWrongWay = false;


        if (nextNode)
        {

            if (vehicleControl.vehicleMode == VehicleMode.AICar)
            {
                if (Vector3.Distance(frontPoint.position, nextNode.position) < nextNodeDistance && nextNode != currentNode)
                {
                    currentNode = nextNode;
                    wrongNode = nextNode;
                    goNextNode = true;
                }

            }
            else if (vehicleControl.vehicleMode == VehicleMode.Player)
            {

                if (Vector3.Dot(NextNodeForward, NextNodetoOther) < 0.0f)
                {

                    carPreviousNodes--;
                    currentNode = nextNode;

                    if (wrongNode != null && wrongNode.GetComponent<AINode>().nextNode == nextNode) wrongNode = nextNode;

                    goNextNode = true;
                }
                else if (Vector3.Dot(CurrentNodeForward, CurrentNodetoOther) > 0.0f && currentNode.GetComponent<AINode>().previousNode != currentNode)
                {
                    carPreviousNodes++;
                    currentNode = currentNode.GetComponent<AINode>().previousNode;

                    if (carPreviousNodes == 5)
                    {
                        carPreviousNodes = 0;
                        transform.GetComponent<Rigidbody>().Sleep();
                        transform.rotation = wrongNode.rotation;
                        transform.position = wrongNode.position + Vector3.up;

                        currentNode = wrongNode;
                    }

                    goNextNode = true;
                }
            }

            if (Vector3.Distance(frontPoint.position, nextNode.position) > nextNodeDistance * 5)
            {
                carPreviousNodes = 0;
                transform.GetComponent<Rigidbody>().Sleep();
                transform.rotation = wrongNode.rotation;
                transform.position = wrongNode.position + Vector3.up;

                currentNode = wrongNode;
            }
        }

        //////////////////////////////////////////////////////////////////////////////////////////////////	

        GameUI.manage.carBrakeWarning = false;

        if (currentNode.GetComponent<AINode>())
        {
            AINode Nodescript = currentNode.GetComponent<AINode>();

            if (Mathf.Abs(AISteer) > 0.0f && vehicleControl.speed > 70.0f && Nodescript.nodeSetting.brakeing)
            {
                AIAccel = -Mathf.Abs(AISteer);
                GameUI.manage.carBrakeWarning = true;
            }
            else
            {
                AIAccel = 0.2f;
            }

            if (goNextNode)
            {
                nextNode = Nodescript.nextNode;
                goNextNode = false;
            }
        }

        var relativeTarget = transform.InverseTransformPoint(nextNode.position);

        targetAngle = Mathf.Atan2(relativeTarget.x, relativeTarget.z);
        targetAngle *= Mathf.Rad2Deg;
        targetAngle = Mathf.Clamp(targetAngle, -65, 65);

        AISteer = Mathf.SmoothStep(AISteer, targetAngle / 60, steerSpeed / 3.0f);
    }