Exemplo n.º 1
0
        // read the calibration data and undo obfuscation transformation
        private void ReadCalibrationData()
        {
            byte[] buffer = new byte[16];
            // 0x04A40020 is the address of the calibration data on the wiimote
            _Wiimote.ReadMemory(0x04A40020, buffer, 0, 16);
            for (int i = 0; i < 16; i++)
            {
                buffer[i] = (byte)((buffer[i] ^ 0x17) + 0x17 & 0xFF);
            }

            AccelerometerCalibration accelerometerCalibration = new AccelerometerCalibration(
                (ushort)((buffer[0] << 2) + ((buffer[3]) & 0x3)),
                (ushort)((buffer[4] << 2) + ((buffer[7]) & 0x3)),
                (ushort)((buffer[1] << 2) + ((buffer[3] >> 2) & 0x3)),
                (ushort)((buffer[5] << 2) + ((buffer[7] >> 2) & 0x3)),
                (ushort)((buffer[2] << 2) + ((buffer[3] >> 4) & 0x3)),
                (ushort)((buffer[6] << 2) + ((buffer[7] >> 4) & 0x3)));

            _Accelerometer = new Accelerometer(accelerometerCalibration);

            AnalogStickCalibration stickCalibration = new AnalogStickCalibration(buffer[9], buffer[10], buffer[8],
                                                                                 buffer[12], buffer[13], buffer[11]);

            _Stick = new AnalogStick(stickCalibration);
        }
Exemplo n.º 2
0
    void Start()
    {
        startRotation = transform.localRotation;

        AccelerometerCalibration.CalibrateAccelerometer();

        Cursor.lockState = CursorLockMode.Locked;
    }
Exemplo n.º 3
0
        // read the calibration data and undo obfuscation transformation
        private void ReadCalibrationData()
        {
            byte[] buffer = new byte[16];
            // 0x04A40020 is the address of the calibration data on the wiimote
            _Wiimote.ReadMemory(0x04A40020, buffer, 0, 16);
            for (int i = 0; i < 16; i++)
            {
                buffer[i] = (byte)((buffer[i] ^ 0x17) + 0x17 & 0xFF);
            }

            AccelerometerCalibration accelerometerCalibration = new AccelerometerCalibration(
                 (ushort)((buffer[0] << 2) + ((buffer[3]) & 0x3)),
                 (ushort)((buffer[4] << 2) + ((buffer[7]) & 0x3)),
                 (ushort)((buffer[1] << 2) + ((buffer[3] >> 2) & 0x3)),
                 (ushort)((buffer[5] << 2) + ((buffer[7] >> 2) & 0x3)),
                 (ushort)((buffer[2] << 2) + ((buffer[3] >> 4) & 0x3)),
                 (ushort)((buffer[6] << 2) + ((buffer[7] >> 4) & 0x3)));

            _Accelerometer = new Accelerometer(accelerometerCalibration);

            AnalogStickCalibration stickCalibration = new AnalogStickCalibration(buffer[9], buffer[10], buffer[8],
                                                           buffer[12],buffer[13], buffer[11]);

            _Stick = new AnalogStick(stickCalibration);
        }
Exemplo n.º 4
0
    void Update()
    {
        if (Application.platform == RuntimePlatform.Android)
        {
            if (Input.touchCount != 0)
            {
                transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime * 120, Space.Self);
            }

            Vector3 fixedAcceleration = AccelerometerCalibration.FixAcceleration(Input.acceleration);

            transform.Rotate(new Vector3(fixedAcceleration.y * sensitivity * Time.deltaTime * 120, 0, 0), Space.Self);

            transform.Rotate(new Vector3(0, fixedAcceleration.x * sensitivity * Time.deltaTime * 120, 0), Space.World);
        }
        else
        {
            // Movement
            if (Input.GetAxisRaw("Horizontal") != 0 && xVelocity < moveSpeed && xVelocity > -moveSpeed)
            {
                xVelocity += Input.GetAxisRaw("Horizontal") * moveSpeed / 30;
            }
            else if (xVelocity > 0.05f)
            {
                xVelocity -= moveSpeed / 60;
            }
            else if (xVelocity < -0.05f)
            {
                xVelocity += moveSpeed / 60;
            }
            else
            {
                xVelocity = 0;
            }

            if (Input.GetAxisRaw("Vertical") != 0 && zVelocity < moveSpeed && zVelocity > -moveSpeed)
            {
                zVelocity += Input.GetAxisRaw("Vertical") * moveSpeed / 30;
            }
            else if (zVelocity > 0.05f)
            {
                zVelocity -= moveSpeed / 60;
            }
            else if (zVelocity < -0.05f)
            {
                zVelocity += moveSpeed / 60;
            }
            else
            {
                zVelocity = 0;
            }
            transform.Translate(new Vector3(xVelocity, 0, zVelocity), Space.Self);

            // Height
            if (Input.GetMouseButtonDown(0))
            {
                mouse0Down = true;
            }
            else if (Input.GetMouseButtonUp(0))
            {
                mouse0Down = false;
            }

            if (Input.GetMouseButtonDown(1))
            {
                mouse1Down = true;
            }
            else if (Input.GetMouseButtonUp(1))
            {
                mouse1Down = false;
            }

            if (mouse0Down)
            {
                height += moveSpeed;
            }
            if (mouse1Down)
            {
                height -= moveSpeed;
            }

            transform.position = new Vector3(transform.position.x, height, transform.position.z);

            //Rotation
            rotationY += Input.GetAxis("Mouse Y") * sensitivity;
            rotationX += Input.GetAxis("Mouse X") * sensitivity;

            Quaternion yQuaternion = Quaternion.AngleAxis(rotationY, Vector3.left);
            Quaternion xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up);

            transform.localRotation = startRotation * xQuaternion * yQuaternion;
        }
    }