private void ButtonClick(object sender, EventArgs e) { handTracker = HandTracker.Create(); btn_start.Enabled = false; HandleError(handTracker.StartGestureDetection(GestureData.GestureType.HandRaise)); handTracker.OnNewData += HandTrackerOnNewData; }
private void NiTeOnNewData(HandTracker handTracker) { try { if (Settings.Default.SmartCam && this.uTracker != null && this.uTracker.IsValid && this.hTracker != null && this.hTracker.IsValid) { using (UserTrackerFrameRef userframe = this.uTracker.ReadFrame()) { using (HandTrackerFrameRef handframe = this.hTracker.ReadFrame()) { foreach (GestureData gesture in handframe.Gestures) { if (!gesture.IsComplete) { continue; } PointF handPos = this.hTracker.ConvertHandCoordinatesToDepth(gesture.CurrentPosition); short userId = Marshal.ReadByte( userframe.UserMap.Pixels + (int)(handPos.Y * userframe.UserMap.DataStrideBytes) + (int)(handPos.X * 2)); if (userId > 0) { this.activeUserId = userId; } } handframe.Release(); } if (this.activeUserId > 0) { UserData user = userframe.GetUserById(this.activeUserId); if (user.IsValid && user.IsVisible && user.CenterOfMass.Z > 0) { RectangleF position = new RectangleF(0, 0, 0, 0); PointF botlocation = this.uTracker.ConvertJointCoordinatesToDepth(user.CenterOfMass); int pSize = (int) (Math.Max((int)((4700 - user.CenterOfMass.Z) * 0.08), 50) * ((float)userframe.UserMap.FrameSize.Height / 480)); position.Y = (int)botlocation.Y - pSize; position.Height = pSize; position.X = (int)botlocation.X; this.activePosition.X = position.X / userframe.UserMap.FrameSize.Width; this.activePosition.Width = position.Width / userframe.UserMap.FrameSize.Width; this.activePosition.Y = position.Y / userframe.UserMap.FrameSize.Height; this.activePosition.Height = position.Height / userframe.UserMap.FrameSize.Height; userframe.Release(); return; } } userframe.Release(); } } } catch (Exception) { } this.activeUserId = 0; }
public void PromotePotentialHand(PersistentHand potential) { _Velocity.InitValue(potential.Velocity); _X.InitValue(potential.X); _Y.InitValue(potential.Y); _Z.InitValue(potential.Z); _Pitch.InitValue(potential.Pitch); _Roll.InitValue(potential.Roll); _Yaw.InitValue(potential.Yaw); _FingerCount.InitValue(potential.FingerCount); HandTracker.InitPosition(potential.HandTracker.CurrentPosition); FingerTracker.InitPosition(potential.FingerTracker.CurrentPosition); Id = potential.Id; DetectedHand = potential.DetectedHand; FinalHand = potential.FinalHand; CurrentHand = potential.CurrentHand; CurrentFPS = potential.CurrentFPS; StabilizedHand = potential.StabilizedHand; potential.FinalHand = potential.CurrentHand; potential.DetectedHand = Hand.Invalid; potential.StabilizedHand = Hand.Invalid; potential.CurrentHand = Hand.Invalid; potential._Stabilized.CurrentValue = false; potential.Id = 0; }
public HandTrackerReceiver(IMessageReceiver receiver, HandTracker handTracker) { receiver.AssignCommandHandler( VmmCommands.EnableImageBasedHandTracking, c => handTracker.ImageProcessEnabled = c.ToBoolean() ); }
/// <summary> /// Constructor. /// </summary> public MicrosoftArticulatedHand(TrackingState trackingState, Utilities.Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null) : base(trackingState, controllerHandedness, inputSource, interactions, new ArticulatedHandDefinition(inputSource, controllerHandedness)) { #if MSFT_OPENXR handTracker = new HandTracker(controllerHandedness == Utilities.Handedness.Left ? MixedReality.OpenXR.Preview.Handedness.Left : MixedReality.OpenXR.Preview.Handedness.Right, HandPoseType.Tracked); #endif // MSFT_OPENXR }
private void UpdateHandJoints(HandTracker handTracker, FrameTime frameTime) { if (handTracker.TryLocateHandJoints(frameTime, handJointLocations)) { ApplyWrist(handProxy.Wrist, HandJoint.Wrist); Apply(handProxy.ThumbMetacarpal, HandJoint.ThumbMetacarpal); Apply(handProxy.ThumbProximal, HandJoint.ThumbProximal); Apply(handProxy.ThumbDistal, HandJoint.ThumbDistal); Apply(handProxy.ThumbTip, HandJoint.ThumbTip); Apply(handProxy.IndexMetacarpal, HandJoint.IndexMetacarpal); Apply(handProxy.IndexProximal, HandJoint.IndexProximal); Apply(handProxy.IndexIntermediate, HandJoint.IndexIntermediate); Apply(handProxy.IndexDistal, HandJoint.IndexDistal); Apply(handProxy.IndexTip, HandJoint.IndexTip); Apply(handProxy.MiddleMetacarpal, HandJoint.MiddleMetacarpal); Apply(handProxy.MiddleProximal, HandJoint.MiddleProximal); Apply(handProxy.MiddleIntermediate, HandJoint.MiddleIntermediate); Apply(handProxy.MiddleDistal, HandJoint.MiddleDistal); Apply(handProxy.MiddleTip, HandJoint.MiddleTip); Apply(handProxy.RingMetacarpal, HandJoint.RingMetacarpal); Apply(handProxy.RingProximal, HandJoint.RingProximal); Apply(handProxy.RingIntermediate, HandJoint.RingIntermediate); Apply(handProxy.RingDistal, HandJoint.RingDistal); Apply(handProxy.RingTip, HandJoint.RingTip); Apply(handProxy.LittleMetacarpal, HandJoint.LittleMetacarpal); Apply(handProxy.LittleProximal, HandJoint.LittleProximal); Apply(handProxy.LittleIntermediate, HandJoint.LittleIntermediate); Apply(handProxy.LittleDistal, HandJoint.LittleDistal); Apply(handProxy.LittleTip, HandJoint.LittleTip); } else { // Disable the hand } }
public bool Update(Frame frame) { if (IsFinalized) { return(true); } CurrentFPS = frame.CurrentFramesPerSecond; var hand = frame.Hand(Id); if (!hand.IsValid) { // Our hand is not in this frame, // but we won't give up for 25ms. if (frame.Timestamp - CurrentHandTime < 25000) { return(true); } // Our hand is truly gone... FinalHand = CurrentHand; DetectedHand = Hand.Invalid; StabilizedHand = Hand.Invalid; CurrentHand = Hand.Invalid; _Stabilized.CurrentValue = false; Id = 0; return(true); } // We still exist in this frame, update current CurrentHand = hand; CurrentHandTime = frame.Timestamp; if (!IsStabilized) { // Check for stabilization complete if (_Stabilized.Update(frame)) { StabilizedHand = hand; } } _Velocity.Update(frame); _X.Update(frame); _Y.Update(frame); _Z.Update(frame); if (_Velocity.CurrentValue < 300) { _Pitch.Update(frame); _Roll.Update(frame); _Yaw.Update(frame); } _FingerCount.Update(frame); HandTracker.Update(frame); FingerTracker.Update(frame); return(true); }
//init sensors private void WindowLoaded(object sender, RoutedEventArgs e) { handDection = new HandTracker(); // Look through all sensors and start the first connected one. // This requires that a Kinect is connected at the time of app startup. // To make your app robust against plug/unplug, // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit foreach (var potentialSensor in KinectSensor.KinectSensors) { if (potentialSensor.Status == KinectStatus.Connected) { this.sensor = potentialSensor; break; } } if (null != this.sensor) { this.sensor.SkeletonStream.Enable(); this.sensor.SkeletonFrameReady += SensorDetectHandReady; this.sensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30); this.sensor.DepthFrameReady += SensorDepthFrameReady; // Turn on the color stream to receive color frames this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30); // Allocate space to put the pixels we'll receive this.colorPixels = new byte[this.sensor.ColorStream.FramePixelDataLength]; // This is the bitmap we'll display on-screen this.colorBitmap = new WriteableBitmap(this.sensor.ColorStream.FrameWidth, this.sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null); // Set the image we display to point to the bitmap where we'll put the image data this.ColorImage.Source = this.colorBitmap; // Add an event handler to be called whenever there is new color frame data this.sensor.ColorFrameReady += this.SensorColorFrameReady; // Start the sensor! try { this.sensor.Start(); } catch (IOException) { this.sensor = null; } } if (null == this.sensor) { Console.WriteLine("No Kinect ready"); } }
public Table(int numPlayers, bool maniacPlay, int keepTopPercentHero, int keepTopPercentVillain, HandTracker handTracker) { HandTracker = handTracker; PlayerCount = numPlayers; ManiacPlay = maniacPlay; KeepTopPercentHero = keepTopPercentHero; KeepTopPercentVillain = keepTopPercentVillain; //Sort the emotional cards by numeric value. Array.Sort(HandTracker.EmotionalCardsNumeric); //Sort the Hero's starting hands. var bestStartingHands = HandTracker.BestHoleCardsNumericByPlayerCount[PlayerCount]; var bestStartingHandHeroCount = (int)(bestStartingHands.Length * ((double)keepTopPercentHero / 100)); BestHoleCardsNumericHero = new int[bestStartingHandHeroCount]; Array.Copy(bestStartingHands, BestHoleCardsNumericHero, bestStartingHandHeroCount); Array.Sort(BestHoleCardsNumericHero); //Sort the Villain's starting hands. var bestStartingHandVillainCount = (int)(bestStartingHands.Length * ((double)keepTopPercentVillain / 100)); BestHoleCardsNumericVillain = new int[bestStartingHandVillainCount]; Array.Copy(bestStartingHands, BestHoleCardsNumericVillain, bestStartingHandVillainCount); Array.Sort(BestHoleCardsNumericVillain); //Sort the best starting hands by numeric value. //for (int i = 2; i < HandTracker.BestHoleCardsNumericByPlayerCount.Length; i++) //{ // Array.Sort(HandTracker.BestHoleCardsNumericByPlayerCount[i]); //} //Populate the deck Deck = new Card[HandTracker.DeckSuitCount * HandTracker.DeckNumericValueCount]; for (short suit = 0; suit < HandTracker.DeckSuitCount; suit++) { for (short value = 0; value < HandTracker.DeckNumericValueCount; value++) { int slot = suit * HandTracker.DeckNumericValueCount + value; Deck[slot] = new Card(suit, value); } } PlayerHoleCards = new Card[numPlayers][]; for (int i = 0; i < PlayerHoleCards.Length; i++) { PlayerHoleCards[i] = new Card[2]; } AllPlayerFullHands = new PokerHand[numPlayers]; for (int i = 0; i < numPlayers; i++) { AllPlayerFullHands[i] = new PokerHand(this); } }
private static void UpdateHandJoints(HandTracker handTracker, Hand hand, FrameTime frameTime) { if (handTracker.TryLocateHandJoints(frameTime, HandJointLocations)) { hand?.UpdateHandJoints(HandJointLocations); } else { hand?.DisableHandJoints(); } }
public virtual void Install(bool reset) { #if UNITY_EDITOR if (pointerPrefab == null) { pointerPrefab = ResourceExt.EditorLoadAsset <GameObject>("Assets/Juniper/Assets/Prefabs/Rigs/DiskProbe2018.2.prefab"); } if (laserPointerNormalMaterial == null) { laserPointerNormalMaterial = ResourceExt.EditorLoadAsset <Material>("Assets/Juniper/Assets/Materials/LaserPointer_White.mat"); } if (laserPointerEnabledMaterial == null) { laserPointerEnabledMaterial = ResourceExt.EditorLoadAsset <Material>("Assets/Juniper/Assets/Materials/LaserPointer_Green.mat"); } if (laserPointerDisabledMaterial == null) { laserPointerDisabledMaterial = ResourceExt.EditorLoadAsset <Material>("Assets/Juniper/Assets/Materials/LaserPointer_Red.mat"); } #endif Find.Any(out stage); stage.Install(reset); stage.IndependentHead = HasFloorPosition; Gaze = MakePointer <GazePointer>(stage.Head, "GazePointer"); Mouse = MakePointer <Mouse>(stage.Head, "Mouse"); Helper = MakePointer <NetworkPointer>(stage.Hands, "Network"); Touches = new TouchPoint[10]; for (var i = 0; i < Touches.Length; ++i) { Touches[i] = MakePointer <TouchPoint>(stage.Head, $"Touches/TouchPoint{i.ToString()}"); Touches[i].fingerID = i; } Controllers = MotionController.MakeControllers(MakeHandPointer <MotionController>); Hands = HandTracker.MakeControllers(MakeHandPointer <HandTracker>); Voice = this.FindClosest <KeywordRecognizer>(); }
public static IObservable <HandTrackerDataEventArgs> HandDataArrived(HandTracker handTracker) { if (handTracker is null) { return(Observable.Empty <HandTrackerDataEventArgs>()); } return(Observable.FromEvent <HandTracker.OnUpdate, HandTrackerDataEventArgs>(handler => { HandTracker.OnUpdate cfaHandler = (x) => { handler(new HandTrackerDataEventArgs(x)); }; return cfaHandler; }, cfaHandler => handTracker.OnUpdateEvent += cfaHandler, cfaHandler => handTracker.OnUpdateEvent -= cfaHandler)); }
private void ButtonClick(object sender, EventArgs e) { this.handTracker = HandTracker.Create(); this.btn_start.Enabled = false; HandleError(this.handTracker.StartGestureDetection(GestureData.GestureType.HandRaise)); this.handTracker.OnNewData += this.HandTrackerOnNewData; // FIXED Jun 2013 // * Because of incompatibility between current version of OpenNI and NiTE, // * we can't use event based reading. So we put our sample in a loop. // * You can copy OpenNI.dll from version 2.0 to solve this problem. // * Then you can uncomment above line of code and comment below ones. // */ // while (this.IsHandleCreated) // { // hTracker_onNewData(hTracker); // Application.DoEvents(); // } }
public PickSelector(Model leftHandCursor, Model rightHandCursor) : base() { Root = new Engine(); rightPicker = new RayPicker(); rightPicker.Name = "magicmirror.rightpicker"; rightPicker.Options = Picker.MESH; rightPicker.Buttons = MouseEvent.RIGHT; rightPicker.SetFlags((uint)SharedObj.DOEVENTS); rightPicker.PickShape = rightHandCursor; leftPicker = rightPicker.Clone() as RayPicker; leftPicker.Name = "magicmirror.leftpicker"; leftPicker.PickShape = leftHandCursor; Root.Append(rightPicker); Root.Append(leftPicker); handTracker = new HandTracker(); handTracker.ButtonMask = MouseEvent.RIGHT; handTracker.ZOffset = 0.5f; handTracker.RightHandCursor = rightHandCursor; handTracker.LeftHandCursor = leftHandCursor; }
/** Updates hand position and rotation */ void UpdateHand(HandTracker hand) { bool bControllerActive = IsControllerActive(hand.m_controller); if (bControllerActive) { if (hand.Equals(triggerHand)) { hand.transform.localPosition = (hand.m_controller.Position - hand.m_baseOffset) * m_sensitivity + triggerInitialPosition; } //hand.transform.localPosition = (hand.m_controller.Position - hand.m_baseOffset) * m_sensitivity + hand.transform.InverseTransformPoint(handTarget_Trigger.transform.position); else { hand.transform.localPosition = (hand.m_controller.Position - hand.m_baseOffset) * m_sensitivity + forgripInitialPosition; } //hand.transform.localPosition = (hand.m_controller.Position - hand.m_baseOffset) * m_sensitivity + hand.transform.InverseTransformPoint(handTarget_Forgrip.transform.position); //hand.transform.position = handTarget_Trigger.transform.position; //hand.transform.position = (hand.m_controller.Position - hand.m_baseOffset) * m_sensitivity + hand.InitialPosition; //hand.transform.localPosition = (hand.m_controller.Position - hand.m_baseOffset) * m_sensitivity + hand.InitialPosition; //hand.transform.position = (hand.m_controller.Position - hand.m_baseOffset) * m_sensitivity + hand.m_resetPosition; if (forgripHand.m_controller.GetButton(SixenseButtons.TRIGGER) && hand.Equals(triggerHand)) { hand.transform.LookAt(forgripHand.transform); } else { hand.transform.localRotation = (hand.m_controller.Rotation * Quaternion.Inverse(hand.m_baseRotation)); } //hand.transform.rotation = handTarget_Trigger.transform.rotation; } else { // use the inital position and orientation because the controller is not active hand.transform.position = hand.InitialPosition; hand.transform.rotation = hand.InitialRotation; } }
// ReSharper disable once ParameterHidesMember private void HandTrackerOnNewData(HandTracker handTracker) { if (!handTracker.IsValid) { return; } using (var frame = handTracker.ReadFrame()) { if (frame == null || !frame.IsValid) { return; } lock (this) { using (var depthFrame = frame.DepthFrame) { if (image?.Width != depthFrame.FrameSize.Width || image?.Height != depthFrame.FrameSize.Height) { image?.Dispose(); image = new Bitmap( depthFrame.FrameSize.Width, depthFrame.FrameSize.Height, PixelFormat.Format24bppRgb); } } using (var g = Graphics.FromImage(image)) { g.FillRectangle(Brushes.Black, new Rectangle(new Point(0, 0), image.Size)); foreach (var gesture in frame.Gestures) { if (gesture.IsComplete) { handTracker.StartHandTracking(gesture.CurrentPosition); } } if (frame.Hands.Length == 0) { g.DrawString("Raise your hand", SystemFonts.DefaultFont, Brushes.White, 10, 10); } else { foreach (var hand in frame.Hands) { if (hand.IsTracking) { var handPosEllipse = new Point(); var handPos = handTracker.ConvertHandCoordinatesToDepth(hand.Position); if (!handPos.IsEmpty && !float.IsNaN(handPos.X) && !float.IsNaN(handPos.Y)) { handPosEllipse.X = (int)handPos.X - 5; handPosEllipse.Y = (int)handPos.Y - 5; g.DrawEllipse(new Pen(Brushes.White, 5), new Rectangle(handPosEllipse, new Size(5, 5))); } } } } g.Save(); } } Invoke( new MethodInvoker( delegate { try { // ReSharper disable AccessToDisposedClosure fps = (1000000 / (frame.Timestamp - lastTime) + fps * 4) / 5; lastTime = frame.Timestamp; Text = @"Frame #" + frame.FrameIndex + @" - Time: " + frame.Timestamp + @" - FPS: " + fps; // ReSharper restore AccessToDisposedClosure pb_preview.Image?.Dispose(); pb_preview.Image = image.Clone( new Rectangle(new Point(0, 0), image.Size), PixelFormat.Format24bppRgb); } catch { } })); } }
public MainWindow() { InitializeComponent(); try { Nuitrack.Init(); } catch (nuitrack.Exception exception) { Debug.WriteLine("Can not initialize Nuitrack. Exception: ", exception); } try { // Create and setup all required modules _depthSensor = DepthSensor.Create(); _colorSensor = ColorSensor.Create(); _userTracker = UserTracker.Create(); _skeletonTracker = SkeletonTracker.Create(); _handTracker = HandTracker.Create(); _gestureRecognizer = GestureRecognizer.Create(); } catch (nuitrack.Exception exception) { Debug.WriteLine("Cannot create Nuitrack module."); throw exception; } // Add event handlers for all modules _depthSensor.OnUpdateEvent += onDepthSensorUpdate; _colorSensor.OnUpdateEvent += onColorSensorUpdate; _userTracker.OnUpdateEvent += onUserTrackerUpdate; _skeletonTracker.OnSkeletonUpdateEvent += onSkeletonUpdate; _handTracker.OnUpdateEvent += onHandTrackerUpdate; _gestureRecognizer.OnNewGesturesEvent += onNewGestures; // Add an event handler for the IssueUpdate event Nuitrack.onIssueUpdateEvent += onIssueDataUpdate; // Create and configure the Bitmap object according to the depth sensor output mode OutputMode mode = _depthSensor.GetOutputMode(); OutputMode colorMode = _colorSensor.GetOutputMode(); if (mode.XRes < colorMode.XRes) { mode.XRes = colorMode.XRes; } if (mode.YRes < colorMode.YRes) { mode.YRes = colorMode.YRes; } _bitmap = new DirectBitmap(mode.XRes, mode.YRes); for (int y = 0; y < mode.YRes; ++y) { for (int x = 0; x < mode.XRes; ++x) { _bitmap.SetPixel(x, y, System.Drawing.Color.FromKnownColor(KnownColor.Aqua)); } } }
private void NiTeOnNewData(HandTracker handTracker) { try { if (Settings.Default.SmartCam && _userTracker != null && _userTracker.IsValid && _handTracker != null && _handTracker.IsValid) { using (var userFrame = _userTracker.ReadFrame()) { using (var handFrame = _handTracker.ReadFrame()) { foreach (var gesture in handFrame.Gestures) { if (!gesture.IsComplete) { continue; } var handPos = _handTracker.ConvertHandCoordinatesToDepth(gesture.CurrentPosition); short userId = Marshal.ReadByte( userFrame.UserMap.Pixels + (int)(handPos.Y * userFrame.UserMap.DataStrideBytes) + (int)(handPos.X * 2)); if (userId > 0) { _activeUserId = userId; } } } if (_activeUserId > 0) { var user = userFrame.GetUserById(_activeUserId); if (user.IsValid && user.IsVisible && user.CenterOfMass.Z > 0) { var position = new RectangleF(0, 0, 0, 0); var userLocation = _userTracker.ConvertJointCoordinatesToDepth(user.CenterOfMass); var pSize = (int) (Math.Max((int)((4700 - user.CenterOfMass.Z) * 0.08), 50) * ((float)userFrame.UserMap.FrameSize.Height / 480)); position.Y = (int)userLocation.Y - pSize; position.Height = pSize; position.X = (int)userLocation.X; _activePosition.X = position.X / userFrame.UserMap.FrameSize.Width; _activePosition.Width = position.Width / userFrame.UserMap.FrameSize.Width; _activePosition.Y = position.Y / userFrame.UserMap.FrameSize.Height; _activePosition.Height = position.Height / userFrame.UserMap.FrameSize.Height; return; } } } } } catch { // ignored } _activeUserId = 0; }
public override void UpdateHand() { // Register the hand tracker HandTracker tracker = GameObject.FindGameObjectWithTag("hand_tracker").GetComponent <HandTracker>(); tracker.SetSphereMesh(_sphereMesh); if (_spherePositions == null || _spherePositions.Length != TOTAL_JOINT_COUNT) { _spherePositions = new Vector3[TOTAL_JOINT_COUNT]; } if (_sphereMat == null) { _sphereMat = new Material(_material); _sphereMat.hideFlags = HideFlags.DontSaveInEditor; } //Update all joint spheres in the fingers foreach (var finger in _hand.Fingers) { for (int j = 0; j < 4; j++) { int key = getFingerJointIndex((int)finger.Type, j); Vector3 position = finger.Bone((Bone.BoneType)j).NextJoint.ToVector3(); _spherePositions[key] = position; //drawSphere(position) tracker.RegisterSphere(System.String.Format("finger_{0}", key), position, _jointRadius, handedness, transform.lossyScale.x, drawSphere(position)); } } //Now we just have a few more spheres for the hands //PalmPos, WristPos, and mockThumbJointPos, which is derived and not taken from the frame obj Vector3 palmPosition = _hand.PalmPosition.ToVector3(); //drawSphere(palmPosition, _palmRadius) tracker.RegisterSphere("palm", palmPosition, _palmRadius, handedness, transform.lossyScale.x, drawSphere(palmPosition, _palmRadius)); this.palm_position = palmPosition; float pitch = -_hand.Direction.Pitch; float yaw = -_hand.Direction.Yaw; float roll = _hand.PalmNormal.Roll; this.palm_rotation = new Vector3(pitch, yaw, roll) * 180.0f / Mathf.PI; Vector3 thumbBaseToPalm = _spherePositions[THUMB_BASE_INDEX] - _hand.PalmPosition.ToVector3(); Vector3 mockThumbJointPos = _hand.PalmPosition.ToVector3() + Vector3.Reflect(thumbBaseToPalm, _hand.Basis.xBasis.ToVector3()); //drawSphere(mockThumbJointPos) tracker.RegisterSphere("thumb", mockThumbJointPos, _jointRadius, handedness, transform.lossyScale.x, drawSphere(mockThumbJointPos)); //If we want to show the arm, do the calculations and display the meshes if (_showArm) { var arm = _hand.Arm; Vector3 right = arm.Basis.xBasis.ToVector3() * arm.Width * 0.7f * 0.5f; Vector3 wrist = arm.WristPosition.ToVector3(); Vector3 elbow = arm.ElbowPosition.ToVector3(); float armLength = Vector3.Distance(wrist, elbow); wrist -= arm.Direction.ToVector3() * armLength * 0.05f; Vector3 armFrontRight = wrist + right; Vector3 armFrontLeft = wrist - right; Vector3 armBackRight = elbow + right; Vector3 armBackLeft = elbow - right; //drawSphere(armFrontRight) //drawSphere(armFrontLeft) //drawSphere(armBackLeft) //drawSphere(armBackRight) tracker.RegisterSphere("arm_front_right", armFrontRight, _jointRadius, handedness, transform.lossyScale.x, drawSphere(armFrontRight)); tracker.RegisterSphere("arm_front_left", armFrontLeft, _jointRadius, handedness, transform.lossyScale.x, drawSphere(armFrontLeft)); tracker.RegisterSphere("arm_back_left", armBackLeft, _jointRadius, handedness, transform.lossyScale.x, drawSphere(armBackLeft)); tracker.RegisterSphere("arm_back_right", armBackRight, _jointRadius, handedness, transform.lossyScale.x, drawSphere(armBackRight)); //drawCylinder(armFrontLeft, armFrontRight); //drawCylinder(armBackLeft, armBackRight); //drawCylinder(armFrontLeft, armBackLeft); //drawCylinder(armFrontRight, armBackRight); tracker.RegisterCylinder("bone_arm_front_lr", armFrontLeft, armFrontRight, handedness, gameObject.layer, transform.lossyScale.x, transform.lossyScale.y, drawCylinder(armFrontLeft, armFrontRight)); tracker.RegisterCylinder("bone_arm_back_lr", armBackLeft, armBackRight, handedness, gameObject.layer, transform.lossyScale.x, transform.lossyScale.y, drawCylinder(armBackLeft, armBackRight)); tracker.RegisterCylinder("bone_arm_fb_ll", armFrontLeft, armBackLeft, handedness, gameObject.layer, transform.lossyScale.x, transform.lossyScale.y, drawCylinder(armFrontLeft, armBackLeft)); tracker.RegisterCylinder("bone_arm_fb_rr", armFrontRight, armBackRight, handedness, gameObject.layer, transform.lossyScale.x, transform.lossyScale.y, drawCylinder(armFrontRight, armBackRight)); } //Draw cylinders between finger joints for (int i = 0; i < 5; i++) { for (int j = 0; j < 3; j++) { int keyA = getFingerJointIndex(i, j); int keyB = getFingerJointIndex(i, j + 1); Vector3 posA = _spherePositions[keyA]; Vector3 posB = _spherePositions[keyB]; //drawCylinder(posA, posB); tracker.RegisterCylinder(System.String.Format("finger_cyl_{0}_{1}", keyA, keyB), posA, posB, handedness, gameObject.layer, transform.lossyScale.x, transform.lossyScale.y, drawCylinder(posA, posB)); } } //Draw cylinders between finger knuckles for (int i = 0; i < 4; i++) { int keyA = getFingerJointIndex(i, 0); int keyB = getFingerJointIndex(i + 1, 0); Vector3 posA = _spherePositions[keyA]; Vector3 posB = _spherePositions[keyB]; //drawCylinder(posA, posB); tracker.RegisterCylinder(System.String.Format("knuckle_{0}_{1}", keyA, keyB), posA, posB, handedness, gameObject.layer, transform.lossyScale.x, transform.lossyScale.y, drawCylinder(posA, posB)); } //Draw the rest of the hand //drawCylinder(mockThumbJointPos, THUMB_BASE_INDEX); tracker.RegisterCylinder("thumb_base", mockThumbJointPos, _spherePositions[THUMB_BASE_INDEX], handedness, gameObject.layer, transform.lossyScale.x, transform.lossyScale.y, drawCylinder(mockThumbJointPos, THUMB_BASE_INDEX)); //drawCylinder(mockThumbJointPos, PINKY_BASE_INDEX); tracker.RegisterCylinder("pinky_base", mockThumbJointPos, _spherePositions[PINKY_BASE_INDEX], handedness, gameObject.layer, transform.lossyScale.x, transform.lossyScale.y, drawCylinder(mockThumbJointPos, PINKY_BASE_INDEX)); }
// Update is called once per frame void Update() { bool bResetHandPosition = false; bool bGhostRifleEnabled = false; foreach (HandTracker hand in m_hands) { //Render ghost gun accordingly if (IsControllerActive(hand.m_controller) && hand.m_controller.GetButton(SixenseButtons.ONE)) { bGhostRifleEnabled = true; } if (IsControllerActive(hand.m_controller) && hand.m_controller.GetButtonUp(SixenseButtons.ONE)) { bResetHandPosition = true; triggerHand = hand; //rifle.transform.position = rifleGhost.transform.position; if (hand.m_controller.Hand.ToString().Equals("RIGHT")) { rifle.transform.parent = rightHandObject.transform; } else { rifle.transform.parent = leftHandObject.transform; } if (AKRIFLE) { rifle.transform.localPosition = new Vector3(0.01000834f, -0.1583923f, 1.819998f); } //else rifle.transform.localPosition = new Vector3(-0.1059966f, 0.4159997f, 1.770007f); //else rifle.transform.position = rifleGhost.transform.position; rifle.transform.rotation = rifle.transform.parent.rotation; if (AKRIFLE) { rifle.transform.rotation *= Quaternion.Euler(0, 180f, 0); } /*Vector3 rot = rifle.transform.parent.rotation.eulerAngles; * rot = new Vector3(rot.x, rot.y + 180, rot.z); * rifle.transform.rotation = Quaternion.Euler(rot);*/ } //if (IsControllerActive(hand.m_controller) && hand.m_controller.Hand.ToString().Equals("RIGHT") && hand.m_controller.GetButtonDown(SixenseButtons.TRIGGER)) if (IsControllerActive(hand.m_controller) && hand.Equals(triggerHand) && hand.m_controller.GetButtonDown(SixenseButtons.TRIGGER)) { if (rifle.GetComponent <ShootController>()) { rifle.GetComponent <ShootController>().fireLaser(); } } if (m_bInitialized) { UpdateHand(hand); } } if (bResetHandPosition) { m_bInitialized = true; m_baseOffset = Vector3.zero; // Get the base offset assuming forward facing down the z axis of the base foreach (HandTracker hand in m_hands) { if (!hand.Equals(triggerHand)) { forgripHand = hand; } hand.m_baseOffset = hand.m_controller.Position; hand.m_baseRotation = hand.m_controller.Rotation; if (hand.Equals(triggerHand)) { hand.transform.position = handTarget_Trigger.transform.position; triggerInitialPosition = hand.transform.localPosition; } else if (hand.Equals(forgripHand)) { hand.transform.position = handTarget_Forgrip.transform.position; forgripInitialPosition = hand.transform.localPosition; } /*if (hand.Equals(triggerHand)) * { * // Positon * hand.transform.position = handTarget_Trigger.transform.position; * * //BROKEN * //hand.transform.position = handTarget_Trigger.transform.position; * //hand.InitialPosition = handTarget_Trigger.transform.position; * * // Rotation * hand.transform.rotation = handTarget_Trigger.transform.rotation; * * //BROKEN * //hand.transform.rotation = handTarget_Trigger.transform.rotation; * //hand.InitialRotation = handTarget_Trigger.transform.rotation; * } else if(hand.Equals(forgripHand)) * { * // Positon * hand.transform.position = handTarget_Forgrip.transform.position; * * //BROKEN * //hand.transform.position = handTarget_Forgrip.transform.position; * //hand.InitialPosition = handTarget_Forgrip.transform.position; * * // Rotation * hand.transform.rotation = handTarget_Forgrip.transform.rotation; * * //BROKEN * //hand.transform.rotation = handTarget_Forgrip.transform.rotation; * //hand.InitialRotation = handTarget_Forgrip.transform.rotation; * }*/ /*// Positon * hand.m_baseOffset = hand.m_controller.Position; * hand.transform.localPosition = hand.InitialPosition; * //hand.transform.position = hand.resetTarget.transform.position; * * //hand.m_resetPosition = hand.resetTarget.transform.position; * * // Rotation * hand.m_baseRotation = hand.m_controller.Rotation; * hand.transform.localRotation = hand.InitialRotation;*/ } //m_baseOffset /= 2; //m_baseOffset = Vector3.zero; } if (bGhostRifleEnabled) { rifleGhost.SetActive(true); } else { rifleGhost.SetActive(false); } }
private bool Start() { RegisterFilter(); if (_isIdle && _broadcaster.HasServer()) { MessageBox.Show( @"Only one server is allowed.", @"Multi-Server", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } var isSameDevice = _currentDevice != null && _currentDevice.IsValid && _currentDevice.DeviceInfo.Uri == Settings.Default.DeviceURI; var isSameSensor = isSameDevice && _currentSensor != null && _currentSensor.IsValid && _currentSensor.SensorInfo.GetSensorType() == (Device.SensorType)Settings.Default.CameraType; if (!isSameDevice) { if (Settings.Default.DeviceURI == string.Empty) { _currentDevice = null; MessageBox.Show( @"Please select a device to open and then click Apply.", @"Device Open", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } } if (!isSameSensor) { if (Settings.Default.CameraType == -1) { _currentDevice = null; MessageBox.Show( @"Please select a sensor to open and then click Apply.", @"Sensor Create", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } } if (!isSameDevice) { try { _currentDevice = Device.Open(Settings.Default.DeviceURI); } catch (Exception ex) { _currentDevice = null; MessageBox.Show( string.Format("Can not open selected Device. {0}", ex.Message), @"Device Open", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } if (!isSameSensor) { try { _currentSensor = _currentDevice.CreateVideoStream((Device.SensorType)Settings.Default.CameraType); _currentSensor.OnNewFrame += CurrentSensorOnNewFrame; } catch (Exception ex) { _currentSensor = null; MessageBox.Show( string.Format("Can not open selected Sensor from selected Device. {0}", ex.Message), @"Sensor Create", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } else { _currentSensor.Stop(); } var videoModes = _currentSensor.SensorInfo.GetSupportedVideoModes().ToArray(); VideoMode selectedVideoMode = null; switch (_currentSensor.SensorInfo.GetSensorType()) { case Device.SensorType.Color: _renderOptions = VideoFrameRef.CopyBitmapOptions.Force24BitRgb; if (Settings.Default.Color_HD) { foreach (var vm in videoModes) { if (vm.Resolution.Width == 1280 && (vm.Resolution.Height == 960 || vm.Resolution.Height == 1024)) { if ((selectedVideoMode == null || selectedVideoMode.Fps < vm.Fps && vm.DataPixelFormat < selectedVideoMode.DataPixelFormat) && vm.DataPixelFormat != VideoMode.PixelFormat.Jpeg && vm.DataPixelFormat != VideoMode.PixelFormat.Yuv422) { selectedVideoMode = vm; } } } _isHd = selectedVideoMode != null; if (!_isHd) { MessageBox.Show( @"This device doesn't support ~1.3MP resolution.", @"HD Resolution", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } if (selectedVideoMode == null) { foreach (var vm in videoModes) { if (vm.Resolution.Width == 640 && vm.Resolution.Height == 480) { if ((selectedVideoMode == null || selectedVideoMode.Fps < vm.Fps && vm.DataPixelFormat < selectedVideoMode.DataPixelFormat) && vm.DataPixelFormat != VideoMode.PixelFormat.Jpeg && vm.DataPixelFormat != VideoMode.PixelFormat.Yuv422) { selectedVideoMode = vm; } } } } break; case Device.SensorType.Depth: _renderOptions = VideoFrameRef.CopyBitmapOptions.Force24BitRgb | VideoFrameRef.CopyBitmapOptions.DepthFillShadow; if (Settings.Default.Depth_Fill) { if (cb_mirror.Enabled && cb_mirror.Checked) { _renderOptions |= VideoFrameRef.CopyBitmapOptions.DepthFillRigthBlack; } else { _renderOptions |= VideoFrameRef.CopyBitmapOptions.DepthFillLeftBlack; } } if (Settings.Default.Depth_Invert) { _renderOptions |= VideoFrameRef.CopyBitmapOptions.DepthInvert; } if (Settings.Default.Depth_Histogram) { _renderOptions |= VideoFrameRef.CopyBitmapOptions.DepthHistogramEqualize; } foreach (var vm in videoModes) { if (vm.Resolution.Width == 640 && vm.Resolution.Height == 480) { if ((selectedVideoMode == null || selectedVideoMode.Fps < vm.Fps) && (vm.DataPixelFormat == VideoMode.PixelFormat.Depth1Mm || vm.DataPixelFormat == VideoMode.PixelFormat.Depth100Um)) { selectedVideoMode = vm; } } } break; case Device.SensorType.Ir: _renderOptions = VideoFrameRef.CopyBitmapOptions.Force24BitRgb; foreach (var vm in videoModes) { if (vm.Resolution.Width == 640 && vm.Resolution.Height == 480) { if ((selectedVideoMode == null || selectedVideoMode.Fps < vm.Fps && vm.DataPixelFormat < selectedVideoMode.DataPixelFormat) && vm.DataPixelFormat != VideoMode.PixelFormat.Jpeg && vm.DataPixelFormat != VideoMode.PixelFormat.Yuv422) { selectedVideoMode = vm; } } } break; } if (selectedVideoMode != null) { try { if (_currentSensor.VideoMode.Fps != selectedVideoMode.Fps || _currentSensor.VideoMode.DataPixelFormat != selectedVideoMode.DataPixelFormat || _currentSensor.VideoMode.Resolution.Width != selectedVideoMode.Resolution.Width || _currentSensor.VideoMode.Resolution.Height != selectedVideoMode.Resolution.Height) { _currentSensor.VideoMode = selectedVideoMode; } } catch (Exception ex) { MessageBox.Show( string.Format("Can not set active video mode to {0}. {1}", selectedVideoMode, ex.Message), @"Sensor Config", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } else { MessageBox.Show( @"No acceptable video mode found.", @"Sensor Config", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } _softMirror = Settings.Default.Mirroring; if (Settings.Default.SmartCam) { try { if (!isSameDevice || _userTracker == null || _handTracker == null || !_userTracker.IsValid || !_handTracker.IsValid) { _userTracker = UserTracker.Create(_currentDevice); _handTracker = HandTracker.Create(_currentDevice); _handTracker.StartGestureDetection(GestureData.GestureType.HandRaise); _handTracker.OnNewData += NiTeOnNewData; } } catch { // ignored } } if (!HandleError(_currentSensor.Start())) { Stop(false); return(false); } btn_stopstart.Text = @"Stop Streaming"; _isIdle = false; notify.Visible = true; return(true); }
public MainForm() { // Initialize Nuitrack. This should be called before using any Nuitrack module. // By passing the default arguments we specify that Nuitrack must determine // the location automatically. try { Nuitrack.Init(""); } catch (Exception exception) { Console.WriteLine("Cannot initialize Nuitrack."); throw exception; } try { // Create and setup all required modules _depthSensor = DepthSensor.Create(); _colorSensor = ColorSensor.Create(); _userTracker = UserTracker.Create(); _skeletonTracker = SkeletonTracker.Create(); _handTracker = HandTracker.Create(); _gestureRecognizer = GestureRecognizer.Create(); } catch (Exception exception) { Console.WriteLine("Cannot create Nuitrack module."); throw exception; } //_depthSensor.SetMirror(false); // Add event handlers for all modules _depthSensor.OnUpdateEvent += onDepthSensorUpdate; _colorSensor.OnUpdateEvent += onColorSensorUpdate; _userTracker.OnUpdateEvent += onUserTrackerUpdate; _userTracker.OnNewUserEvent += onUserTrackerNewUser; _userTracker.OnLostUserEvent += onUserTrackerLostUser; _skeletonTracker.OnSkeletonUpdateEvent += onSkeletonUpdate; _handTracker.OnUpdateEvent += onHandTrackerUpdate; _gestureRecognizer.OnNewGesturesEvent += onNewGestures; // Add an event handler for the IssueUpdate event Nuitrack.onIssueUpdateEvent += onIssueDataUpdate; // Create and configure the Bitmap object according to the depth sensor output mode OutputMode mode = _depthSensor.GetOutputMode(); OutputMode colorMode = _colorSensor.GetOutputMode(); if (mode.XRes < colorMode.XRes) { mode.XRes = colorMode.XRes; } if (mode.YRes < colorMode.YRes) { mode.YRes = colorMode.YRes; } _bitmap = new DirectBitmap(mode.XRes, mode.YRes); for (int y = 0; y < mode.YRes; ++y) { for (int x = 0; x < mode.XRes; ++x) { _bitmap.SetPixel(x, y, Color.FromKnownColor(KnownColor.Aqua)); } } // Set fixed form size this.MinimumSize = this.MaximumSize = new Size(mode.XRes, mode.YRes); // Disable unnecessary caption bar buttons this.MinimizeBox = this.MaximizeBox = false; // Enable double buffering to prevent flicker this.DoubleBuffered = true; // Run Nuitrack. This starts sensor data processing. try { Nuitrack.Run(); } catch (Exception exception) { Console.WriteLine("Cannot start Nuitrack."); throw exception; } this.Show(); }
void updateObjects() { // Clean up the scene objects foreach (GameObject ext_object in tracked_game_objects) { Destroy(ext_object); } tracked_game_objects.Clear(); // Set the hand information for the current index if (experiment_info[current_index].show_hands) { hand_model_l.SetActive(true); hand_model_r.SetActive(true); } else { hand_model_r.SetActive(false); hand_model_l.SetActive(false); } // Get the information of the moving balls MovingBallInfo[] object_infos = experiment_info[current_index].data; error_model.UpdateKinectPosition(experiment_info[current_index].kinect_x_offset, experiment_info[current_index].kinect_y_offset, experiment_info[current_index].kinect_z_offset); // Set the hand tracking foreach (HandPositionManager hp in GameObject.FindObjectsOfType <HandPositionManager>()) { hp.from_leap = !experiment_info[current_index].use_vive_tracker; } // Construct the object foreach (MovingBallInfo info in object_infos) { // Instantiate the new object based on the reference object MovingBall new_object = null; if (info.type == "sphere") { new_object = Instantiate(object_samples[0]); } else if (info.type == "cylinder") { new_object = Instantiate(object_samples[1]); } else if (info.type == "cube") { new_object = Instantiate(object_samples[2]); } else if (info.type == "flat-cylinder") { new_object = Instantiate(object_samples[3]); } else if (info.type == "hand") { HandTracker.Hand h = HandTracker.LoadHand(info.handPath); h._sphere_material = GameObject.FindGameObjectWithTag("hand_tracker").GetComponent <HandTracker>()._sphere_material; h._cyl_material = GameObject.FindGameObjectWithTag("hand_tracker").GetComponent <HandTracker>()._cyl_material; new_object = Instantiate(object_samples[4]); new_object.GetComponent <HandMovingBall>().h = h; // ref_object = object_samples[4]; } else if (info.type == "controller") { new_object = Instantiate(object_samples[5]); } else if (info.type == "neutral") { new_object = Instantiate(object_samples[6]); } else { Debug.Log("Error. Invalid object type."); continue; } new_object.use_vive = info.enable_tracking; // Set the x, y and z offset from the info new_object.x_offset = info.x_offset; new_object.z_offset = info.z_offset; new_object.y_offset = info.y_offset; new_object.xrot_offset = info.xrot_offset; // + t.start_rot_x; new_object.zrot_offset = info.zrot_offset; // + t.start_rot_z; new_object.yrot_offset = info.yrot_offset; // + t.start_rot_y; if (info.wireframe) { new_object.SetWireframe(); } // Set the rotation and scale from the info new_object.transform.eulerAngles = new Vector3(new_object.transform.eulerAngles.x, new_object.transform.eulerAngles.y, new_object.transform.eulerAngles.z); new_object.transform.localScale = new Vector3(info.scale_x, info.scale_y, info.scale_z); // Add the object to the tracked game objects class tracked_game_objects.Add(new_object.gameObject); if (info.show_error) { tracked_game_objects.Add(addErrors(new_object, info.error_type)); } } }
// Update is called once per frame void Update() { bool bResetHandPosition = false; bool bGhostRifleEnabled = false; foreach (HandTracker hand in m_hands) { //Render ghost gun accordingly if (IsControllerActive(hand.m_controller) && hand.m_controller.GetButton(SixenseButtons.ONE)) { bGhostRifleEnabled = true; } if (IsControllerActive(hand.m_controller) && hand.m_controller.GetButtonUp(SixenseButtons.ONE)) { bResetHandPosition = true; triggerHand = hand; //rifle.transform.position = rifleGhost.transform.position; if (hand.m_controller.Hand.ToString().Equals("RIGHT")) { rifle.transform.parent = rightHandObject.transform; } else { rifle.transform.parent = leftHandObject.transform; } if (AKRIFLE) rifle.transform.localPosition = new Vector3(0.01000834f, -0.1583923f, 1.819998f); //else rifle.transform.localPosition = new Vector3(-0.1059966f, 0.4159997f, 1.770007f); //else rifle.transform.position = rifleGhost.transform.position; rifle.transform.rotation = rifle.transform.parent.rotation; if (AKRIFLE) { rifle.transform.rotation *= Quaternion.Euler(0, 180f, 0); } /*Vector3 rot = rifle.transform.parent.rotation.eulerAngles; rot = new Vector3(rot.x, rot.y + 180, rot.z); rifle.transform.rotation = Quaternion.Euler(rot);*/ } //if (IsControllerActive(hand.m_controller) && hand.m_controller.Hand.ToString().Equals("RIGHT") && hand.m_controller.GetButtonDown(SixenseButtons.TRIGGER)) if (IsControllerActive(hand.m_controller) && hand.Equals(triggerHand) && hand.m_controller.GetButtonDown(SixenseButtons.TRIGGER)) { if(rifle.GetComponent<ShootController>()) rifle.GetComponent<ShootController>().fireLaser(); } if (m_bInitialized) { UpdateHand(hand); } } if (bResetHandPosition) { m_bInitialized = true; m_baseOffset = Vector3.zero; // Get the base offset assuming forward facing down the z axis of the base foreach (HandTracker hand in m_hands) { if (!hand.Equals(triggerHand)) forgripHand = hand; hand.m_baseOffset = hand.m_controller.Position; hand.m_baseRotation = hand.m_controller.Rotation; if (hand.Equals(triggerHand)) { hand.transform.position = handTarget_Trigger.transform.position; triggerInitialPosition = hand.transform.localPosition; } else if (hand.Equals(forgripHand)) { hand.transform.position = handTarget_Forgrip.transform.position; forgripInitialPosition = hand.transform.localPosition; } /*if (hand.Equals(triggerHand)) { // Positon hand.transform.position = handTarget_Trigger.transform.position; //BROKEN //hand.transform.position = handTarget_Trigger.transform.position; //hand.InitialPosition = handTarget_Trigger.transform.position; // Rotation hand.transform.rotation = handTarget_Trigger.transform.rotation; //BROKEN //hand.transform.rotation = handTarget_Trigger.transform.rotation; //hand.InitialRotation = handTarget_Trigger.transform.rotation; } else if(hand.Equals(forgripHand)) { // Positon hand.transform.position = handTarget_Forgrip.transform.position; //BROKEN //hand.transform.position = handTarget_Forgrip.transform.position; //hand.InitialPosition = handTarget_Forgrip.transform.position; // Rotation hand.transform.rotation = handTarget_Forgrip.transform.rotation; //BROKEN //hand.transform.rotation = handTarget_Forgrip.transform.rotation; //hand.InitialRotation = handTarget_Forgrip.transform.rotation; }*/ /*// Positon hand.m_baseOffset = hand.m_controller.Position; hand.transform.localPosition = hand.InitialPosition; //hand.transform.position = hand.resetTarget.transform.position; //hand.m_resetPosition = hand.resetTarget.transform.position; // Rotation hand.m_baseRotation = hand.m_controller.Rotation; hand.transform.localRotation = hand.InitialRotation;*/ } //m_baseOffset /= 2; //m_baseOffset = Vector3.zero; } if (bGhostRifleEnabled) { rifleGhost.SetActive(true); } else { rifleGhost.SetActive(false); } }
public HandEventArgs(int id, Point3D position, HandTracker handTracker) { this.handTracker = handTracker; hand = new Hand(id, position); }
// ReSharper disable once ParameterHidesMember private void HandTrackerOnNewData(HandTracker handTracker) { if (!handTracker.IsValid) { return; } HandTrackerFrameRef frame = handTracker.ReadFrame(); if (frame == null || !frame.IsValid) { return; } lock (this.image) { using (VideoFrameRef depthFrame = frame.DepthFrame) { if (this.image.Width != depthFrame.FrameSize.Width || this.image.Height != depthFrame.FrameSize.Height) { this.image = new Bitmap( depthFrame.FrameSize.Width, depthFrame.FrameSize.Height, PixelFormat.Format24bppRgb); } } using (Graphics g = Graphics.FromImage(this.image)) { g.FillRectangle(Brushes.Black, new Rectangle(new Point(0, 0), this.image.Size)); foreach (GestureData gesture in frame.Gestures) { if (gesture.IsComplete) { handTracker.StartHandTracking(gesture.CurrentPosition); } } if (frame.Hands.Length == 0) { g.DrawString("Raise your hand", SystemFonts.DefaultFont, Brushes.White, 10, 10); } else { foreach (HandData hand in frame.Hands) { if (hand.IsTracking) { Point handPosEllipse = new Point(); PointF handPos = handTracker.ConvertHandCoordinatesToDepth(hand.Position); handPosEllipse.X = (int)handPos.X - 5; handPosEllipse.Y = (int)handPos.Y - 5; g.DrawEllipse(new Pen(Brushes.White, 5), new Rectangle(handPosEllipse, new Size(5, 5))); } } } g.Save(); } } this.Invoke( new MethodInvoker( delegate { this.fps = ((1000000 / (frame.Timestamp - this.lastTime)) + (this.fps * 4)) / 5; this.lastTime = frame.Timestamp; this.Text = @"Frame #" + frame.FrameIndex + @" - Time: " + frame.Timestamp + @" - FPS: " + this.fps; this.pb_preview.Image = this.image.Clone( new Rectangle(new Point(0, 0), this.image.Size), PixelFormat.Format24bppRgb); frame.Release(); })); }
/// <summary> ///3D扫描的构造函数 -byCQZ 2019.6.16 /// /// </summary> private void NuitrackCreate() { try { Nuitrack.Init(""); Console.WriteLine("Initialize succneed."); } catch (nuitrack.Exception exception) { Console.WriteLine("Cannot initialize Nuitrack."); //throw exception; MessageBoxX.Warning("3D摄像头初始化失败,请检查SDK配置和是否进行密钥认证。"); } try { // Create and setup all required modules _depthSensor = DepthSensor.Create(); _colorSensor = ColorSensor.Create(); _userTracker = UserTracker.Create(); _skeletonTracker = SkeletonTracker.Create(); _handTracker = HandTracker.Create(); _gestureRecognizer = GestureRecognizer.Create(); } catch (nuitrack.Exception exception) { Console.WriteLine("Cannot create Nuitrack module."); //throw exception; MessageBoxX.Warning("3D摄像头初始化失败,请检查SDK配置和是否进行密钥认证。"); } _depthSensor.SetMirror(false); // Add event handlers for all modules _depthSensor.OnUpdateEvent += onDepthSensorUpdate; _colorSensor.OnUpdateEvent += onColorSensorUpdate; _userTracker.OnUpdateEvent += onUserTrackerUpdate; _skeletonTracker.OnSkeletonUpdateEvent += onSkeletonUpdate; _handTracker.OnUpdateEvent += onHandTrackerUpdate; _gestureRecognizer.OnNewGesturesEvent += onNewGestures; // Add an event handler for the IssueUpdate event Nuitrack.onIssueUpdateEvent += onIssueDataUpdate; // Create and configure the Bitmap object according to the depth sensor output mode OutputMode mode = _depthSensor.GetOutputMode(); OutputMode colorMode = _colorSensor.GetOutputMode(); if (mode.XRes < colorMode.XRes) { mode.XRes = colorMode.XRes; } if (mode.YRes < colorMode.YRes) { mode.YRes = colorMode.YRes; } Console.WriteLine(mode.XRes + "=====================" + mode.YRes); _bitmap = new DirectBitmap(mode.XRes, mode.YRes); for (int y = 0; y < mode.YRes; ++y) { for (int x = 0; x < mode.XRes; ++x) { _bitmap.SetPixel(x, y, Color.FromKnownColor(KnownColor.Aqua)); } } try { Nuitrack.Run(); Console.WriteLine("Start Nuitrack."); } catch (nuitrack.Exception exception) { Console.WriteLine("Cannot start Nuitrack."); //throw exception; MessageBoxX.Warning("3D摄像头启动失败,请检查SDK配置和是否进行密钥认证。"); } }
public HandEventArgs(Hand hand, HandTracker handTracker) { this.handTracker = handTracker; this.hand = hand; }
/** Updates hand position and rotation */ void UpdateHand(HandTracker hand) { bool bControllerActive = IsControllerActive(hand.m_controller); if (bControllerActive) { if(hand.Equals(triggerHand)) hand.transform.localPosition = (hand.m_controller.Position - hand.m_baseOffset) * m_sensitivity + triggerInitialPosition; //hand.transform.localPosition = (hand.m_controller.Position - hand.m_baseOffset) * m_sensitivity + hand.transform.InverseTransformPoint(handTarget_Trigger.transform.position); else hand.transform.localPosition = (hand.m_controller.Position - hand.m_baseOffset) * m_sensitivity + forgripInitialPosition; //hand.transform.localPosition = (hand.m_controller.Position - hand.m_baseOffset) * m_sensitivity + hand.transform.InverseTransformPoint(handTarget_Forgrip.transform.position); //hand.transform.position = handTarget_Trigger.transform.position; //hand.transform.position = (hand.m_controller.Position - hand.m_baseOffset) * m_sensitivity + hand.InitialPosition; //hand.transform.localPosition = (hand.m_controller.Position - hand.m_baseOffset) * m_sensitivity + hand.InitialPosition; //hand.transform.position = (hand.m_controller.Position - hand.m_baseOffset) * m_sensitivity + hand.m_resetPosition; if (forgripHand.m_controller.GetButton(SixenseButtons.TRIGGER) && hand.Equals(triggerHand)) { hand.transform.LookAt(forgripHand.transform); } else { hand.transform.localRotation = (hand.m_controller.Rotation * Quaternion.Inverse(hand.m_baseRotation)); } //hand.transform.rotation = handTarget_Trigger.transform.rotation; } else { // use the inital position and orientation because the controller is not active hand.transform.position = hand.InitialPosition; hand.transform.rotation = hand.InitialRotation; } }