devNotes 6-03-16 native vuforia app structure, dev UI, look and feel

https://www.youtube.com/watch?v=MDkj3SrQFXE

 

 

From Falafel:

using UnityEngine;
using System.Collections;
 
public class Magnetometer : MonoBehaviour {
 
  public TextMesh Status_Text;
 
  // Use this for initialization
  void Start () {
    Input.compass.enabled = true;
    Input.location.Start ();
  }
 
  // Update is called once per frame
  void Update () {
    var xrot = Mathf.Atan2 (Input.acceleration.z, Input.acceleration.y);
    var yzmag = Mathf.Sqrt (Mathf.Pow (Input.acceleration.y, 2) + Mathf.Pow (Input.acceleration.z, 2));
    var zrot = Mathf.Atan2 (Input.acceleration.x, yzmag);
 
    var xangle = xrot * (180 / Mathf.PI) + 90;
    var zangle = -zrot * (180 / Mathf.PI);
    transform.eulerAngles = new Vector3 (xangle, 0, zangle - Input.compass.trueHeading);
 
    if (Status_Text != null) {
      Status_Text.text = Input.compass.trueHeading.ToString ();
    }
  }
}

https://sourceforge.net/projects/grepwin/

grep

using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif

namespace UnityStandardAssets.CrossPlatformInput
{
    // helps with managing tilt input on mobile devices
    public class TiltInput : MonoBehaviour
    {
        // options for the various orientations
        public enum AxisOptions
        {
            ForwardAxis,
            SidewaysAxis,
        }


        [Serializable]
        public class AxisMapping
        {
            public enum MappingType
            {
                NamedAxis,
                MousePositionX,
                MousePositionY,
                MousePositionZ
            };


            public MappingType type;
            public string axisName;
        }


        public AxisMapping mapping;
        public AxisOptions tiltAroundAxis = AxisOptions.ForwardAxis;
        public float fullTiltAngle = 25;
        public float centreAngleOffset = 0;


        private CrossPlatformInputManager.VirtualAxis m_SteerAxis;


        private void OnEnable()
        {
            if (mapping.type == AxisMapping.MappingType.NamedAxis)
            {
                m_SteerAxis = new CrossPlatformInputManager.VirtualAxis(mapping.axisName);
                CrossPlatformInputManager.RegisterVirtualAxis(m_SteerAxis);
            }
        }


        private void Update()
        {
            float angle = 0;
            if (Input.acceleration != Vector3.zero)
            {
                switch (tiltAroundAxis)
                {
                    case AxisOptions.ForwardAxis:
                        angle = Mathf.Atan2(Input.acceleration.x, -Input.acceleration.y)*Mathf.Rad2Deg +
                                centreAngleOffset;
                        break;
                    case AxisOptions.SidewaysAxis:
                        angle = Mathf.Atan2(Input.acceleration.z, -Input.acceleration.y)*Mathf.Rad2Deg +
                                centreAngleOffset;
                        break;
                }
            }

            float axisValue = Mathf.InverseLerp(-fullTiltAngle, fullTiltAngle, angle)*2 - 1;
            switch (mapping.type)
            {
                case AxisMapping.MappingType.NamedAxis:
                    m_SteerAxis.Update(axisValue);
                    break;
                case AxisMapping.MappingType.MousePositionX:
                    CrossPlatformInputManager.SetVirtualMousePositionX(axisValue*Screen.width);
                    break;
                case AxisMapping.MappingType.MousePositionY:
                    CrossPlatformInputManager.SetVirtualMousePositionY(axisValue*Screen.width);
                    break;
                case AxisMapping.MappingType.MousePositionZ:
                    CrossPlatformInputManager.SetVirtualMousePositionZ(axisValue*Screen.width);
                    break;
            }
        }


        private void OnDisable()
        {
            m_SteerAxis.Remove();
        }
    }
}


namespace UnityStandardAssets.CrossPlatformInput.Inspector
{
#if UNITY_EDITOR
    [CustomPropertyDrawer(typeof (TiltInput.AxisMapping))]
    public class TiltInputAxisStylePropertyDrawer : PropertyDrawer
    {
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            float x = position.x;
            float y = position.y;
            float inspectorWidth = position.width;

            // Don't make child fields be indented
            var indent = EditorGUI.indentLevel;
            EditorGUI.indentLevel = 0;

            var props = new[] {"type", "axisName"};
            var widths = new[] {.4f, .6f};
            if (property.FindPropertyRelative("type").enumValueIndex > 0)
            {
                // hide name if not a named axis
                props = new[] {"type"};
                widths = new[] {1f};
            }
            const float lineHeight = 18;
            for (int n = 0; n < props.Length; ++n)
            {
                float w = widths[n]*inspectorWidth;

                // Calculate rects
                Rect rect = new Rect(x, y, w, lineHeight);
                x += w;

                EditorGUI.PropertyField(rect, property.FindPropertyRelative(props[n]), GUIContent.none);
            }

            // Set indent back to what it was
            EditorGUI.indentLevel = indent;
            EditorGUI.EndProperty();
        }
    }
#endif
}

 

function Update() 
{
      // Orient an object to point northward.
      transform.rotation = Quaternion.Euler(0, -Input.compass.trueHeading, 0);	
}

 

From:

using UnityEngine;
 
public class MoveWithCompass : MonoBehaviour
{
    private double _lastCompassUpdateTime = 0;
    private Quaternion _correction = Quaternion.identity;
    private Quaternion _targetCorrection = Quaternion.identity;
    private Quaternion _compassOrientation = Quaternion.identity;
   
    void Start()
    {
        Input.gyro.enabled = true;
        Input.compass.enabled = true;
    }
   
    void Update()
    {
        // The gyro is very effective for high frequency movements, but drifts its
        // orientation over longer periods, so we want to use the compass to correct it.
        // The iPad's compass has low time resolution, however, so we let the gyro be
        // mostly in charge here.
       
        // First we take the gyro's orientation and make a change of basis so it better
        // represents the orientation we'd like it to have
        Quaternion gyroOrientation = Quaternion.Euler (90, 0, 0) * Input.gyro.attitude * Quaternion.Euler(0, 0, 90);
   
        // See if the compass has new data
        if (Input.compass.timestamp > _lastCompassUpdateTime)
        {
            _lastCompassUpdateTime = Input.compass.timestamp;
       
            // Work out an orientation based primarily on the compass
            Vector3 gravity = Input.gyro.gravity.normalized;
            Vector3 flatNorth = Input.compass.rawVector -
                Vector3.Dot(gravity, Input.compass.rawVector) * gravity;
            _compassOrientation = Quaternion.Euler (180, 0, 0) * Quaternion.Inverse(Quaternion.LookRotation(flatNorth, -gravity)) * Quaternion.Euler (0, 0, 90);
           
            // Calculate the target correction factor
            _targetCorrection = _compassOrientation * Quaternion.Inverse(gyroOrientation);
        }
       
        // Jump straight to the target correction if it's a long way; otherwise, slerp towards it very slowly
        if (Quaternion.Angle(_correction, _targetCorrection) > 45)
            _correction = _targetCorrection;
        else
            _correction = Quaternion.Slerp(_correction, _targetCorrection, 0.02f);
       
        // Easy bit :)
        transform.rotation = _correction * gyroOrientation;
    }
}
using UnityEngine;
using System.Collections;
 
public class GyroCamera : MonoBehaviour {
 
    Quaternion initialRotation;
    Quaternion gyroInitialRotation;
    bool gyroEnabled;
 
    void Start () {
        initialRotation = transform.rotation;
        Input.gyro.enabled = true;
        gyroInitialRotation = Input.gyro.attitude;
    }
 
    void Update() {
        if(gyroEnabled){
        #if !UNITY_EDITOR
            Quaternion offsetRotation = ConvertRotation(Quaternion.Inverse(gyroInitialRotation) * Input.gyro.attitude);
            transform.rotation = initialRotation * offsetRotation;
        #else
            //for unity editor contorl
            float speed = 2.0f;
            transform.Rotate(Input.GetAxis("Mouse Y") * speed, Input.GetAxis("Mouse X") * speed, 0);
        #endif
        }
    }
 
    public void AlignGyro() {
        gyroEnabled = false;
        transform.rotation = Quaternion.identity;
    }
 
    public void StartGyro() {
        initialRotation = transform.rotation;
        gyroInitialRotation = Input.gyro.attitude;
        gyroEnabled = true;
    }
 
    private static Quaternion ConvertRotation(Quaternion q)
    {
        return new Quaternion(q.x, q.y, -q.z, -q.w);  
    }
}

Three Spheres:

Argos LatLong Hex

Argos Voronoi

Argos Fibonacci

—————————————————

Build for Android HandHeld

Build for Android GearVR

ghgdhdfhd

 

gdfgdfngbd