-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using Assets; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class JoystickThrustmasterWarthog : MonoBehaviour { | ||
public const string USB_ID = "044f:0402"; | ||
//public const string USB_ID = "044f:0404"; | ||
|
||
public GameObject Model; | ||
public GameObject Joystick; | ||
|
||
// Use this for initialization | ||
void Start() | ||
{ | ||
UDPListener.StickEventListener += StickEvent; | ||
} | ||
|
||
// Update is called once per frame | ||
void Update() | ||
{ | ||
} | ||
|
||
void StickEvent(JoystickState state) | ||
{ | ||
if (state.UsbID != USB_ID) | ||
{ | ||
return; | ||
} | ||
|
||
Model.SetActive(true); | ||
|
||
foreach (KeyValuePair<string, int> entry in state.Data) | ||
{ | ||
switch (entry.Key) | ||
{ | ||
case "Connected": | ||
if (Model.activeInHierarchy) | ||
Model.SetActive(entry.Value == 1); | ||
break; | ||
|
||
case "X": | ||
Joystick.transform.localEulerAngles = new Vector3(Joystick.transform.localEulerAngles.x, ConvertRange(entry.Value, 0, 65535, -20, 20), Joystick.transform.localEulerAngles.z); | ||
break; | ||
case "Y": | ||
Joystick.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, -20, 20), Joystick.transform.localEulerAngles.y, Joystick.transform.localEulerAngles.z); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
public static float ConvertRange( | ||
double value, // value to convert | ||
double originalStart, double originalEnd, // original range | ||
double newStart, double newEnd) // desired range | ||
{ | ||
double scale = (double)(newEnd - newStart) / (originalEnd - originalStart); | ||
return (float)(newStart + ((value - originalStart) * scale)); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using Assets; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class ThrottleThrustmasterWarthog : MonoBehaviour { | ||
public const string USB_ID = "044f:0404"; | ||
|
||
public GameObject Model; | ||
public GameObject LeftThrottle; | ||
public GameObject RightThrottle; | ||
|
||
// Use this for initialization | ||
void Start() | ||
{ | ||
UDPListener.StickEventListener += StickEvent; | ||
} | ||
|
||
// Update is called once per frame | ||
void Update() | ||
{ | ||
} | ||
|
||
void StickEvent(JoystickState state) | ||
{ | ||
if (state.UsbID != USB_ID) | ||
{ | ||
return; | ||
} | ||
|
||
Model.SetActive(true); | ||
|
||
foreach (KeyValuePair<string, int> entry in state.Data) | ||
{ | ||
switch (entry.Key) | ||
{ | ||
case "Connected": | ||
if (Model.activeInHierarchy) | ||
Model.SetActive(entry.Value == 1); | ||
break; | ||
|
||
case "RotationZ": // Left Throttle | ||
// Rotate Z between -30 and 30 | ||
LeftThrottle.transform.eulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, 40, -25), LeftThrottle.transform.eulerAngles.y, LeftThrottle.transform.eulerAngles.z); | ||
break; | ||
|
||
case "Z": // Right Throttle | ||
// Rotate X between -30 and 30 | ||
RightThrottle.transform.eulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, 40, -25), RightThrottle.transform.eulerAngles.y, RightThrottle.transform.eulerAngles.z); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
public static float ConvertRange( | ||
double value, // value to convert | ||
double originalStart, double originalEnd, // original range | ||
double newStart, double newEnd) // desired range | ||
{ | ||
double scale = (double)(newEnd - newStart) / (originalEnd - originalStart); | ||
return (float)(newStart + ((value - originalStart) * scale)); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class MouseRotate : MonoBehaviour { | ||
|
||
float rotSpeed = 20; | ||
|
||
void Start() | ||
{ | ||
Debug.Log("Mouse Rotate " + gameObject.name); | ||
} | ||
|
||
void OnMouseDrag() | ||
{ | ||
Debug.Log("Dragged " + gameObject.name); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.