1、标量和矢量的乘法和除法
2、矢量之间的加减法
加法:点从原始位置按照指定的速度矢量移动到新的位置。
Vector3 location = new Vector3(1,2,3);
Vector3 speed = new Vector3(4,5,6);
float time = 0.2f;
Vector3 newLocation = location + speed * time;
3、矢量取模
获取矢量的长度
Vector3 vector = new Vector3(7,8,9);
float ma = MathF.Sqrt(MathF.Pow(vector.X,2)+MathF.Pow(vector.Y,2)+MathF.Pow(vector.Z,2));
4、单位矢量
5、点积、标量积、内积
Vector3 a = new Vector3();
Vector3 b = new Vector3();
float d = a.X * b.X + a.Y * b.Y + a.Z * b.Z;
应用
- 求方向:整数相同,负数相反,0垂直
//敌人在玩家的前方还是后方
Vector3 enemyPos = new Vector3();
Vector3 playerPos = new Vector3();
Vector3 playerForward = new Vector3();
Vector3 enemy2Player = enemyPos - playerPos;
//d大于零,方向相同。d小于0方向相反
float d = Vector3.Dot(enemy2Player,playerForward);
6、叉积、矢量积,外积
留言