Unity ScriptingAPI Vector3学习

本文详细介绍了Unity中Vector3结构的用途、静态变量、普通变量、构造函数、方法以及各种操作符,包括点乘、线性插值、角度计算等,帮助开发者理解和运用3D向量。

链接:http://docs.unity3d.com/ScriptReference/Vector3.html

Vector3

struct in UnityEngine

描述

Representation of 3D vectors and points.
表示3D向量或点。

This structure is used throughout Unity to pass 3D positions and directions around. It also contains functions for doing common vector operations.
此结构用来贯穿整个Unity3D位置和方向的转换。也包括一般向量操作方法。

Besides the functions listed below, other classes can be used to manipulate vectors and points as well. For example the Quaternion and the Matrix4x4 classes are useful for rotating or transforming vectors and points.
除了以下列出的方法,其他类也有操作向量和位置的方法。例如Quaternion和Matrix4x4……

静态变量

  • back 代表(0,0,-1)
  • down 代表(0,-1,0)
  • forward 代表(0,0,1)
  • left 代表(-1,0,0)
  • one 代表(1,1,1)单位向量
  • right 代表(1,0,0)
  • up 代表(0,1,0)
  • zero 代表(0,0,0)
    这里写图片描述

普通变量

  • magnitude 返回向量的长度(模),只读
  • normalized 返回该向量对应的单位向量, 不是one,只读
  • sqrManitude 返回长度的平方,只读
  • this[int] 下标[0][1][2]代表x,y,z
  • x
  • y
  • z

构造函数

public Vector3(float x, float y, float z);

普通方法

public void Set(float new_x, float new_y, float new_z);

Set函数

public string ToString();
public string ToString(string format);

返回向量对应的格式化字符串

操作符

operator - 向量相减
operator != 向量判等,返回bool
operator * 数乘
operator / 数除
operator + 向量相加
operator == 向量判等,返回bool

静态方法(常用)

public static float Angle(Vector3 from, Vector3 to);

返回两向量间角度,不是弧度,数值不超过180。

public static Vector3 ClampMagnitude(Vector3 vector, float maxLength);

限制向量vector长度为maxLength,若vector.magnitude > maxLegth, 返回值叫vector缩小

public static float Distance(Vector3 a, Vector3 b);

Distance函数返回向量的距离,为(a-b).magnitude

public static float Dot(Vector3 lhs, Vector3 rhs);

两向量点乘,为(|a| * |b| * cos(angle))

public static Vector3 Lerp(Vector3 from, Vector3 to, float t);

线性插值两个向量,t=0,返回from,t=1,返回to,一般采用Vector3.Lerp(startPoint, endPoint, Time.deltaTime * xx)实现平滑移动

public static Vector3 Max(Vector3 lhs, Vector3 rhs);
public static Vector3 Min(Vector3 lhs, Vector3 rhs);

返回两向量x,y,z对应坐标的最大或者最小值

public static Vector3 MoveTowards(Vector3 current, Vector3 target, float maxDistanceDelta);

current向 target移动,maxDistanceDelta为每秒的距离

public void Normalize();

取单位向量。

public static Vector3 Project(Vector3 vector, Vector3 onNormal);

将vector投影到onNormal上。
这里写图片描述

public static void OrthoNormalize(ref Vector3 normal, ref Vector3 tangent);

取normal的单位向量,然后取tangent的单位向量,并与normal正交。

public static void OrthoNormalize(ref Vector3 normal, ref Vector3 tangent, ref Vector3 binormal);

去normal的单位向量,然后去tangent的单位向量,并与normal正交;去binormal单位向量,并与normal和tangent分别正交。

public static Vector3 ProjectOnPlane(Vector3 vector, Vector3 planeNormal);

投影vector到以planeNormal为法向量的平面上。

public static Vector3 Reflect(Vector3 inDirection, Vector3 inNormal);

反射indirection,以inNormal为法向量的平面为反射面。
这里写图片描述

public static Vector3 RotateTowards(Vector3 current, Vector3 target, float maxRadiansDelta, float maxMagnitudeDelta);

与MoveTowards不同之处在于这里current代表的是方向而非点。

public static Vector3 Scale(Vector3 a, Vector3 b);

(1,2,3)*(2,3,4) = (2,6,12)

public static Vector3 Slerp(Vector3 from, Vector3 to, float t);

球面插值

public static Vector3 SmoothDamp(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime, float maxSpeed = Mathf.Infinity, float deltaTime = Time.deltaTime);

平滑阻尼,向量由一些像弹簧阻尼器函数平滑,这将永远不会超过。最常见的用途是平滑跟随相机,例如下:

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    public Transform target;
    public float smoothTime = 0.3F;
    private Vector3 velocity = Vector3.zero;
    void Update() {
        Vector3 targetPosition = target.TransformPoint(new Vector3(0, 5, -10));
        transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
    }
}
内容概要:CLV-40A1-FM是一款符合CPCI标准的AFDX/ARINC-664 Part7协议光纤接口仿真板卡,由成都科洛威尔科技有限公司生产,主要用于航空电子全双工交换以太网的ES端系统测试与仿真。该板卡支持最多4路SFP光纤接口,可在冗余或独立模式下运行,支持2048个发送和接收虚拟链路(VL),具备全硬件协议处理能力,支持多种接收模式(VL接收、VL监控、顺序监控)、BAG调度发送、EDE校验、故障注入、时间戳、硬件BAG生成等功能,并提供丰富的状态指示与中断机制。板卡支持Windows、Linux等多种操作系统,配备DMA与大容量缓存,适用于高可靠性航空总线的仿真与测试场景。; 适合人群:从事航空电子系统开发、测试的工程师,具备嵌入式系统或通信协议基础的研发人员,以及需要进行AFDX总线仿真与验证的技术团队;; 使用场景及目标:①用于AFDX网络中端系统(ES)的功能仿真与协议一致性测试;②支持双冗余网络架构下的容错性验证与数据同步分析;③实现高精度数据收发控制、故障注入测试及总线监控;④适用于实验室研发、地面测试系统及机载设备集成验证; 阅读建议:建议结合《快速使用手册》和《API函数使用手册》进行开发与调试,重点关注VL配置、BAG调度、硬件资源限制(如缓存带宽)等内容,确保系统设计满足实时性与稳定性要求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值