public void Update(AnalogState state, ThumbStick thumbStick, FrameDetails frame) { // Speed is pixels per second var speed = MovementConfiguration.Speed * frame.TimeDelta / 1000d; var accel = MovementConfiguration.Acceleration; double x, y; if (accel != 0d && accel != 1d) { var angle = state.Angle; var distance = Math.Pow(1d + state.Distance, accel) - 1d; x = distance * Math.Cos(angle); y = -distance *Math.Sin(angle); } else { x = state.X; y = -state.Y; } if (MovementConfiguration.InvertX) { x = -x; } if (MovementConfiguration.InvertY) { y = -y; } MovementActuator.Move(x * speed, y * speed); }
void KuunteleLiiketta2(AnalogState hiirenTila) { int kohtausNumero = 0; foreach (PhysicsObject sana in tuoteLista) { //string apu = sana.ToString(); if (Mouse.IsCursorOn(sana)) { kohtausNumero = tuoteLista.IndexOf(sana); break; } } switch (kohtausNumero) { case 0: elamansuola.Position = Mouse.PositionOnWorld; MessageDisplay.Add("Käytä ensi kerralla Himalajan suolaa"); MessageDisplay.MaxMessageCount = 0; break; case 1: hksininen.Position = Mouse.PositionOnWorld; MessageDisplay.Add("Vähä kyrsää... Brus suomalaista!"); MessageDisplay.MaxMessageCount = 0; break; } }
void HeitaHiirella(AnalogState state) { //MessageDisplay.RealTime = true; //MessageDisplay.Add( String.Format( "({0}, {1})", Mouse.PositionOnScreen.X, Mouse.PositionOnScreen.Y ) ); if (onHeittamassa) { pallo.Position = Mouse.PositionOnWorld; LisaaLiike(state.MouseMovement); } }
public void TestAnalogLoopChange(AnalogState input) { if (input.state < 25600) { input.state++; } else { Debug.Log("Current state: " + input.state.ToString()); Debug.Log("Finished testing"); } }
/// <summary> /// Näyttää valinnan päävalikossa punaisella. /// </summary> /// <param name="hiirenTila"></param> private void ValikossaLiikkuminen(AnalogState hiirenTila) { foreach (Label kohta in valikonKohdat) { if (Mouse.IsCursorOn(kohta)) { kohta.TextColor = Color.BloodRed; } else { kohta.TextColor = Color.Black; } } }
void OnMouseMove(AnalogState anaSt) { GameObject hoverObject = GetObjectAt(Mouse.PositionOnScreen); if (activeCell != null && hoverObject != activeCell) { activeCell.Color = activeCellOrigColor; activeCell = null; } if (activeCell == null && hoverObject != null) { activeCellOrigColor = hoverObject.Color; activeCell = hoverObject; hoverObject.Color = Color.Lighter(hoverObject.Color, 100); } }
/* * Creates the serial controller. */ public RobloxUltimateDrivingSerialController() { // Get the input devices. this.Keyboard = Keyboard.GetInstance(); this.Gamepad = Gamepad.GetInstance(); // Create the signals. this.BrakeSignal = new KeyboardPWMSignal(VirtualKeyCode.VK_B, THROTTLE_KEYBOARD_FREQUENCY); this.BrakeSignal.DutyCycle = 0; // Create the state controllers. this.TurnSignalStateController = new AnalogState(3, 1, (newState, previousState) => { if ((newState == 1 && previousState == 0) || newState == 0) { this.Keyboard.SendKeyPress(VirtualKeyCode.VK_Z); } else if ((newState == 1 && previousState == 2) || newState == 2) { this.Keyboard.SendKeyPress(VirtualKeyCode.VK_C); } }); this.ShifterStateController = new AnalogState(3, 1, (newState, previousState) => { // Change the reversing state. if (newState == 0) { this.Reversing = true; } else { this.Reversing = false; } // Press the parking key. if ((newState == 1 && previousState == 2) || newState == 2) { this.Keyboard.SendKeyPress(VirtualKeyCode.VK_P); } }); }
/// <summary> /// Hoidetaan tähtääminen /// Määritetään uusi Vector suunta, johon lasketaan pelaajan aseen ja hiiren välinen suunta. /// </summary> /// <param name="hiirenliike">hiirenliike</param> public void Tahtaa(AnalogState hiirenliike) { //MessageDisplay.Add(Mouse.PositionOnWorld.X + ""); if (pelaajaKatsooVasemmalle == false && Mouse.PositionOnScreen.X < 0) { pelaaja.MirrorImage(); pelaajanAse.FlipImage(); pelaajanAse.X = -10; pelaajaKatsooVasemmalle = true; } else if (pelaajaKatsooVasemmalle == true && Mouse.PositionOnScreen.X > 0) { pelaaja.MirrorImage(); pelaajanAse.FlipImage(); pelaajanAse.X = 10; pelaajaKatsooVasemmalle = false; } Vector suunta = (Mouse.PositionOnWorld - pelaajanAse.AbsolutePosition).Normalize(); pelaajanAse.Angle = suunta.Angle; }
public void Update(AnalogState state, ThumbStick thumbStick, FrameDetails frame) { var x = Configuration.InvertX ? -state.X : state.X; var y = Configuration.InvertY ? state.Y : -state.Y; var distance = Math.Sqrt(x * x + y * y); if (distance <= Configuration.MinRadius) { memory.Clear(); distance = 0d; } else { distance = (distance - Configuration.MinRadius) / (1d - Configuration.MinRadius); } var angle = Math.Atan2(y, x); memory.Enqueue(new AngleData(angle)); var avgCos = 0d; var avgSin = 0d; foreach (var item in memory) { avgCos += item.Cos; avgSin += item.Sin; } avgCos /= memory.Count; avgSin /= memory.Count; var avgAngle = Math.Atan2(avgSin, avgCos); while (memory.Count > Configuration.Smoothing / frame.FrameTime) { memory.Dequeue(); } RadialActuator.Update((avgAngle * 180d / Math.PI + 90d) % 360d, distance); }
public void SetWeight(AnalogState input) { SetWeight(input.state); }
public void TestAnalogChange(AnalogState input) { Debug.Log("Current state: " + input.state.ToString()); Debug.Log("Previous state: " + input.previous_state.ToString()); }
void tahtaa(AnalogState hiirenliike) { Vector suunta = (Mouse.PositionOnWorld - pelaaja.AbsolutePosition).Normalize(); pelaajan1ase.Angle = suunta.Angle; }
void hiirenliikutus(AnalogState hiirenTila) { cursor.X = Mouse.PositionOnWorld.X; cursor.Y = Mouse.PositionOnWorld.Y; }
/* * Handles the serial handler. */ public void HandleInputs() { try { // Create and open the port. var port = new SerialPort("COM" + this.Port, 9600, Parity.None, 8, StopBits.One); port.Open(); Console.WriteLine("Opened on port COM" + this.Port); // Create the controllers. if (this.Controllers == null) { this.Controllers = new List <BaseSerialController>() { null, new RobloxUltimateDrivingSerialController(), }; this.AnalogInputNames = new List <string>() { "Mode Selector", "Steering Wheel", "Right Pedal", "Left Pedal", "Left Shifter", "Right Shifter", }; this.ControllerNames = new List <string>() { null, "Roblox Ultimate Driving", }; this.LastAnalogInputs = new List <byte>() { 0, 0, 0, 0, 0, 0 }; } // Create the analog input mapper. var analogMappers = new List <AnalogMapper>(); foreach (var data in this.AnalogInputs) { analogMappers.Add(AnalogMapper.FromData(data)); } // Create the mode selector. var currentController = 0; var modeSelectorStateController = new AnalogState(6, 0, (newState, previousState) => { currentController = newState; // Start the new controller. if (newState < this.Controllers.Count && this.Controllers[newState] != null) { Console.WriteLine("Using controls for " + this.ControllerNames[newState]); this.Controllers[newState].Start(); } else { Console.WriteLine("Disabled controls"); } // Stop the previous controller. if (previousState < this.Controllers.Count && this.Controllers[previousState] != null) { this.Controllers[previousState].Stop(); } }); // Start accepting inputs. while (true) { // Read the line. var line = port.ReadLine(); try { // Handle the inputs. if (line.Length >= 4 && line.Contains(",")) { var inputType = line[0]; if (inputType == 'A') { var channel = int.Parse(line.Substring(1).Split(',')[0]); var input = int.Parse(line.Substring(1).Split(',')[1]); if (channel < analogMappers.Count) { var mapper = analogMappers[channel]; var initiallyEnabled = mapper.MinimumRangeMet(); var mappedValue = mapper.GetValue(input); if (mapper.MinimumRangeMet()) { if (channel == 0) { modeSelectorStateController.SetValue(mappedValue); } else { // Send the input. this.LastAnalogInputs[channel] = mappedValue; if (currentController < this.Controllers.Count && this.Controllers[currentController] != null) { this.Controllers[currentController].HandleInput("A" + channel + "," + mappedValue); if (!initiallyEnabled && this.AnalogInputNames[channel] != null) { Console.WriteLine(this.AnalogInputNames[channel] + " is now active."); } } // Reset the pedals if both are down. if ((channel == 2 || channel == 3) && (this.LastAnalogInputs[2] == 255 && this.LastAnalogInputs[3] == 255)) { Console.WriteLine("Resetting pedals."); analogMappers[2].Reset(); analogMappers[3].Reset(); } } } } } else { if (currentController < this.Controllers.Count && this.Controllers[currentController] != null) { this.Controllers[currentController].HandleInput(line); } } } } catch (FormatException) { } } } catch (IOException) { } catch (InvalidOperationException) { } finally { if (this.Controllers != null) { foreach (var controller in this.Controllers) { if (controller != null) { controller.Stop(); } } } } }
//ht=hiirentila void osoitin(AnalogState ht) { }
private void MuutaPainovoimaa(AnalogState state) { Gravity = 1000 * state.StateVector; }
/// <summary> /// Tähdätään puhelimen kallistuksen mukaan. 30 asteen kallistuksella taso on vaakassa. /// </summary> /// <param name="s"></param> private void TahtaaAccel(AnalogState s) { double kulma = s.StateVector.Y * 120 + 30; maila.Tavoite = Angle.FromDegrees(kulma); }
public void Press(AnalogState input) { Press(input.state); }
public void movePlayerAnalog(AnalogState al, PhysicsObject player) { double xPos = al.StateVector.X; double yPos = al.StateVector.Y; Vector pPushVector = new Vector((xPos) * PLAYER_SPEED_X.X, (yPos) * PLAYER_SPEED_Y.Y); player.Push(pPushVector); double maxVibration = 0.15; double maxBias = 0.5; double prcBias = (0.5 * Math.Abs((xPos + yPos / 2))) + (0.5 * Math.Max(0, Math.Min(1, (1 - Math.Abs((player.Velocity.Magnitude / 100)))))); //Bias the control double rightControllerVibr = ((maxVibration / 2) - ((maxVibration / 2 * maxBias) * xPos)) * prcBias; double leftControllerVibr = ((maxVibration / 2) + ((maxVibration / 2 * maxBias) * xPos)) * prcBias; if (((ControllerOne.GetType()) == typeof(GamePad)) && vibrateEnabled) { GamePad gp = ControllerOne as GamePad; gp.Vibrate(leftControllerVibr, rightControllerVibr, 0, 0, 0.1); } //player.Velocity = pPushVector; }
void Tahtaa(AnalogState hiirenLiike) { Vector suunta = (Mouse.PositionOnWorld - pelaaja1.Weapon.AbsolutePosition).Normalize(); pelaaja1.Weapon.Angle = suunta.Angle; }
void Tahtaa(AnalogState hiirenliike) { Vector suunta = (Mouse.PositionOnWorld - Pelaaja.Weapon.AbsolutePosition).Normalize(); Pelaaja.Weapon.Angle = suunta.Angle; }
void MouseMoves(AnalogState astate) { var mp = Mouse.PositionOnWorld; foreach (var edge in dragEdges) { var eps = (EdgeEndpoints)edge.Tag; RouteEdgeObject(edge, mp, instance.points[eps.Key]); } if (activePointIdx >= 0) { int routeIdx = instance.GetRouteIdxForNode(activePointIdx); HighlightOnlyTruck(routeIdx); int pidx = GetIndexOfPointUnderMouse(); List <GameObject> removedEdges = null; if (pidx != -1 && pidx != activePointIdx && (pidx == 0 || instance.GetNodeNeighbourCount(pidx) < 2) && instance.ConnectNode(pidx, dragEdges, out removedEdges)) { foreach (var rmEdge in removedEdges) { Remove(rmEdge); } foreach (var edge in dragEdges) { var eps = (EdgeEndpoints)edge.Tag; RouteEdgeObject(edge, instance.points[eps.Key], instance.points[eps.Value]); } RefreshStateAndUpdateDisplays(); HighlightViolations(); // The edges are now considered "used" dragEdges = new List <GameObject>(); ActivatePoint(pidx); } } else { var node = GetIndexOfPointUnderMouse(); if (node != -1) { bool removed = false; List <int> nbrCloneList = new List <int>(instance.GetNodeNeighbours(node)); foreach (var nbr in nbrCloneList) { //var rmEdges = instance.RemoveEdges(node, nbr); //foreach (var rme in rmEdges) //{ // Remove(rme); // removed = true; //} } if (removed) { RefreshStateAndUpdateDisplays(); HighlightViolations(); } } var edge = GetEdgeUnderMouse(); int routeIdx = instance.GetRouteIdxForEdge(edge); if (routeIdx != -1) { HighlightOnlyTruck(routeIdx); } } }
void ValikossaLiikkuminen(AnalogState hiirenTila) { foreach (Label kohta in valikonKohdat) { if (Mouse.IsCursorOn(kohta)) { kohta.TextColor = Color.Red; } else { kohta.TextColor = Color.Black; } } }
public void SetVolume(AnalogState input) { SetVolume(input.state); }
public void SetIntensity(AnalogState input) { SetIntensity(input.state); }