예제 #1
0
 void localMotion(EasyInput.Core.Motion motion)
 {
     userAccelXValue.text       = motion.currentRawUserAcceleration.x.ToString();
     userAccelYValue.text       = motion.currentRawUserAcceleration.y.ToString();
     userAccelZValue.text       = motion.currentRawUserAcceleration.z.ToString();
     gravityXValue.text         = motion.currentRawGravity.x.ToString();
     gravityYValue.text         = motion.currentRawGravity.y.ToString();
     gravityZValue.text         = motion.currentRawGravity.z.ToString();
     smoothUserAccelXValue.text = motion.currentSmoothedUserAcceleration.x.ToString();
     smoothUserAccelYValue.text = motion.currentSmoothedUserAcceleration.y.ToString();
     smoothUserAccelZValue.text = motion.currentSmoothedUserAcceleration.z.ToString();
     smoothGravityXValue.text   = motion.currentSmoothedGravity.x.ToString();
     smoothGravityYValue.text   = motion.currentSmoothedGravity.y.ToString();
     smoothGravityZValue.text   = motion.currentSmoothedGravity.z.ToString();
     velocityXValue.text        = motion.currentVelocity.x.ToString();
     velocityYValue.text        = motion.currentVelocity.y.ToString();
     velocityZValue.text        = motion.currentVelocity.z.ToString();
     positionXValue.text        = motion.currentRelativePositionSinceReset.x.ToString();
     positionYValue.text        = motion.currentRelativePositionSinceReset.y.ToString();
     positionZValue.text        = motion.currentRelativePositionSinceReset.z.ToString();
     orientationXValue.text     = motion.currentOrientation.x.ToString();
     orientationYValue.text     = motion.currentOrientation.y.ToString();
     orientationZValue.text     = motion.currentOrientation.z.ToString();
     rotationXValue.text        = motion.currentRotationRate.x.ToString();
     rotationYValue.text        = motion.currentRotationRate.y.ToString();
     rotationZValue.text        = motion.currentRotationRate.z.ToString();
     totVelocityXValue.text     = motion.totalVelocitySinceReset.x.ToString();
     totVelocityYValue.text     = motion.totalVelocitySinceReset.y.ToString();
     totVelocityZValue.text     = motion.totalVelocitySinceReset.z.ToString();
     totRotationXValue.text     = motion.totalRotationRateSinceReset.x.ToString();
     totRotationYValue.text     = motion.totalRotationRateSinceReset.y.ToString();
     totRotationZValue.text     = motion.totalRotationRateSinceReset.z.ToString();
 }
예제 #2
0
        void trackThrow(EasyInput.Core.Motion motion)
        {
            if (throwInProcess)
            {
                //there are a couple of factors that you see in a bowling motion if you look at the telemetry
                //left or right handed can be determined from the x axis user acceleration during the backswing (doesn't matter in this demo but if we had animation of a player could be used for that)
                //hardness of throw can use the user acceleration z axis during the forward swing (higher value harder throw)
                //spin can be determined from the x and z axis during forward part of the throw

                //aim of shot is the hardest as some drift will have already occured (the aim is really only dictated by
                //the direction going the last few frames before release of the button) best place to gauge this is the velocity
                //vector but there will have been some drift and in tests the sensors on board aren't good enough
                //so instead user will actually pick aim before throw

                //base hardness off current velocity.z (light throw tends to be around 1.0 and really hard around 3.0)
                //in terms of the game the lightest throw should be 450 and the hardest be 700
                if (motion.totalVelocitySinceReset.magnitude > 10f)
                {
                    currentThrow.z = 365f + (85f * motion.currentVelocity.z);
                }
                else
                {
                    //we hit and released the button but we didn't really do the motion
                    currentThrow.z = 10f;
                }

                //calculate the x component off the previously detemined aim (degreesOff)
                currentThrow.x = degreesOff * (currentThrow.z / 100);

                //base spin off of currentorientation.x (none = < 5f)

                if (motion.currentOrientation.x < 20f && motion.currentOrientation.x > -20f)
                {
                    currentTorque.z = 0f;
                }
                else
                {
                    currentTorque.z = motion.currentOrientation.x / 8f;
                }
            }
            else if (!throwInProcess && !preventThrowAgain)
            {
                if (motion.currentOrientation.x < aimDegreesClamp && motion.currentOrientation.x > -aimDegreesClamp)
                {
                    temp   = aimArrow.localRotation.eulerAngles;
                    temp.y = 270f - motion.currentOrientation.x;
                    aimArrow.localRotation = Quaternion.Euler(temp);

                    //aim will get expressed in the x component of currentThrow and is a percentage of the z component
                    //number of degrees of aim arrow is rotation times current throw z component divided by 100
                    //we won't know the z component until we throw the ball
                    degreesOff = aimArrow.localRotation.eulerAngles.y - 270f;
                }
            }
        }