Unity接口函数Vector3.Project()

来源:互联网 发布:网络媒介推广 编辑:程序博客网 时间:2024/05/16 14:00
using UnityEngine;using System.Collections;/// <summary>/// Vector3.Project()函数测试。/// </summary>public class Vector3_Project : MonoBehaviour{    public Transform m_from_T;    public Transform m_to_T;    /// <summary>    /// 向量的公共点    /// </summary>    public Transform m_comm_T;    private Vector3 m_projects = Vector3.zero;    // Update is called once per frame    void Update()    {        m_projects = Vector3.Project(m_from_T.position - m_comm_T.position, m_to_T.position - m_comm_T.position);        /// 绘制源向量的辅助线        Debug.DrawLine(m_comm_T.position, m_from_T.position, Color.blue);        /// 绘制投影的目标向量的辅助线        Debug.DrawLine(m_comm_T.position, m_to_T.position + (m_to_T.position - m_comm_T.position).normalized * 100f, Color.red);        Debug.DrawLine(m_to_T.position, m_comm_T.position + (m_comm_T.position - m_to_T.position).normalized * 100f, Color.red);        /// 绘制投影在目标向量的结果向量        Debug.DrawLine(m_comm_T.position, m_comm_T.position + m_projects, Color.black);        Vector3 p1 = m_comm_T.position + m_projects;        Vector3 v1 = p1 - m_from_T.position;        /// 绘制开始向量到投影点的垂线。        Debug.DrawLine(m_from_T.position, m_from_T.position + v1.normalized * 100f, Color.green);    }}
</pre><pre name="code" class="csharp"><p>测试函数</p><p>static function <em>Project</em> (<em>vector</em> : <a target=_blank href="">Vector3</a>, <em>onNormal</em> : <a target=_blank href="">Vector3</a>) : <a target=_blank href="">Vector3</a> </p>

0 0
原创粉丝点击