in Assets/MixedRealityToolkit.SDK/Features/UX/Scripts/Pointers/TeleportPointer.cs [302:419]
public override void OnInputChanged(InputEventData<Vector2> eventData)
{
// Don't process input if we've got an active teleport request in progress.
if (isTeleportRequestActive || !MixedRealityToolkit.IsTeleportSystemEnabled)
{
return;
}
if (eventData.SourceId == InputSourceParent.SourceId &&
eventData.Handedness == Handedness &&
eventData.MixedRealityInputAction == teleportAction)
{
currentInputPosition = eventData.InputData;
}
if (Mathf.Abs(currentInputPosition.y) > inputThreshold ||
Mathf.Abs(currentInputPosition.x) > inputThreshold)
{
// Get the angle of the pointer input
float angle = Mathf.Atan2(currentInputPosition.x, currentInputPosition.y) * Mathf.Rad2Deg;
// Offset the angle so it's 'forward' facing
angle += angleOffset;
PointerOrientation = angle;
if (!teleportEnabled)
{
float absoluteAngle = Mathf.Abs(angle);
if (absoluteAngle < teleportActivationAngle)
{
teleportEnabled = true;
MixedRealityToolkit.TeleportSystem?.RaiseTeleportRequest(this, TeleportHotSpot);
}
else if (canMove)
{
// wrap the angle value.
if (absoluteAngle > 180f)
{
absoluteAngle = Mathf.Abs(absoluteAngle - 360f);
}
// Calculate the offset rotation angle from the 90 degree mark.
// Half the rotation activation angle amount to make sure the activation angle stays centered at 90.
float offsetRotationAngle = 90f - rotateActivationAngle;
// subtract it from our current angle reading
offsetRotationAngle = absoluteAngle - offsetRotationAngle;
// if it's less than zero, then we don't have activation
if (offsetRotationAngle > 0)
{
// check to make sure we're still under our activation threshold.
if (offsetRotationAngle < rotateActivationAngle)
{
canMove = false;
// Rotate the camera by the rotation amount. If our angle is positive then rotate in the positive direction, otherwise in the opposite direction.
MixedRealityToolkit.Instance.MixedRealityPlayspace.RotateAround(CameraCache.Main.transform.position, Vector3.up, angle >= 0.0f ? rotationAmount : -rotationAmount);
}
else // We may be trying to strafe backwards.
{
// Calculate the offset rotation angle from the 180 degree mark.
// Half the strafe activation angle to make sure the activation angle stays centered at 180f
float offsetStrafeAngle = 180f - backStrafeActivationAngle;
// subtract it from our current angle reading
offsetStrafeAngle = absoluteAngle - offsetStrafeAngle;
// Check to make sure we're still under our activation threshold.
if (offsetStrafeAngle > 0 && offsetStrafeAngle < backStrafeActivationAngle)
{
canMove = false;
var height = MixedRealityToolkit.Instance.MixedRealityPlayspace.position.y;
var newPosition = -CameraCache.Main.transform.forward * strafeAmount + MixedRealityToolkit.Instance.MixedRealityPlayspace.position;
newPosition.y = height;
MixedRealityToolkit.Instance.MixedRealityPlayspace.position = newPosition;
}
}
}
}
}
}
else
{
if (!canTeleport && !teleportEnabled)
{
// Reset the move flag when the user stops moving the joystick
// but hasn't yet started teleport request.
canMove = true;
}
if (canTeleport)
{
canTeleport = false;
teleportEnabled = false;
if (TeleportSurfaceResult == TeleportSurfaceResult.Valid ||
TeleportSurfaceResult == TeleportSurfaceResult.HotSpot)
{
MixedRealityToolkit.TeleportSystem?.RaiseTeleportStarted(this, TeleportHotSpot);
}
}
if (teleportEnabled)
{
canTeleport = false;
teleportEnabled = false;
MixedRealityToolkit.TeleportSystem?.RaiseTeleportCanceled(this, TeleportHotSpot);
}
}
if (teleportEnabled &&
TeleportSurfaceResult == TeleportSurfaceResult.Valid ||
TeleportSurfaceResult == TeleportSurfaceResult.HotSpot)
{
canTeleport = true;
}
}