添加了旋转方法
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
/*
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Models
|
||||
@@ -23,4 +24,5 @@ namespace Models
|
||||
public Quaternion currentQ;
|
||||
//该骨骼节点的当前角度
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace Models
|
||||
{
|
||||
@@ -21,7 +22,7 @@ namespace Models
|
||||
/// <summary>
|
||||
/// MediaPipe捕捉空间坐标
|
||||
/// </summary>
|
||||
public Vector3 MediaPipePos;
|
||||
public Vector3 MediaPipePos;
|
||||
|
||||
/// <summary>
|
||||
/// 节点的父节点列表
|
||||
@@ -57,6 +58,35 @@ namespace Models
|
||||
public void CalculateCurrentQuaternion(PoseLandmark landmark)
|
||||
{
|
||||
|
||||
//var temp = _posLandmarks.Find(t=>t.mediaPipeName == landmark.Type.ToString());
|
||||
var sum = new Vector3(0,0,0);
|
||||
|
||||
if (landmark.Visibility > 0.6)
|
||||
{
|
||||
var temp = new Vector4(landmark.X, landmark.Y, landmark.Z, 1);
|
||||
|
||||
|
||||
MediaPipePos = new Vector3(-temp.x, -temp.y, -temp.z);
|
||||
|
||||
}
|
||||
|
||||
if (UnityName != HumanBodyBones.LastBone)
|
||||
{
|
||||
Debug.Log(UnityName+".MediaPipePos:"+MediaPipePos);
|
||||
}
|
||||
|
||||
foreach (var parents in Parent)
|
||||
{
|
||||
|
||||
sum += parents.MediaPipePos;
|
||||
//Debug.Log("parents:"+parents.UnityName+".MediaPipePos:"+parents.MediaPipePos);
|
||||
|
||||
}
|
||||
//Debug.Log("sum:"+sum);
|
||||
var currentPos = sum / Parent.Count;
|
||||
|
||||
CurrentQuaternion = Quaternion.LookRotation(MediaPipePos - currentPos);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -104,5 +134,51 @@ namespace Models
|
||||
}
|
||||
|
||||
|
||||
//绕X轴旋转
|
||||
private Matrix4x4 RotateAxisX(float rot)
|
||||
{
|
||||
var matrix = new Matrix4x4();
|
||||
float cosrot = MathF.Cos(rot);
|
||||
float sinrot = MathF.Sin(rot);
|
||||
|
||||
matrix.SetRow(0, new Vector4(1,0,0,0));
|
||||
matrix.SetRow(1, new Vector4(0,cosrot,-sinrot,0));
|
||||
matrix.SetRow(2, new Vector4(0,sinrot,cosrot,0));
|
||||
matrix.SetRow(3, new Vector4(0,0,0,1));
|
||||
|
||||
return matrix;
|
||||
}
|
||||
|
||||
//绕Y轴旋转
|
||||
private Matrix4x4 RotateAxisY(float rot)
|
||||
{
|
||||
var matrix = new Matrix4x4();
|
||||
float cosrot = MathF.Cos(rot);
|
||||
float sinrot = MathF.Sin(rot);
|
||||
|
||||
matrix.SetRow(0, new Vector4(cosrot,0,sinrot,0));
|
||||
matrix.SetRow(1, new Vector4(0,1,0,0));
|
||||
matrix.SetRow(2, new Vector4(-sinrot,0,cosrot,0));
|
||||
matrix.SetRow(3, new Vector4(0,0,0,1));
|
||||
|
||||
return matrix;
|
||||
}
|
||||
|
||||
//绕Z轴旋转
|
||||
private Matrix4x4 RotateAxisZ(float rot)
|
||||
{
|
||||
var matrix = new Matrix4x4();
|
||||
float cosrot = MathF.Cos(rot);
|
||||
float sinrot = MathF.Sin(rot);
|
||||
|
||||
matrix.SetRow(0, new Vector4(cosrot,-sinrot,0,0));
|
||||
matrix.SetRow(1, new Vector4(sinrot,cosrot,0,0));
|
||||
matrix.SetRow(2, new Vector4(0,0,1,0));
|
||||
matrix.SetRow(3, new Vector4(0,0,0,1));
|
||||
|
||||
return matrix;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user