本文整理汇总了C#中Leap.Controller.Frame方法的典型用法代码示例。如果您正苦于以下问题:C# Controller.Frame方法的具体用法?C# Controller.Frame怎么用?C# Controller.Frame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Leap.Controller
的用法示例。
在下文中一共展示了Controller.Frame方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RecordData
/// <summary>
/// Write the data of each frame in the file.
/// </summary>
/// <param name="controller">Controller that represent the device.</param>
/// <param name="path">Path of the file where the data will be write.<br/>
/// If one already exist it will be deleted and a new empty on is created.</param>
public void RecordData(Controller controller, String path)
{
if (Directory.Exists(path) == true)
{
String destination = path + "leapMotion.data";
try
{
if (File.Exists(destination) == true)
File.Delete(destination);
file = File.Create(destination);
}
catch (ArgumentException e)
{
throw e;
}
}
else
throw new System.ArgumentException("Destination path doesn't exist", "path");
BinaryWriter writer = new BinaryWriter(file);
for (int f = 9; f >= 0; f--)
{
Frame frameToSerialize = controller.Frame(f);
byte[] serialized = frameToSerialize.Serialize;
Int32 length = serialized.Length;
writer.Write(length);
writer.Write(serialized);
}
}
示例2: GetBeforeFrame
// 現在のフレームと、直前の5フレームを取得する
static void GetBeforeFrame()
{
Controller leap = new Controller();
long previousFrameId = -1;
while ( true ) {
// 最新のフレームを取得する(leap.Frame( 0 ) と同じ)
var currentFrame = leap.Frame();
if ( previousFrameId == currentFrame.Id ) {
continue;
}
previousFrameId = currentFrame.Id;
// 直前の5フレームを取得する
Console.Write( currentFrame.Id + ", " );
for ( int i = 1; i <= 5; ++i ) {
var previousFrame = leap.Frame( i );
Console.Write( previousFrame.Id + ", " );
}
Console.WriteLine();
}
// 終了処理(onExit()相当)
}
示例3: Start
// Use this for initialization
void Start () {
Application.runInBackground = true;
controller = new Leap.Controller ();
state = State.UP;
previousFingers = new Vector[4];
currentFingers = new Vector[4];
previousFingers [0] = controller.Frame().Hands.Leftmost.Fingers.FingerType(Finger.FingerType.TYPE_MIDDLE)[0].StabilizedTipPosition;
previousFingers [1] = controller.Frame().Hands.Leftmost.Fingers.FingerType(Finger.FingerType.TYPE_INDEX)[0].StabilizedTipPosition;
previousFingers [2] = controller.Frame().Hands.Rightmost.Fingers.FingerType(Finger.FingerType.TYPE_INDEX)[0].StabilizedTipPosition;
previousFingers [3] = controller.Frame().Hands.Rightmost.Fingers.FingerType(Finger.FingerType.TYPE_MIDDLE)[0].StabilizedTipPosition;
}
示例4: OnFrame
public override void OnFrame(Controller leapController)
{
Frame currentFrame = leapController.Frame();
if (handsLastFrame == 0 && currentFrame.Hands.Count > 0 && LeapRegisterFingers != null)
LeapRegisterFingers(true);
else if (handsLastFrame > 0 && currentFrame.Hands.Count == 0 && LeapRegisterFingers != null)
LeapRegisterFingers(false);
handsLastFrame = currentFrame.Hands.Count;
if (currentFrame.Hands.Count > 0 &&
currentFrame.Hands[0].Fingers.Count > 0 &&
LeapSwipe != null)
{
GestureList gestures = currentFrame.Gestures();
foreach (Gesture gesture in gestures)
{
SwipeGesture swipe = new SwipeGesture(gesture);
if (Math.Abs(swipe.Direction.x) > Math.Abs(swipe.Direction.y)) // Horizontal swipe
{
if (swipe.Direction.x > 0)
LeapSwipe(SwipeDirection.Right);
else
LeapSwipe(SwipeDirection.Left);
}
else // Vertical swipe
{
if (swipe.Direction.y > 0)
LeapSwipe(SwipeDirection.Up);
else
LeapSwipe(SwipeDirection.Down);
}
}
}
}
示例5: OnFrame
public override void OnFrame(Controller controller)
{
// Get the most recent frame and report some basic information
var frame = controller.Frame();
try
{
// Update all registered items
lock (_FrameUpdateItems)
{
var item = _FrameUpdateItems.First;
while (item != null)
{
var next = item.Next;
if (!item.Value.Update(frame))
_FrameUpdateItems.Remove(item);
item = next;
}
}
}
catch (Exception e)
{
_LogAction("Exception: " + e.GetType().FullName + "\n" + e.Message + "\n" + e.StackTrace);
}
}
示例6: OnFrame
public override void OnFrame(Controller controller)
{
// Get the most recent frame and report some basic information
Frame frame = controller.Frame();
// Get gestures
// Only handles swipe gesture for now...
GestureList gestures = frame.Gestures();
for (int i = 0; i < gestures.Count; i++)
{
Gesture gesture = gestures[i];
switch (gesture.Type)
{
case Gesture.GestureType.TYPE_SWIPE:
SwipeGesture swipe = new SwipeGesture(gesture);
OnGesture("swipe", swipe.Id, swipe.State.ToString(), swipe.Position.ToFloatArray(), swipe.Direction.ToFloatArray());
break;
case Gesture.GestureType.TYPECIRCLE:
CircleGesture circle = new CircleGesture(gesture);
OnCircleGesture("circle", circle.Id, circle.State.ToString(), circle.Progress, circle.Normal, circle.Pointable);
break;
}
}
}
示例7: OnFrame
public override void OnFrame(Controller controller)
{
Frame frame = controller.Frame();
// Get the first hand
Hand hand = frame.Hands[0];
// Check if the hand has any fingers
FingerList fingers = hand.Fingers;
if (!fingers.Empty)
{
// Calculate the hand's average finger tip position
Vector avgPos = Vector.Zero;
Vector avgVelocity = Vector.Zero;
foreach (Finger finger in fingers)
{
avgPos += finger.TipPosition;
avgVelocity += finger.TipVelocity;
}
avgPos /= fingers.Count;
avgVelocity /= fingers.Count;
List<Gesture.Direction> directions = new List<Gesture.Direction>();
if (avgVelocity.y > 1500)
{
directions.Add(Gesture.Direction.Up);
}
else if (avgVelocity.y < -1500)
{
directions.Add(Gesture.Direction.Down);
}
if (avgVelocity.x > 1500)
{
directions.Add(Gesture.Direction.Left);
}
else if (avgVelocity.x < -1500)
{
directions.Add(Gesture.Direction.Right);
}
if (avgVelocity.z > 1500)
{
directions.Add(Gesture.Direction.Forward);
}
else if (avgVelocity.z < -1500)
{
directions.Add(Gesture.Direction.Backward);
}
if (directions.Count > 0)
{
Gesture gesture = new Gesture(directions.ToArray(), fingers.Count);
onGesture(gesture);
}
//Console.WriteLine("Hand has " + fingers.Count
// + " fingers, average finger tip Velocity: " + avgVelocity);
}
}
示例8: OnFrame
public override void OnFrame(Controller controller)
{
Frame frame = controller.Frame();
foreach (IFrameListener frameListener in frameListeners)
{
frameListener.OnFrame(frame);
}
}
示例9: OnFrame
public override void OnFrame(Controller controller)
{
Frame frame = controller.Frame();
//Console.WriteLine("FRAME");
foreach (IFrameListener frameListener in frameListeners)
{
frameListener.OnFrame(frame);
}
}
示例10: OnFrame
public override void OnFrame( Controller leap )
{
var frame = leap.Frame();
#if true
// 今回のフレームで検出したすべての手、指、ツール
HandList hands = frame.Hands;
FingerList fingers = frame.Fingers;
ToolList tools = frame.Tools;
PointableList pointables = frame.Pointables;
Console.WriteLine( string.Format( "手 : {0} 指 : {1} ツール : {2} ポインタ : {3}",
hands.Count, fingers.Count, tools.Count, pointables.Count ) );
#endif
#if false
// 手のIDから、同じ手を追跡し続ける
if ( handId == -1 ) {
handId = frame.Hands[0].Id;
}
else {
Hand hand = frame.Hand( handId );
handId = hand.Id;
// 手の情報を表示する
Console.WriteLine( string.Format( "ID : {0} 位置 : {1} 速度 : {2} 法線 : {3} 向き : {4}",
hand.Id, hand.PalmPosition, hand.PalmVelocity, hand.PalmNormal, hand.Direction ) );
}
#endif
#if false
// 一番左、右、手前の手を取得する
HandList hands = frame.Hands;
Hand leftMost = hands.Leftmost;
Hand rightMost = hands.Rightmost;
Hand frontMost = hands.Frontmost;
Console.WriteLine( string.Format( "左 : {0} 右 : {1} 手前 : {2}",
leftMost.PalmPosition, rightMost.PalmPosition, frontMost.PalmPosition ) );
#endif
#if false
// 手に属している指とツールを取得する
foreach ( var hand in frame.Hands ) {
Console.WriteLine( string.Format( "ID : {0} ポインタ : {1} 指: {2} ツール : {3}",
hand.Id, hand.Pointables.Count, hand.Fingers.Count, hand.Fingers.Count ) );
}
#endif
#if false
// 指の情報を表示する
Finger finger = frame.Fingers[0];
Console.WriteLine( string.Format( "ID : {0} 位置 : {1} 速度 : {2} 向き : {3}",
finger.Id, finger.TipPosition, finger.TipVelocity, finger.Direction ) );
#endif
}
示例11: OnFrame
public override void OnFrame(Controller controller)
{
var frame = controller.Frame();
if (frame.Hands.IsEmpty) return;
var hand = frame.Hands[0];
var direction = hand.StabilizedPalmPosition;
var moveDirection = new MoveDirection(hand.StabilizedPalmPosition.x, hand.StabilizedPalmPosition.y, hand.StabilizedPalmPosition.z);
Task.Factory.StartNew(() => OnHandMoveOn(direction, moveDirection, hand.Fingers.Count));
}
示例12: AverageFingerPosition
// 指のIDとフレーム履歴を利用して、10フレームの指の平均座標を求める
static void AverageFingerPosition()
{
Controller leap = new Controller();
long previousFrameId = -1;
// 初期化処理(OnInit()相当)をここに書く
// 無限ループ内で、前回のフレームのIDと比較して新しいフレームを取得する
while ( true ) {
var frame = leap.Frame();
if ( previousFrameId == frame.Id ) {
continue;
}
previousFrameId = frame.Id;
//Console.WriteLine( "Frame ID : " + frame.Id );
// フレーム更新処理(OnFrame()相当)をここに書く
//Average a finger position for the last 10 frames
int count = 0;
Vector average = new Vector();
// 最初のに検出された指の平均を取得する
Finger fingerToAverage = frame.Fingers[0];
for ( int i = 0; i < 10; i++ ) {
// 指定したフレームの、指定した指IDの、指データを取得する
Finger fingerFromFrame = leap.Frame( i ).Finger( fingerToAverage.Id );
if ( fingerFromFrame.IsValid ) {
// 取得した指データが有効であれば平均値の算出に利用する
average += fingerFromFrame.TipPosition;
count++;
}
average /= count;
}
// 平均値を表示する
Console.WriteLine( average );
}
// 終了処理(OnExit()相当)をここに書く
}
示例13: OnFrame
public override void OnFrame(Controller controller)
{
var h = FrameArrived;
if (h != null)
{
using (var frame = controller.Frame())
{
h(frame);
}
}
}
示例14: OnFrame
public override void OnFrame(Controller controller)
{
Frame frame = controller.Frame();
SafeWriteLine("Frame id: " + frame.Id
+ ", timestamp: " + frame.Timestamp
+ ", hands: " + frame.Hands.Count
+ ", fingers: " + frame.Fingers.Count
+ ", tools: " + frame.Tools.Count
+ ", gestures: " + frame.Gestures().Count);
}
示例15: OnFrame
public override void OnFrame(Controller ctrl)
{
//Get the current frame
Frame currentFrame = ctrl.Frame();
this.currentTime = currentFrame.Timestamp;
this.timeChange = currentTime - previousTime;
if (this.timeChange < 1000 || currentFrame.Hands.IsEmpty)
return;
//Get the first finger
Finger finger = currentFrame.Fingers[0];
//Get the closest screen that intercepts a ray projected from the finger
Screen screen = ctrl.LocatedScreens.ClosestScreenHit(finger);
//Get finger tip's velocity
float tipVelocity = (int)finger.TipVelocity.Magnitude;
/*only print info when velocity exceeds a certain threshold,
so that the slightest movements won't continuously output
data to the screen*/
if (screen == null || !screen.IsValid || tipVelocity <= 25)
return;
Vector vector = screen.Intersect(finger, true);
//x and y positions are sometimes returned as NaN (e.g. if hand is partly obscured by screen)
if (float.IsNaN(vector.x) || float.IsNaN(vector.y))
return;
float xScreenIntersect = vector.x;
float yScreenIntersect = vector.y;
float x = xScreenIntersect * screen.WidthPixels;
float y = screen.HeightPixels - (yScreenIntersect * screen.HeightPixels);
Result result = new Result
{
X = (int)x,
Y = (int)y,
XIntersect = xScreenIntersect,
YIntersect = yScreenIntersect,
ScreenWidth = screen.WidthPixels,
ScreenHeight = screen.HeightPixels,
TipVelocity = tipVelocity
};
this.reporter.Print(result);
previousTime = currentTime;
}