devNotes 11-24-2016 Compute Shader Stylus

 

sdgfgfgfggf

 

using UnityEngine;
using System.Collections;
using ArgosTweenSpacePuppy;
using VRTK;
using UnityEngine.UI;
using System;

public class Fine_Tune_Controller_Adjuster : MonoBehaviour
{
    public bool bFineTuner_On = false;
    public bool bStylus_On = false;
    private bool bGripPressed;
    Vector3 vEuler;
    public GameObject Fine_Tuner_Cowling_Prefab;
    private GameObject inst_Fine_Tuner_Cowling;
    public GameObject Stylus_Prefab;
    private GameObject inst_Stylus;
    public float zExtended_FT = 3f;
    public float tweenDuration_FT = 1.618f;
    private float normZ_FT = 0;
    private float tAccum_FT = 0;
    private float base_Scale_FT = 1f;

    public float zExtended_STYL = 3f;
    public float tweenDuration_STYL = 1.618f;
    private float normZ_STYL = 0;
    private float tAccum_STYL = 0;
    private float base_Scale_STYL = 1f;

    float lastVal = 0;
    private float lerpValBack = 0;
    public float return_Duration;
    public float throttle_Value;

    public int stay_count = 0;
    public Vector3 orgPos;

    private UI_Ladder ui_Ladder;

    // Use this for initialization
    void Start ()
    {
        //GetComponent<VRTK_ControllerEvents>().ApplicationMenuPressed += new ControllerInteractionEventHandler(DoApplicationMenuPressed);
        GetComponent<VRTK_ControllerEvents>().GripPressed += new ControllerInteractionEventHandler(DoGripPressed);
        GetComponent<VRTK_ControllerEvents>().GripReleased += new ControllerInteractionEventHandler(DoGripReleased);

        inst_Fine_Tuner_Cowling = (GameObject)Instantiate(Fine_Tuner_Cowling_Prefab,transform);
        Vector3 v = inst_Fine_Tuner_Cowling.transform.localPosition; 
        v.z -= zExtended_FT;
        inst_Fine_Tuner_Cowling.transform.localPosition = v;
        inst_Fine_Tuner_Cowling.SetActive(false);
        base_Scale_FT = inst_Fine_Tuner_Cowling.transform.localScale.x;

        inst_Stylus = (GameObject)Instantiate(Stylus_Prefab, transform);
        v = inst_Stylus.transform.localPosition;
        v.z -= zExtended_FT;
        inst_Stylus.transform.localPosition = v;
        inst_Stylus.SetActive(false);
        base_Scale_STYL = inst_Stylus.transform.localScale.x;

        ui_Ladder = UI_Ladder.Instance;
        ui_Ladder.Stylus_Parameter_Update += new UI_Ladder.Stylus_Update_Event_Handler(Do_Stylus_Update);
    }

    private void Do_Stylus_Update(object sender, EventArgs e)
    {
        if(bStylus_On)
            inst_Stylus.GetComponent<Stylus>().Update_Stylus_From_UI();
    }


    public void Controller_FineTune_Button(bool bOn)
    {
        bFineTuner_On = !bFineTuner_On;

        if (bFineTuner_On)
        {
            inst_Fine_Tuner_Cowling.SetActive(true);
            StopCoroutine("Tween_Pos_Fine_Tuner");
            StartCoroutine("Tween_Pos_Fine_Tuner", true);
        }
        else
        {
            //inst_Fine_Tuner_Cowling.SetActive(false);
            StopCoroutine("Tween_Pos_Fine_Tuner");
            StartCoroutine("Tween_Pos_Fine_Tuner", false);
        }
    }

    public void Controller_Stylus_Button(bool bOn)
    {
        bStylus_On = !bStylus_On;

        if (bStylus_On)
        {
            inst_Stylus.SetActive(true);
            Do_Stylus_Update(this, EventArgs.Empty);
            StopCoroutine("Tween_Pos_Stylus");
            StartCoroutine("Tween_Pos_Stylus", true);
        }
        else
        {
            //inst_Fine_Tuner_Cowling.SetActive(false);
            StopCoroutine("Tween_Pos_Stylus");
            StartCoroutine("Tween_Pos_Stylus", false);
        }
    }

    private void DoGripPressed(object sender, ControllerInteractionEventArgs e)
    {
        bGripPressed = true;
    }

    private void DoGripReleased(object sender, ControllerInteractionEventArgs e)
    {
        bGripPressed = false;
    }

    private IEnumerator Tween_Pos_Fine_Tuner(bool show)
    {
        float dir = 1;

        if (!show)
        {
            dir = -1;
        }

        int i = 0; //Sanity check for infinite loops

        float linProg = tAccum_FT / tweenDuration_FT;

        while (i < 180 && ((show && linProg < 1) || (!show && linProg > 0)))
        {
            tAccum_FT += dir * Time.deltaTime;
            linProg = tAccum_FT / tweenDuration_FT;
            Mathf.Clamp(tAccum_FT, 0, tweenDuration_FT);

            normZ_FT = EaseMethods.CircleEaseInOut(tAccum_FT, 0, 1, tweenDuration_FT);
            Set_FineTuner_Position(normZ_FT);

            yield return true;
            i++;
        }

        if (show)
        {
            tAccum_FT = tweenDuration_FT;
            normZ_FT = 1;
        }
        else
        {
            tAccum_FT = 0;
            normZ_FT = 0;
            inst_Fine_Tuner_Cowling.SetActive(false);
        }
        Set_FineTuner_Position(normZ_FT);
        StopCoroutine("Tween_Pos_Fine_Tuner");
    }

    private IEnumerator Tween_Pos_Stylus(bool show)
    {
        float dir = 1;

        if (!show)
        {
            dir = -1;
        }

        int i = 0; //Sanity check for infinite loops

        float linProg = tAccum_STYL / tweenDuration_STYL;

        while (i < 180 && ((show && linProg < 1) || (!show && linProg > 0)))
        {
            tAccum_STYL += dir * Time.deltaTime;
            linProg = tAccum_STYL / tweenDuration_STYL;
            Mathf.Clamp(tAccum_STYL, 0, tweenDuration_STYL);

            normZ_STYL = EaseMethods.CircleEaseInOut(tAccum_STYL, 0, 1, tweenDuration_STYL);
            Set_Stylus_Position(normZ_STYL);

            yield return true;
            i++;
        }

        if (show)
        {
            tAccum_STYL = tweenDuration_STYL;
            normZ_STYL = 1;
        }
        else
        {
            tAccum_STYL = 0;
            normZ_STYL = 0;
            inst_Stylus.SetActive(false);
        }
        Set_Stylus_Position(normZ_STYL);
        StopCoroutine("Tween_Pos_Stylus");
    }

    public void Set_FineTuner_Position(float normZ)
    {
        Vector3 v = Vector3.zero;
        v.z = zExtended_FT * (normZ - 1);
        inst_Fine_Tuner_Cowling.transform.localPosition = v;

        Vector3 vScale = base_Scale_FT * Vector3.one * normZ;
        inst_Fine_Tuner_Cowling.transform.localScale = vScale;
    }

    public void Set_Stylus_Position(float normZ)
    {
        Vector3 v = Vector3.zero;
        v.z = zExtended_STYL * (normZ - 1);
        inst_Stylus.transform.localPosition = v;
        Vector3 vScale = base_Scale_STYL * Vector3.one * normZ;
        inst_Stylus.transform.localScale = vScale;
    }

    bool bReturn = false;
    float accumTime;
    float initVal;
    void Update()//positive - 60 to left - 360  300 to the right
    {
        if (bFineTuner_On && bGripPressed)
        {
            vEuler = transform.localRotation.eulerAngles;
            vEuler.x = 0;
            vEuler.y = 0;

            float val = vEuler.z;

            if (val > 60f && val < 180f) val = 60f;
            if (val < 300f && val > 180f) val = 300f;
            float setVal = val;

            if (val < 300f)//60 range
            {
                val = -(val / 60f);
            }
            else
            {
                val = (360f - val) / 60f;
            }
            lastVal = val;
            throttle_Value = val;

            UI_Ladder.Instance.Set_FineTune_Val(throttle_Value);

            ushort aPulse = (ushort)(Mathf.Abs(throttle_Value * throttle_Value * 800));
            GetComponent<VRTK_ControllerActions>().TriggerHapticPulse(aPulse);
            bReturn = false;
        }
        else
        {
            UI_Ladder.Instance.Set_FineTune_Val(0);
        }
    }
}

 

using UnityEngine;
using System.Collections;
using ProceduralToolkit;

public class Stylus : MonoBehaviour
{
    private MeshDraft stylus_MD;
    private MeshDraft boundary_MD;
    Vector3[] vSphereCenters = new Vector3[12];
    float[] fRadii = new float[12];
    UI_Ladder ui_Ladder;
    Vector3 vMarker_Position;
    public GameObject boundary_Render;

	void Awake()
    {
        ui_Ladder = UI_Ladder.Instance;
        stylus_MD = new MeshDraft();
        boundary_MD = new MeshDraft(); 
        GetComponent<MeshFilter>().mesh = stylus_MD.ToMesh();

        vMarker_Position = GetComponentInChildren<Marker_Stylus>().transform.localPosition;
    }

	public void Update_Stylus_From_UI()
    {
        float r1                = UI_Ladder.Instance.stylus_Radius_Root;
        float r2                = UI_Ladder.Instance.stylus_Radius_Tip;
        int num_ATT             = UI_Ladder.Instance.stylus_Num_Attractors;
        float stylus_Len        = UI_Ladder.Instance.stylus_Length;
        float stylus_Boundary   = UI_Ladder.Instance.stylus_Boundary;

        float sum = 0f;
        for (int i = 0; i<num_ATT; i++)
        {
            fRadii[i] = r1 + i * (r2 - r1) / num_ATT;
            sum += fRadii[i];
        }
        float wLen = 0;
        stylus_MD.Clear();
        boundary_MD.Clear();
        for (int j = 0; j< num_ATT; j++)
        {
            wLen += fRadii[j];
            vSphereCenters[j] = Vector3.forward * (wLen / sum) * stylus_Len;
            stylus_MD.Add(MeshDraft.Sphere_Offset(fRadii[j], 12, 12, vSphereCenters[j] + vMarker_Position));
            boundary_MD.Add(MeshDraft.Sphere_Offset(fRadii[j]*(1 + stylus_Boundary), 12, 12, vSphereCenters[j] + vMarker_Position));
        }
        GetComponent<MeshFilter>().mesh = stylus_MD.ToMesh();
        boundary_Render.GetComponent<MeshFilter>().mesh = boundary_MD.ToMesh();
    }
}

Untitled-18