public void BeginSearch() { //searching = true; Wii.StartSearch(); theText.text = "I'm looking."; Time.timeScale = 1.0f; }
// Start is called before the first frame update void Start() { Time.fixedDeltaTime = PlayerPrefs.GetFloat("DeltaTime"); Board0 = gameObject.AddComponent <GenericBoard>(); Board1 = gameObject.AddComponent <GenericBoard>(); Board2 = gameObject.AddComponent <GenericBoard>(); Board3 = gameObject.AddComponent <GenericBoard>(); Wii.StartSearch(); Wii.WakeUp(); Boards.Add(Board0); Boards.Add(Board1); Boards.Add(Board2); Boards.Add(Board3); Board0.BoardNumber = 0; Board1.BoardNumber = 1; Board2.BoardNumber = 2; Board3.BoardNumber = 3; updatetime = 0.02F; Board0.RotationAngle = PlayerPrefs.GetFloat("Board0_angle"); Board1.RotationAngle = PlayerPrefs.GetFloat("Board1_angle"); Board2.RotationAngle = 0; Board3.RotationAngle = 0; Board0.Board_length = PlayerPrefs.GetFloat("Board_Length"); Board0.Board_width = PlayerPrefs.GetFloat("Board_Width"); Board1.Board_length = PlayerPrefs.GetFloat("Board_Length"); Board1.Board_width = PlayerPrefs.GetFloat("Board_Width"); Board2.Board_length = PlayerPrefs.GetFloat("Board_Length"); Board2.Board_width = PlayerPrefs.GetFloat("Board_Width"); Board3.Board_length = PlayerPrefs.GetFloat("Board_Length"); Board3.Board_width = PlayerPrefs.GetFloat("Board_Width"); Board0.BoardPosition.Set(0f, 0f); Board1.BoardPosition.Set(PlayerPrefs.GetFloat("Board1_x"), PlayerPrefs.GetFloat("Board1_y")); Board0.Board_Force_error_storage.Set(0.0f, 0.0f, 0.0f, 0.0f); Board1.Board_Force_error_storage.Set(0.0f, 0.0f, 0.0f, 0.0f); foreach (GenericBoard item in Boards) { // Calculate Initial Sensor Position item.SensorXRelative.x = Mathf.Cos(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_length - Mathf.Sin(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_width; item.SensorXRelative.y = Mathf.Sin(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_length + Mathf.Cos(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_width; item.SensorYRelative.x = -Mathf.Cos(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_length - Mathf.Sin(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_width; item.SensorYRelative.y = -Mathf.Sin(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_length + Mathf.Cos(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_width; item.SensorZRelative.x = Mathf.Cos(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_length + Mathf.Sin(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_width; item.SensorZRelative.y = Mathf.Sin(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_length - Mathf.Cos(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_width; item.SensorWRelative.x = -Mathf.Cos(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_length + Mathf.Sin(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_width; item.SensorWRelative.y = -Mathf.Sin(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_length - Mathf.Cos(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_width; item.SensorXinGlobal = item.BoardPosition + item.SensorXRelative; item.SensorYinGlobal = item.BoardPosition + item.SensorYRelative; item.SensorZinGlobal = item.BoardPosition + item.SensorZRelative; item.SensorWinGlobal = item.BoardPosition + item.SensorWRelative; } }
void Awake() { Debug.Log("Awake called."); Debug.Log("Awake called."); Wii.StartSearch(); Wii.WakeUp(); }
public void BeginSearch() { //searching = true; Wii.StartSearch(); Debug.Log("I'm looking."); Time.timeScale = 1.0f; }
// Start is called before the first frame update void Start() { Wii.StartSearch(); Wii.WakeUp(); Boards.Add(Board0); Boards.Add(Board1); Boards.Add(Board2); Boards.Add(Board3); Board0.BoardNumber = 0; Board1.BoardNumber = 1; Board2.BoardNumber = 2; Board3.BoardNumber = 3; updatetime = 0.02F; Board0.RotationAngle = 90; Board1.RotationAngle = 90; Board2.RotationAngle = 0; Board3.RotationAngle = 0; Board0.Board_length = 400f; Board0.Board_width = 200f; Board1.Board_length = 400f; Board1.Board_width = 200f; Board2.Board_length = 400f; Board2.Board_width = 200f; Board3.Board_length = 400f; Board3.Board_width = 200f; Board0.BoardPosition.Set(0f, 0f); Board1.BoardPosition.Set(500f, 0f); foreach (GenericBoard item in Boards) { // Calculate Initial Sensor Position item.RotationMatrix = new float[, ] { { Mathf.Cos(Mathf.Deg2Rad * item.RotationAngle), -Mathf.Sin(Mathf.Deg2Rad * item.RotationAngle) }, { Mathf.Sin(Mathf.Deg2Rad * item.RotationAngle), Mathf.Cos(Mathf.Deg2Rad * item.RotationAngle) } }; item.SensorXRelative.x = Mathf.Cos(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_length - Mathf.Sin(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_width; item.SensorXRelative.y = Mathf.Sin(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_length + Mathf.Cos(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_width; item.SensorYRelative.x = -Mathf.Cos(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_length - Mathf.Sin(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_width; item.SensorYRelative.y = -Mathf.Sin(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_length + Mathf.Cos(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_width; item.SensorZRelative.x = Mathf.Cos(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_length + Mathf.Sin(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_width; item.SensorZRelative.y = Mathf.Sin(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_length - Mathf.Cos(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_width; item.SensorWRelative.x = -Mathf.Cos(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_length + Mathf.Sin(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_width; item.SensorWRelative.y = -Mathf.Sin(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_length - Mathf.Cos(Mathf.Deg2Rad * item.RotationAngle) * 1 / 2 * item.Board_width; item.SensorXinGlobal = item.BoardPosition + item.SensorXRelative; item.SensorYinGlobal = item.BoardPosition + item.SensorYRelative; item.SensorZinGlobal = item.BoardPosition + item.SensorZRelative; item.SensorWinGlobal = item.BoardPosition + item.SensorWRelative; } }
// Use this for initialization void OnEnable() { // Connects to a board if (!Wii.IsActive(remote)) { Debug.Log("Start searching"); Wii.StartSearch(); } Wii.OnDiscoveryFailed += OnDiscoveryFailed; Wii.OnWiimoteDiscovered += OnWiimoteDiscovered; Wii.OnWiimoteDisconnected += OnWiimoteDisconnected; }
// Update is called once per frame void Update() { Wii.WakeUp(); Wii.StartSearch(); if (Measurement.WhetherStart == true) { human.transform.localPosition = new Vector2(800f * ((Measurement.GlobalCOP.x + (0.5f * Measurement.Board0.Board_width)) / (Measurement.Board0.Board_width + Measurement.Board1.BoardPosition.x)), 400f * ((Measurement.GlobalCOP.y + (0.5f * Measurement.Board0.Board_length))/ (Measurement.Board0.Board_length))); } if (Measurement.WhetherStart == false) { human.transform.localPosition = new Vector2(0, 0); } }
// Update is called once per frame void FixedUpdate() { Wii.WakeUp(); Wii.StartSearch(); /*theX = (((Board.Board_x[0] - 0.5f * Board.Board_width[0]) * (Board.Board_sensor[0].w + Board.Board_sensor[0].z)) + ((Board.Board_x[0] + 0.5f * Board.Board_width[0]) * (Board.Board_sensor[0].x + Board.Board_sensor[0].y)) + ((Board.Board_x[1] - 0.5f * Board.Board_width[1]) * (Board.Board_sensor[1].w + Board.Board_sensor[1].z)) + ((Board.Board_x[1] + 0.5f * Board.Board_width[1]) * (Board.Board_sensor[1].x + Board.Board_sensor[1].y))) + / (Board.Board_Totalforce[0] + Board.Board_Totalforce[1]); + + theY = (((Board.Board_y[0] - 0.5f * Board.Board_length[0]) * (Board.Board_sensor[0].x + Board.Board_sensor[0].z)) + ((Board.Board_y[0] + 0.5f * Board.Board_length[0]) * (Board.Board_sensor[0].w + Board.Board_sensor[0].y)) + ((Board.Board_y[1] - 0.5f * Board.Board_length[1]) * (Board.Board_sensor[1].x + Board.Board_sensor[1].z)) + ((Board.Board_y[1] + 0.5f * Board.Board_length[1]) * (Board.Board_sensor[1].w + Board.Board_sensor[1].y))) + / (Board.Board_Totalforce[0] + Board.Board_Totalforce[1]); */ }
/* Vector3 x1 = new Vector3(1.0f, 0.0f, 1.0f); // right top * Vector3 y1 = new Vector3(1.0f, 0.0f, -1.0f); // right bottom * Vector3 z1 = new Vector3(-1.0f, 0.0f, 1.0f); // left top * Vector3 w1 = new Vector3(-1.0f, 0.0f, -1.0f); // left bottom*/ public void Awake() { Rigidbody = GetComponent <Rigidbody>(); StartRotation = Motor.localRotation; Camera = Camera.main; Wii.WakeUp(); if (!Wii.GetIsAwake()) { Wii.WakeUp(); } Wii.StartSearch(); discoveryStatus = Wii.GetDiscoveryStatus(); if (discoveryStatus > 99) { Wii.AddVirtualRemote(); } }
// Update is called once per frame void FixedUpdate() { Wii.WakeUp(); Wii.StartSearch(); if (Measurement.WhetherStart == true) { CSVManager.reportFileName = PlayerPrefs.GetString("UserName") + "COPreport.csv"; CSVManager.AppendToReport( new string[6] { PlayerPrefs.GetString("UserName"), Measurement.GlobalTotalForce.ToString(), Measurement.GlobalCOP.x.ToString(), Measurement.GlobalCOP.y.ToString(), Measurement.GlobalVelocity.x.ToString(), Measurement.GlobalVelocity.y.ToString() }); } }
public static void WaketheBoard() { Debug.Log("Awake called."); Wii.StartSearch(); Wii.WakeUp(); }
/// <summary> /// Attempts to find a Wii remote and connect it. /// TODO: troubleshoot issue where this method of connection does not work /// </summary> public void ConnectWii() { Wii.StartSearch(); }
// Start is called before the first frame update void Start() { Wii.StartSearch(); }
void Update() { findClock += Time.deltaTime; bool right = Input.GetKeyUp(KeyCode.LeftArrow); bool left = Input.GetKeyUp(KeyCode.RightArrow); if (findClock >= findInterval) { Wii.StartSearch(); findClock = 0; } inputClock += Time.deltaTime; if (inputClock > -updateDelay) { foreach (var oar in oars.oars) { switch (oar.side) { case WiimoteOars.Oar.SIDES.LEFT: case WiimoteOars.Oar.SIDES.RIGHT: if (oar.isPaddling) { if (oar.direction == WiimoteOars.DIRECTIONS.FORWARDS) { if (oar.side == WiimoteOars.Oar.SIDES.RIGHT) { currentTorque -= TorquePerStroke; } else { currentTorque += TorquePerStroke; } currentSpeed += SpeedPerStroke; } else { if (oar.side == WiimoteOars.Oar.SIDES.RIGHT) { currentTorque += TorquePerStroke * BackwardsTorqueMultiplier; } else { currentTorque -= TorquePerStroke * BackwardsTorqueMultiplier; } currentSpeed -= SpeedPerStroke * BackwardsSpeedMultiplier; } } break; case WiimoteOars.Oar.SIDES.MASTER: if (oar.GetButtonDown("RIGHT")) { left = true; } if (oar.GetButtonDown("LEFT")) { right = true; } if (oar.GetButtonDown("A") && oar.GetButtonDown("B")) { UnityEngine.SceneManagement.SceneManager.LoadScene(UnityEngine.SceneManagement.SceneManager.GetActiveScene().name); } break; } } if (left) { currentTorque -= TorquePerStroke * keyboardAmplification; } if (right) { currentTorque += TorquePerStroke * keyboardAmplification; } if (left) { currentSpeed += SpeedPerStroke * keyboardAmplification; } if (right) { currentSpeed += SpeedPerStroke * keyboardAmplification; } currentSpeed = Mathf.Clamp(currentSpeed, -MaxSpeed, MaxSpeed); } }