tmp

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

namespace InverseKinematics
{
public class JointController : MonoBehaviour
{

    // robot
    private GameObject[] joint = new GameObject[2];
    private GameObject[] arm = new GameObject[2];
    private float[] armL = new float[2];
    private Vector3[] angle = new Vector3[2];

    // UI
    private GameObject[] slider = new GameObject[2];
    private float[] sliderVal = new float[2];
    private GameObject[] angText = new GameObject[2];
    private GameObject[] posText = new GameObject[2];

    void Start()
    {
        // robot
        for (int i = 0; i < joint.Length; i++)
        {
            joint[i] = GameObject.Find("Joint_" + i.ToString());
            arm[i] = GameObject.Find("Arm_" + i.ToString());
            armL[i] = arm[i].transform.localScale.x;
        }

        // UI settings
        for (int i = 0; i < joint.Length; i++)
        {
            slider[i] = GameObject.Find("Slider_" + i.ToString());
            angText[i] = GameObject.Find("Angle_" + i.ToString());
            sliderVal[i] = slider[i].GetComponent<Slider>().value;
        }
        posText[0] = GameObject.Find("Pos_X");
        posText[1] = GameObject.Find("Pos_Y");

    }

    void Update()
    {

        for (int i = 0; i < joint. Length; i ++) {
            sliderVal[i] = slider[i]. GetComponent<Slider>().value;
            angText[i].GetComponent<TMP_Text>().text = sliderVal[i].ToString("f2");
            angle[i].z = sliderVal[i];
            joint[i].transform.localEulerAngles = angle[i];
        }
        float px = armL[0] * Mathf.Cos( angle[0].z * Mathf.Deg2Rad) + armL[1] * Mathf.Cos(( angle[0].z + angle[1].z) * Mathf.Deg2Rad);
        float py = armL[0] * Mathf.Sin( angle[0].z * Mathf.Deg2Rad) + armL[1] * Mathf.Sin(( angle[0].z + angle[1].z) * Mathf.Deg2Rad);
        posText[0].GetComponent<TMP_Text>().text = px.ToString("f2");
        posText[1].GetComponent<TMP_Text>().text = py.ToString("f2");

    }

}

}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

namespace InverseKinematics
{
public class JointController2 : MonoBehaviour
{

    // robot
    private GameObject[] joint = new GameObject[2];
    private GameObject[] arm = new GameObject[2];
    private float[] armL = new float[2];
    private Vector3[] angle = new Vector3[2];

    // UI
    private GameObject[] slider = new GameObject[2];
    private float[] sliderVal = new float[2];
    private GameObject[] angText = new GameObject[2];
    private GameObject[] posText = new GameObject[2];

    void Start()
    {
        // robot
        for (int i = 0; i < joint.Length; i++)
        {
            joint[i] = GameObject.Find("Joint_" + i.ToString());
            arm[i] = GameObject.Find("Arm_" + i.ToString());
            armL[i] = arm[i].transform.localScale.x;
        }

        // UI settings
        for (int i = 0; i < joint.Length; i++)
        {
            slider[i] = GameObject.Find("Slider_" + i.ToString());
            sliderVal[i] = slider[i].GetComponent<Slider>().value;
            posText[i] = GameObject.Find("Ref_" + i.ToString());
            angText[i] = GameObject.Find("Ang_" + i.ToString());
        }
    }

    void Update()
    {

        for (int i = 0; i < joint.Length; i++)
        {
            sliderVal[i] = slider[i].GetComponent<Slider>().value;
        }
        float x = sliderVal[0];
        float y = sliderVal[1];
        float a = Mathf.Acos((armL[0] * armL[0] + armL[1] * armL[1] - x * x - y * y) / (2f * armL[0] * armL[1]));
        float b = Mathf.Acos((armL[0] * armL[0] + x * x + y * y - armL[1] * armL[1]) / (2f * armL[0] * Mathf.Pow((x * x + y * y), 0.5f)));
        angle[1].z = -Mathf.PI + a;
        angle[0].z = Mathf.Atan2(y, x) + b;
        for (int i = 0; i < joint.Length; i++)
        {
            joint[i].transform.localEulerAngles = angle[i] * Mathf.Rad2Deg;
            posText[i].GetComponent<TMP_Text>().text = sliderVal[i].ToString("f2");
        }
        angText[0].GetComponent<TMP_Text>().text = (angle[0].z * Mathf.Rad2Deg). ToString("f2");
        angText[1].GetComponent<TMP_Text>().text = (angle[1].z * Mathf.Rad2Deg). ToString("f2");

    }

}

}

>画像という分野

画像という分野

画像に関連することを網羅していきます。

ぜひお時間がある方はのぞいてみてください。

CTR IMG