本文整理汇总了C#中Leap.Vector.AngleTo方法的典型用法代码示例。如果您正苦于以下问题:C# Vector.AngleTo方法的具体用法?C# Vector.AngleTo怎么用?C# Vector.AngleTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Leap.Vector
的用法示例。
在下文中一共展示了Vector.AngleTo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnFrame
public override void OnFrame(Controller controller)
{
using (var frame = controller.Frame())
{
Vector A = new Vector(2, 0, 0);
Vector B = new Vector(4, 2, 0);
double rads = Math.Round(A.AngleTo(B), 2);
Console.WriteLine("Radians " + rads);
Console.WriteLine("Degrees " + Math.Round(rads*180/Math.PI, 2));
//Console.WriteLine("Thumb: " + Math.Round(frame.Fingers[0].Length / 10, 2) + "cm");
//Console.WriteLine("Index: " + Math.Round(frame.Fingers[1].Length / 10, 2) + "cm");
//Console.WriteLine("Middle: " + Math.Round(frame.Fingers[2].Length / 10, 2) + "cm");
//Console.WriteLine("Ring: " + Math.Round(frame.Fingers[3].Length / 10, 2) + "cm");
//Console.WriteLine("Pinky: " + Math.Round(frame.Fingers[4].Length / 10, 2) + "cm\n");
}
Console.ReadLine();
//Thread.Sleep(2000);
//using (var frame = controller.Frame())
//{
// _now = frame.Timestamp;
// _timeDifference = _now - _previous;
// if (frame.Hands.IsEmpty || _timeDifference < 5000)
// {
// return;
// }
// _previous = frame.Timestamp;
// if (frame.Gestures().Count > 0 && OnGesturesMade != null)
// {
// OnGesturesMade(frame.Gestures());
// }
// if (frame.Fingers.Count > 0 && OnFingersRegistered != null)
// {
// OnFingersRegistered(frame.Fingers);
// }
//}
}
示例2: VerDirToYAxis
bool VerDirToYAxis(Vector dir, float threshold)
{
bool isVer = false;
float radian = dir.AngleTo(Vector.YAxis);
if(radian>threshold && radian<(Mathf.PI - threshold))
{
isVer = true;
}
return isVer;
}
示例3: Update
// Update is called once per frame
void Update()
{
int clickIndex;
//这里的判定本该分成预备状态、运动状态、终结状态。但是对于点击来讲,这三个状态的手势判定条件都相同(手势相同、阈值相同)
//所以现在都用同一个控制器来表示
if (EnterClickState(out clickIndex))
{
//初始状态
if(!m_IsEnteredClick)
{
//标记进入点击状态,记录初始位置
m_IsEnteredClick = true;
m_EnterPos = m_HandData.FingerDatas[clickIndex][Finger.FingerType.TYPE_INDEX].m_Point.m_Position;
m_PreviousPos = m_EnterPos;
//延迟触发初始事件
StartCoroutine(EnterClickDelay());
}
//非初始状态
else
//不是反弹状态
if(!m_IsEnteredBackClick)
{
m_DeepClickingTime+=Time.deltaTime;
//是否进入一次位置判定
if (m_DeepClickingTime > CheckTimeStep)
{
m_DeepClickingTime = 0f;
//收集当前手指索引的食指指尖位置数据
Vector indexFingerTipPos = m_HandData.FingerDatas[clickIndex][Finger.FingerType.TYPE_INDEX].m_Point.m_Position;
m_Off = indexFingerTipPos - m_PreviousPos;
//是向前点击状态,偏移向量与-z轴(Leap坐标系)的夹角小于某个阈值
if(m_Off.AngleTo(-Vector.ZAxis)<DeepClickRadianThreshold)
//if (indexFingerTipPos.z < m_PreviousPos.z)
{
float deep = m_EnterPos.z - indexFingerTipPos.z;
//是反弹状态
if( deep > DeepThreshold )
{
//标记进入了反弹状态,记录反弹状态的位置
m_IsEnteredBackClick = true;
m_EnterBackPos = indexFingerTipPos;
if(m_OnBackFunc != null)
{
// print("aaa");
m_OnBackFunc();
}
}
}
//不是前进状态
else
{
//手势匹配失败,重置变量
ResetClickState();
}
//更新m_PreviousPos的位置
m_PreviousPos = indexFingerTipPos;
}
}
else //进入了返回状态
{
m_BackClickingTime+=Time.deltaTime;
//进入位置判定
if ( m_BackClickingTime > CheckTimeStep )
{
m_BackClickingTime = 0f;
Vector indexFingerTipPos = m_HandData.FingerDatas[clickIndex][Finger.FingerType.TYPE_INDEX].m_Point.m_Position;
//是后退状态
if (m_PreviousPos.z < indexFingerTipPos.z)
{
float backDeep = indexFingerTipPos.z - m_EnterBackPos.z;
//满足了反弹阈值
if( backDeep > BackThreshold )
{
print("Clicked");
//触发事件,重置状态
if (m_OnClicked!=null)
{
print("Clicked()");
m_OnClicked();
}
ResetClickState();
}
}
}
}
}
//不是手指点击状态
else
{
ResetClickState();
m_IsEnteredClick = false;
}
}
示例4: IsHorAndForwardOpenHand
/// <summary>
/// 判定一个摊开手掌的状态是否是水平向前
/// </summary>
/// <returns><c>true</c>, if and forward open hand was hored, <c>false</c> otherwise.</returns>
bool IsHorAndForwardOpenHand(Vector palmDir,Vector fingerDir )
{
bool isHorAndForward = false;
if( fingerDir.AngleTo(-Vector.ZAxis) < ForwardThreshold &&
palmDir.AngleTo(-Vector.YAxis) < DownThreshold )
{
isHorAndForward=true;
}
return isHorAndForward;
}
示例5: IsPointAsClickForwardDir
/// <summary>
/// 判定一个手指指向是否是点击前方
/// 这里阈值的判定与其说是+x轴,倒不如说是距离yz面的夹角程度更直接,但实现方式上选择了+x轴。
/// </summary>
/// <param name="dir"></param>
/// <param name="threshold">表示距离+x的夹角,标准是90度</param>
bool IsPointAsClickForwardDir(Vector dir,float threshold)
{
bool IsPointAsClick = false;
float radian = dir.AngleTo(Vector.Right);
if (radian > threshold && radian < Mathf.PI - threshold)
{
IsPointAsClick = true;
}
return IsPointAsClick;
}