public Skeleton ToNetworkModel() { Skeleton s = new Skeleton(); s.UserId = UserId; s.BodyLocation = BodyLocation.ToCoord(); s.BodyRotation = BodyRotation.ToCoord(); s.Head = Head.ToCoord(); s.Neck = Neck.ToCoord(); s.Spine = Spine.ToCoord(); s.Hips = Hips.ToCoord(); s.LeftShoulder = LeftShoulder.ToCoord(); s.LeftArm = LeftArm.ToCoord(); s.LeftHand = LeftHand.ToCoord(); s.RightShoulder = RightShoulder.ToCoord(); s.RightArm = RightArm.ToCoord(); s.RightHand = RightHand.ToCoord(); s.LeftKnee = LeftKnee.ToCoord(); s.LeftFoot = LeftFoot.ToCoord(); s.RightKnee = RightKnee.ToCoord(); s.RightFoot = RightFoot.ToCoord(); return(s); }
public virtual void Update(float elapsed) { sinceCheckedConnected += elapsed; if (sinceCheckedConnected >= ConnectedCheckFrequency) { sinceCheckedConnected -= ConnectedCheckFrequency; if (Application.platform.IsOSX()) { Connected = Input.GetJoystickNames().Length > (int)playerIndex; } else if (Application.platform.IsWindows()) { Connected = GamePad.GetState(PlayerIndex).IsConnected; } } if (!Connected) { return; } // XInput.NET if (Application.platform.IsWindows()) { GamePadState gamepadState; try { gamepadState = GamePad.GetState(PlayerIndex, GamePadDeadZone.None); } catch { return; } // Vibration if (leftMotor.Active) { leftMotor = UpdateMotor(leftMotor, elapsed); } if (rightMotor.Active) { rightMotor = UpdateMotor(rightMotor, elapsed); } if (leftMotor.LastAmount != leftMotor.CurrentAmount || rightMotor.LastAmount != rightMotor.CurrentAmount) { GamePad.SetVibration(PlayerIndex, leftMotor.CurrentAmount, rightMotor.CurrentAmount); } // Shoulders LeftShoulder = LeftShoulder.NextState(gamepadState.Buttons.LeftShoulder == ButtonState.Pressed, elapsed); RightShoulder = RightShoulder.NextState(gamepadState.Buttons.RightShoulder == ButtonState.Pressed, elapsed); // Triggers LeftTrigger = LeftTrigger.NextState(gamepadState.Triggers.Left, elapsed); RightTrigger = RightTrigger.NextState(gamepadState.Triggers.Right, elapsed); // Buttons Start = Start.NextState(gamepadState.Buttons.Start == ButtonState.Pressed, elapsed); Back = Back.NextState(gamepadState.Buttons.Back == ButtonState.Pressed, elapsed); A = A.NextState(gamepadState.Buttons.A == ButtonState.Pressed, elapsed); B = B.NextState(gamepadState.Buttons.B == ButtonState.Pressed, elapsed); X = X.NextState(gamepadState.Buttons.X == ButtonState.Pressed, elapsed); Y = Y.NextState(gamepadState.Buttons.Y == ButtonState.Pressed, elapsed); // D-Pad DPad = DPad.NextState(gamepadState.DPad.Up == ButtonState.Pressed, gamepadState.DPad.Down == ButtonState.Pressed, gamepadState.DPad.Left == ButtonState.Pressed, gamepadState.DPad.Right == ButtonState.Pressed, elapsed); // Deadzone that shit const float DeadZone = 0.1f; var left = new Vector2(gamepadState.ThumbSticks.Left.X, gamepadState.ThumbSticks.Left.Y); var right = new Vector2(gamepadState.ThumbSticks.Right.X, gamepadState.ThumbSticks.Right.Y); if (Math.Abs(left.x) < DeadZone) { left.x = 0; } else { left.x = (left.x - DeadZone * Math.Sign(left.x)) / (1 - DeadZone); } if (Math.Abs(left.y) < DeadZone) { left.y = 0; } else { left.y = (left.y - DeadZone * Math.Sign(left.y)) / (1 - DeadZone); } if (Math.Abs(right.x) < DeadZone) { right.x = 0; } else { right.x = (right.x - DeadZone * Math.Sign(right.x)) / (1 - DeadZone); } if (Math.Abs(right.y) < DeadZone) { right.y = 0; } else { right.y = (right.y - DeadZone * Math.Sign(right.y)) / (1 - DeadZone); } // Thumbsticks LeftStick = LeftStick.NextState(left, gamepadState.Buttons.LeftStick == ButtonState.Pressed, elapsed); RightStick = LeftStick.NextState(right, gamepadState.Buttons.RightStick == ButtonState.Pressed, elapsed); } // Tattiebogle if (Application.platform.IsOSX()) { string playerPrefix = "Player" + ((int)PlayerIndex + 1); // Shoulders LeftShoulder = LeftShoulder.NextState(Input.GetButton(playerPrefix + " LeftShoulder"), elapsed); RightShoulder = RightShoulder.NextState(Input.GetButton(playerPrefix + " RightShoulder"), elapsed); // Triggers LeftTrigger = LeftTrigger.NextState(Input.GetAxisRaw(playerPrefix + " LeftTrigger"), elapsed); RightTrigger = RightTrigger.NextState(Input.GetAxisRaw(playerPrefix + " RightTrigger"), elapsed); // Buttons Start = Start.NextState(Input.GetButton(playerPrefix + " Start"), elapsed); Back = Back.NextState(Input.GetButton(playerPrefix + " Back"), elapsed); A = A.NextState(Input.GetButton(playerPrefix + " A"), elapsed); B = B.NextState(Input.GetButton(playerPrefix + " B"), elapsed); X = X.NextState(Input.GetButton(playerPrefix + " X"), elapsed); Y = Y.NextState(Input.GetButton(playerPrefix + " Y"), elapsed); // D-Pad DPad = DPad.NextState(Input.GetButton(playerPrefix + " DPadUp"), Input.GetButton(playerPrefix + " DPadDown"), Input.GetButton(playerPrefix + " DPadLeft"), Input.GetButton(playerPrefix + " DPadRight"), elapsed); // Deadzone that shit const float DeadZone = 0.1f; var left = new Vector2(Input.GetAxisRaw(playerPrefix + " LeftStick X"), Input.GetAxisRaw(playerPrefix + " LeftStick Y") * -1); var right = new Vector2(Input.GetAxisRaw(playerPrefix + " RightStick X"), Input.GetAxisRaw(playerPrefix + " RightStick Y") * -1); if (Math.Abs(left.x) < DeadZone) { left.x = 0; } else { left.x = (left.x - DeadZone * Math.Sign(left.x)) / (1 - DeadZone); } if (Math.Abs(left.y) < DeadZone) { left.y = 0; } else { left.y = (left.y - DeadZone * Math.Sign(left.y)) / (1 - DeadZone); } if (Math.Abs(right.x) < DeadZone) { right.x = 0; } else { right.x = (right.x - DeadZone * Math.Sign(right.x)) / (1 - DeadZone); } if (Math.Abs(right.y) < DeadZone) { right.y = 0; } else { right.y = (right.y - DeadZone * Math.Sign(right.y)) / (1 - DeadZone); } // Thumbsticks LeftStick = LeftStick.NextState(left, Input.GetButton(playerPrefix + " LeftStick Press"), elapsed); RightStick = LeftStick.NextState(right, Input.GetButton(playerPrefix + " RightStick Press"), elapsed); } }
public void MergeFrom(Skeleton other) { if (other == null) { return; } if (other.UserId != 0UL) { UserId = other.UserId; } if (other.bodyLocation_ != null) { if (bodyLocation_ == null) { bodyLocation_ = new global::VrLifeShared.Networking.NetworkingModels.Coord(); } BodyLocation.MergeFrom(other.BodyLocation); } if (other.bodyRotation_ != null) { if (bodyRotation_ == null) { bodyRotation_ = new global::VrLifeShared.Networking.NetworkingModels.Coord(); } BodyRotation.MergeFrom(other.BodyRotation); } if (other.head_ != null) { if (head_ == null) { head_ = new global::VrLifeShared.Networking.NetworkingModels.Coord(); } Head.MergeFrom(other.Head); } if (other.neck_ != null) { if (neck_ == null) { neck_ = new global::VrLifeShared.Networking.NetworkingModels.Coord(); } Neck.MergeFrom(other.Neck); } if (other.spine_ != null) { if (spine_ == null) { spine_ = new global::VrLifeShared.Networking.NetworkingModels.Coord(); } Spine.MergeFrom(other.Spine); } if (other.hips_ != null) { if (hips_ == null) { hips_ = new global::VrLifeShared.Networking.NetworkingModels.Coord(); } Hips.MergeFrom(other.Hips); } if (other.leftShoulder_ != null) { if (leftShoulder_ == null) { leftShoulder_ = new global::VrLifeShared.Networking.NetworkingModels.Coord(); } LeftShoulder.MergeFrom(other.LeftShoulder); } if (other.leftArm_ != null) { if (leftArm_ == null) { leftArm_ = new global::VrLifeShared.Networking.NetworkingModels.Coord(); } LeftArm.MergeFrom(other.LeftArm); } if (other.leftHand_ != null) { if (leftHand_ == null) { leftHand_ = new global::VrLifeShared.Networking.NetworkingModels.Coord(); } LeftHand.MergeFrom(other.LeftHand); } if (other.rightShoulder_ != null) { if (rightShoulder_ == null) { rightShoulder_ = new global::VrLifeShared.Networking.NetworkingModels.Coord(); } RightShoulder.MergeFrom(other.RightShoulder); } if (other.rightArm_ != null) { if (rightArm_ == null) { rightArm_ = new global::VrLifeShared.Networking.NetworkingModels.Coord(); } RightArm.MergeFrom(other.RightArm); } if (other.rightHand_ != null) { if (rightHand_ == null) { rightHand_ = new global::VrLifeShared.Networking.NetworkingModels.Coord(); } RightHand.MergeFrom(other.RightHand); } if (other.leftKnee_ != null) { if (leftKnee_ == null) { leftKnee_ = new global::VrLifeShared.Networking.NetworkingModels.Coord(); } LeftKnee.MergeFrom(other.LeftKnee); } if (other.leftFoot_ != null) { if (leftFoot_ == null) { leftFoot_ = new global::VrLifeShared.Networking.NetworkingModels.Coord(); } LeftFoot.MergeFrom(other.LeftFoot); } if (other.rightKnee_ != null) { if (rightKnee_ == null) { rightKnee_ = new global::VrLifeShared.Networking.NetworkingModels.Coord(); } RightKnee.MergeFrom(other.RightKnee); } if (other.rightFoot_ != null) { if (rightFoot_ == null) { rightFoot_ = new global::VrLifeShared.Networking.NetworkingModels.Coord(); } RightFoot.MergeFrom(other.RightFoot); } }
public override int GetHashCode() { int hash = 1; if (UserId != 0UL) { hash ^= UserId.GetHashCode(); } if (bodyLocation_ != null) { hash ^= BodyLocation.GetHashCode(); } if (bodyRotation_ != null) { hash ^= BodyRotation.GetHashCode(); } if (head_ != null) { hash ^= Head.GetHashCode(); } if (neck_ != null) { hash ^= Neck.GetHashCode(); } if (spine_ != null) { hash ^= Spine.GetHashCode(); } if (hips_ != null) { hash ^= Hips.GetHashCode(); } if (leftShoulder_ != null) { hash ^= LeftShoulder.GetHashCode(); } if (leftArm_ != null) { hash ^= LeftArm.GetHashCode(); } if (leftHand_ != null) { hash ^= LeftHand.GetHashCode(); } if (rightShoulder_ != null) { hash ^= RightShoulder.GetHashCode(); } if (rightArm_ != null) { hash ^= RightArm.GetHashCode(); } if (rightHand_ != null) { hash ^= RightHand.GetHashCode(); } if (leftKnee_ != null) { hash ^= LeftKnee.GetHashCode(); } if (leftFoot_ != null) { hash ^= LeftFoot.GetHashCode(); } if (rightKnee_ != null) { hash ^= RightKnee.GetHashCode(); } if (rightFoot_ != null) { hash ^= RightFoot.GetHashCode(); } return(hash); }
public void Update(TimeSpan elapsed) { if (!Connected) { return; } State state = Controller.GetState(); var gamepadState = state.Gamepad; // Sadly we can't really use the packet information because everything is temporal // Even if everything stayed the same, that's valid data (elapsed time goes up, etc.) // Vibration if (leftMotor.Active) { leftMotor = UpdateMotor(leftMotor, elapsed); } if (rightMotor.Active) { rightMotor = UpdateMotor(rightMotor, elapsed); } if (leftMotor.LastAmount != leftMotor.CurrentAmount || rightMotor.LastAmount != rightMotor.CurrentAmount) { Controller.SetVibration(new Vibration { LeftMotorSpeed = (ushort)(leftMotor.CurrentAmount * ushort.MaxValue), RightMotorSpeed = (ushort)(rightMotor.CurrentAmount * ushort.MaxValue) }); } // Shoulders LeftShoulder = LeftShoulder.NextState((gamepadState.Buttons & GamepadButtonFlags.LeftShoulder) != 0, elapsed); RightShoulder = RightShoulder.NextState((gamepadState.Buttons & GamepadButtonFlags.RightShoulder) != 0, elapsed); // Triggers LeftTrigger = LeftTrigger.NextState(gamepadState.LeftTrigger / (float)byte.MaxValue, elapsed); RightTrigger = RightTrigger.NextState(gamepadState.RightTrigger / (float)byte.MaxValue, elapsed); // Buttons Start = Start.NextState((gamepadState.Buttons & GamepadButtonFlags.Start) != 0); Back = Back.NextState((gamepadState.Buttons & GamepadButtonFlags.Back) != 0); A = A.NextState((gamepadState.Buttons & GamepadButtonFlags.A) != 0, elapsed); B = B.NextState((gamepadState.Buttons & GamepadButtonFlags.B) != 0, elapsed); X = X.NextState((gamepadState.Buttons & GamepadButtonFlags.X) != 0, elapsed); Y = Y.NextState((gamepadState.Buttons & GamepadButtonFlags.Y) != 0, elapsed); // D-Pad DPad = DPad.NextState((gamepadState.Buttons & GamepadButtonFlags.DPadUp) != 0, (gamepadState.Buttons & GamepadButtonFlags.DPadDown) != 0, (gamepadState.Buttons & GamepadButtonFlags.DPadLeft) != 0, (gamepadState.Buttons & GamepadButtonFlags.DPadRight) != 0, elapsed); // Thumb sticks LeftStick = LeftStick.NextState( Normalize(gamepadState.LeftThumbX, gamepadState.LeftThumbY, Gamepad.GamepadLeftThumbDeadZone), (gamepadState.Buttons & GamepadButtonFlags.LeftThumb) != 0, elapsed); RightStick = RightStick.NextState( Normalize(gamepadState.RightThumbX, gamepadState.RightThumbY, Gamepad.GamepadRightThumbDeadZone), (gamepadState.Buttons & GamepadButtonFlags.RightThumb) != 0, elapsed); }
public virtual void Update(float elapsed) { sinceCheckedConnected += elapsed; if (sinceCheckedConnected >= ConnectedCheckFrequency) { sinceCheckedConnected -= ConnectedCheckFrequency; Connected = GamePad.GetState(PlayerIndex).IsConnected; } if (!Connected) { return; } GamePadState gamepadState; try { gamepadState = GamePad.GetState(PlayerIndex, GamePadDeadZone.None); } catch { return; } // Vibration if (leftMotor.Active) { leftMotor = UpdateMotor(leftMotor, elapsed); } if (rightMotor.Active) { rightMotor = UpdateMotor(rightMotor, elapsed); } if (leftMotor.LastAmount != leftMotor.CurrentAmount || rightMotor.LastAmount != rightMotor.CurrentAmount) { GamePad.SetVibration(PlayerIndex, leftMotor.CurrentAmount, rightMotor.CurrentAmount); } // Shoulders LeftShoulder = LeftShoulder.NextState(gamepadState.Buttons.LeftShoulder == ButtonState.Pressed, elapsed); RightShoulder = RightShoulder.NextState(gamepadState.Buttons.RightShoulder == ButtonState.Pressed, elapsed); // Triggers LeftTrigger = LeftTrigger.NextState(gamepadState.Triggers.Left, elapsed); RightTrigger = RightTrigger.NextState(gamepadState.Triggers.Right, elapsed); // Buttons Start = Start.NextState(gamepadState.Buttons.Start == ButtonState.Pressed); Back = Back.NextState(gamepadState.Buttons.Back == ButtonState.Pressed); A = A.NextState(gamepadState.Buttons.A == ButtonState.Pressed, elapsed); B = B.NextState(gamepadState.Buttons.B == ButtonState.Pressed, elapsed); X = X.NextState(gamepadState.Buttons.X == ButtonState.Pressed, elapsed); Y = Y.NextState(gamepadState.Buttons.Y == ButtonState.Pressed, elapsed); // D-Pad DPad = DPad.NextState(gamepadState.DPad.Up == ButtonState.Pressed, gamepadState.DPad.Down == ButtonState.Pressed, gamepadState.DPad.Left == ButtonState.Pressed, gamepadState.DPad.Right == ButtonState.Pressed, elapsed); // Deadzone that shit const float DeadZone = 0.2f; var left = new Vector2(gamepadState.ThumbSticks.Left.X, gamepadState.ThumbSticks.Left.Y); var right = new Vector2(gamepadState.ThumbSticks.Right.X, gamepadState.ThumbSticks.Right.Y); if (Math.Abs(left.x) < DeadZone) { left.x = 0; } else { left.x = (left.x - DeadZone * Math.Sign(left.x)) / (1 - DeadZone); } if (Math.Abs(left.y) < DeadZone) { left.y = 0; } else { left.y = (left.y - DeadZone * Math.Sign(left.y)) / (1 - DeadZone); } if (Math.Abs(right.x) < DeadZone) { right.x = 0; } else { right.x = (right.x - DeadZone * Math.Sign(right.x)) / (1 - DeadZone); } if (Math.Abs(right.y) < DeadZone) { right.y = 0; } else { right.y = (right.y - DeadZone * Math.Sign(right.y)) / (1 - DeadZone); } // Thumbsticks LeftStick = LeftStick.NextState(left, gamepadState.Buttons.LeftStick == ButtonState.Pressed, elapsed); RightStick = LeftStick.NextState(right, gamepadState.Buttons.RightStick == ButtonState.Pressed, elapsed); }