Helper class with debug assertions.
    /// <summary>
    /// Constructs a quaternion that will rotate the from vector to the to vector.
    /// This assumes 'from' and 'to' are normalized.
    /// </summary>
    public static Quaternion RotationBetweenTwoVectors(Vector3 from, Vector3 to)
    {
/*
 *              float dot = Vector3.Dot( from, to );
 *              if ( dot > 0.9999f )
 *              {
 *                      OVRDebugUtils.Assert( dot <= 0.9999f );
 *                      return Quaternion.identity;
 *              }
 *
 *              Quaternion q;
 *              q.w = CosineOfHalfAngleFromCosine( dot );
 *              float sineHalfAngle = SineFromCosine( q.w );
 *
 *              // get a vector orthogonal to both from and to
 *              Vector3 axis = Vector3.Cross( from, to );
 *              OVRDebugUtils.Assert( axis.magnitude > 0.0001f );
 *              q.x = axis.x * sineHalfAngle;
 *              q.y = axis.y * sineHalfAngle;
 *              q.z = axis.z * sineHalfAngle;
 *
 *              return q;
 */
        Quaternion q;

        q.x = from.y * to.z - from.z * to.y;
        q.y = from.z * to.x - from.x * to.z;
        q.z = from.x * to.y - from.y * to.x;
        q.w = to.x * from.x + to.y * from.y + to.z * from.z + 1.0f;
        OVRDebugUtils.Assert(q.w > 1e-18f);
        Normalize(ref q);
        return(q);
    }
    /// <summary>
    /// Clamps a quaternion rotation so that it remains within the specified angle
    /// from identity.
    /// </summary>
    public static bool Clamp(ref Quaternion q, float cosineOfClampAngle)
    {
        float cosineOfHalfClampAngle = CosineOfHalfAngleFromCosine(cosineOfClampAngle);

        if (q.w >= cosineOfHalfClampAngle)
        {
            return(false);            // already inside of the clamp
        }
        if (q.w > 0.99999f)
        {
            q = Quaternion.identity;
            return(true);
        }

        float s = SineFromCosine(q.w);

        OVRDebugUtils.Assert(s > OVRMathUtils.FltSmallestNonDenormal);

        Vector3 axis;

        axis.x = q.x / s;
        axis.y = q.y / s;
        axis.z = q.z / s;
        axis.Normalize();

        float sineOfHalfClampAngle = SineFromCosine(cosineOfHalfClampAngle);

        q.x = axis.x * sineOfHalfClampAngle;
        q.y = axis.y * sineOfHalfClampAngle;
        q.z = axis.z * sineOfHalfClampAngle;
        q.w = cosineOfHalfClampAngle;
        return(true);
    }
Ejemplo n.º 3
0
    static public GameObject FindChild(GameObject obj, string name)
    {
        GameObject go = FindChildNoWarning(obj, name);

        if (go == null)
        {
            OVRDebugUtils.Print("child " + name + " was not found!");
        }

        return(go);
    }
Ejemplo n.º 4
0
 /// <summary>
 /// Outputs debug spam for any depressed button.
 /// This is only used for finding which buttons are which with new controllers.
 /// </summary>
 private static void ShowButtonValues()
 {
     for (int i = 0; i < 6; ++i)
     {
         string buttonName = "Test Button " + i;
         if (Input.GetButton(buttonName))
         {
             OVRDebugUtils.Print("Test Button " + i + " is down.");
         }
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Outputs debug spam for any non-zero axis.
 /// This is only used for finding which axes are which with new controllers.
 /// </summary>
 private static void ShowAxisValues()
 {
     for (int i = 1; i <= 20; ++i)
     {
         string axisName = "Test Axis " + i;
         float  v        = Input.GetAxis(axisName);
         if (Mathf.Abs(v) > 0.2f)
         {
             OVRDebugUtils.Print("Test Axis " + i + ": v = " + v);
         }
     }
 }
    /// <summary>
    /// Normalizes a quaternion.  This can be necessary to repair floating point error.
    /// </summary>
    public static void Normalize(ref Quaternion q)
    {
        float mag = Mathf.Sqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w);

        // if the magnitude is becoming very small, let us know that we're risking a denormal
        OVRDebugUtils.Assert(mag > FltSmallestNonDenormal);
        float inverseMag = 1.0f / mag;

        q.x *= inverseMag;
        q.y *= inverseMag;
        q.z *= inverseMag;
        q.w *= inverseMag;
    }
Ejemplo n.º 7
0
 /// <summary>
 /// Adds a mapping from a joystick to a behavior.
 /// </summary>
 public static void AddInputMapping(int joystickNumber, MonoBehaviour comp)
 {
     for (int i = 0; i < inputMap.Count; ++i)
     {
         InputMapping im = inputMap[i];
         if (im.component == comp && im.joystickNumber == joystickNumber)
         {
             OVRDebugUtils.Assert(false, "Input mapping already exists!");
             return;
         }
     }
     inputMap.Add(new InputMapping(comp, joystickNumber));
 }
Ejemplo n.º 8
0
    /// <summary>
    /// Static contructor for the OVRInputControl class.
    /// </summary>
    static OVRInputControl()
    {
#if UNITY_ANDROID && !UNITY_EDITOR
        OVRGamepadController.SetReadAxisDelegate(ReadJoystickAxis);
        OVRGamepadController.SetReadButtonDelegate(ReadJoystickButton);
#endif
        switch (Application.platform)
        {
        case RuntimePlatform.WindowsPlayer:
            Init_Windows();
            break;

        case RuntimePlatform.WindowsEditor:
            Init_Windows_Editor();
            break;

        case RuntimePlatform.Android:
            Init_Android();
            break;

        case RuntimePlatform.OSXPlayer:
            Init_OSX();
            break;

        case RuntimePlatform.OSXEditor:
            Init_OSX_Editor();
            break;

        case RuntimePlatform.IPhonePlayer:
            Init_iPhone();
            break;
        }

        string[] joystickNames = Input.GetJoystickNames();
        for (int i = 0; i < joystickNames.Length; ++i)
        {
            OVRDebugUtils.Print("Found joystick '" + joystickNames[i] + "'...");
        }
    }
 /// <summary>
 /// Returns the dot product of two quaternions.  Note this is not the cosine
 /// of the angle between the quaternions' forward vectors, but the cosine of
 /// half the angle between them.
 /// </summary>
 public static float QuaternionDot(Quaternion a, Quaternion b)
 {
     OVRDebugUtils.Assert(QuaternionIsNormalized(a, 0.001f));
     OVRDebugUtils.Assert(QuaternionIsNormalized(b, 0.001f));
     return(a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes the input system for iPhone.
 /// </summary>
 private static void Init_iPhone()
 {
     OVRDebugUtils.Print("Initializing input for iPhone.");
     allowKeyControls = false;
     platformPrefix   = "iPhone:";
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes the input system for OSX when running from the Unity editor.
 /// </summary>
 private static void Init_OSX_Editor()
 {
     OVRDebugUtils.Print("Initializing input for OSX Editor.");
     allowKeyControls = true;
     platformPrefix   = "OSX:";
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Initializes the input system for OSX.
 /// </summary>
 private static void Init_OSX()
 {
     OVRDebugUtils.Print("Initializing input for OSX.");
     allowKeyControls = false;
     platformPrefix   = "OSX:";
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Initializes the input system for Android.
 /// </summary>
 private static void Init_Android()
 {
     OVRDebugUtils.Print("Initializing input for Android.");
     allowKeyControls = true;
     platformPrefix   = "Android:";
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Initializes the input system for Windows when running from the Unity editor.
 /// </summary>
 private static void Init_Windows_Editor()
 {
     OVRDebugUtils.Print("Initializing input for Windows Editor.");
     allowKeyControls = true;
     platformPrefix   = "Win:";
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Initializes the input system for OSX.
 /// </summary>
 private static void Init_Windows()
 {
     OVRDebugUtils.Print("Initializing input for Windows.");
     allowKeyControls = false;
     platformPrefix   = "Win:";
 }