Exemplo n.º 1
0
        protected virtual Vector3 ProjectDownBeam(Vector3 jointPosition)
        {
            Vector3    downPosition             = Vector3.zero;
            Ray        projectedBeamDownRaycast = new Ray(jointPosition, Vector3.down);
            RaycastHit collidedWith;

#pragma warning disable 0618
            bool downRayHit = VRTK_CustomRaycast.Raycast(customRaycast, projectedBeamDownRaycast, out collidedWith, layersToIgnore, maximumLength.y);
#pragma warning restore 0618

            if (!downRayHit || (destinationHit.collider && destinationHit.collider != collidedWith.collider))
            {
                if (destinationHit.collider != null)
                {
                    PointerExit(destinationHit);
                }
                destinationHit = new RaycastHit();
                downPosition   = projectedBeamDownRaycast.GetPoint(0f);
            }

            if (downRayHit)
            {
                downPosition = projectedBeamDownRaycast.GetPoint(collidedWith.distance);
                PointerEnter(collidedWith);
                destinationHit = collidedWith;
            }
            return(downPosition);
        }
Exemplo n.º 2
0
        protected virtual void CalculateLean(Vector3 startPosition, float forwardLength, float originalRayDistance)
        {
            //Cast the new down ray based on the position of the end of the forward ray but still at a flat plane of the headset forward (i.e. no headset rotation)
            Vector3 rayDownStartPosition = startPosition + (headset.forward * forwardLength);

            rayDownStartPosition = new Vector3(rayDownStartPosition.x, startPosition.y, rayDownStartPosition.z);

            Ray        downRay = new Ray(rayDownStartPosition, -playArea.up);
            RaycastHit downRayCollision;

            //Cast a ray down from the end of the forward ray position
#pragma warning disable 0618
            if (VRTK_CustomRaycast.Raycast(customRaycast, downRay, out downRayCollision, layersToIgnore, Mathf.Infinity))
#pragma warning restore 0618
            {
                //Determine the difference between the original down ray and the projected forward a bit downray
                float rayDownDelta = VRTK_SharedMethods.RoundFloat(originalRayDistance - downRayCollision.distance, decimalPrecision);
                //Determine the difference between the current play area position and the last play area position
                float playAreaPositionDelta = VRTK_SharedMethods.RoundFloat(Vector3.Distance(playArea.transform.position, lastPlayAreaPosition), decimalPrecision);
                //If the play area is not moving and the delta between the down rays is greater than 0 then you're probably walking forward over something you can stand on
                isMoving = (onGround && playAreaPositionDelta <= playAreaPositionThreshold && rayDownDelta > 0f ? true : isMoving);

                //If the item your standing over is too high to walk on top of then allow leaning over it.
                isLeaning = (onGround && rayDownDelta > leanYThreshold ? true : false);
            }
        }
Exemplo n.º 3
0
        protected virtual float CastRayForward()
        {
            Transform origin = GetOrigin();

            if (origin == null)
            {
                return(0);
            }

            Ray        pointerRaycast = new Ray(origin.position, origin.forward);
            RaycastHit pointerCollidedWith;
            bool       rayHit = VRTK_CustomRaycast.Raycast(customRaycast, pointerRaycast, out pointerCollidedWith, defaultIgnoreLayer, maximumLength);

            CheckRayMiss(rayHit, pointerCollidedWith);
            CheckRayHit(rayHit, pointerCollidedWith);

            float actualLength = maximumLength;

            if (rayHit && pointerCollidedWith.distance < maximumLength)
            {
                actualLength = pointerCollidedWith.distance;
            }

            return(OverrideBeamLength(actualLength));
        }
        protected virtual float CastRayForward()
        {
            Transform  origin         = GetOrigin();
            Ray        pointerRaycast = new Ray(origin.position, origin.forward);
            RaycastHit pointerCollidedWith;

            bool rayHit = VRTK_CustomRaycast.Raycast(customRaycast, pointerRaycast, out pointerCollidedWith, layersToIgnore, maximumLength);

            OnGround(rayHit, pointerCollidedWith);
            CheckRayMiss(rayHit, pointerCollidedWith);
            CheckRayHit(rayHit, pointerCollidedWith);

            // SETTING WAYPOINT
            MarkGroundPoint(rayHit, pointerCollidedWith);
            SelectDrone(rayHit, pointerCollidedWith);
            lineSelected = SelectedLine(rayHit, pointerCollidedWith);
            // SETTING WAYPOINT

            //LogHeight(rayHit, pointerCollidedWith);

            float actualLength = maximumLength;

            if (rayHit && pointerCollidedWith.distance < maximumLength)
            {
                actualLength = pointerCollidedWith.distance;
            }

            return(OverrideBeamLength(actualLength));
        }
Exemplo n.º 5
0
        protected virtual Vector3 ProjectDownBeam(Vector3 jointPosition)
        {
            Vector3    downPosition             = Vector3.zero;
            Ray        projectedBeamDownRaycast = new Ray(jointPosition, Vector3.down);
            RaycastHit collidedWith;

            bool downRayHit = VRTK_CustomRaycast.Raycast(customRaycast, projectedBeamDownRaycast, out collidedWith, layersToIgnore, float.PositiveInfinity);

            if (!downRayHit || (destinationHit.collider && destinationHit.collider != collidedWith.collider))
            {
                if (destinationHit.collider != null)
                {
                    PointerExit(destinationHit);
                }
                destinationHit = new RaycastHit();
                downPosition   = projectedBeamDownRaycast.GetPoint(0f);
            }

            if (downRayHit)
            {
                downPosition = projectedBeamDownRaycast.GetPoint(collidedWith.distance);
                PointerEnter(collidedWith);
                destinationHit = collidedWith;
            }
            return(downPosition);
        }
Exemplo n.º 6
0
        protected virtual void CheckLean()
        {
            //Cast a ray down from the current standing position
            Vector3    standingDownRayStartPosition = (headset ? new Vector3(currentStandingPosition.x, headset.position.y, currentStandingPosition.y) : Vector3.zero);
            Vector3    rayDirection    = (playArea ? -playArea.up : Vector3.zero);
            Ray        standingDownRay = new Ray(standingDownRayStartPosition, rayDirection);
            RaycastHit standingDownRayCollision;
            bool       standingDownRayHit = VRTK_CustomRaycast.Raycast(customRaycast, standingDownRay, out standingDownRayCollision, layersToIgnore, Mathf.Infinity);

            if (standingDownRayHit)
            {
                currentValidFloorObject = standingDownRayCollision.collider.gameObject;
            }

            //Don't bother checking for lean if body collisions are disabled
            if (!headset || !playArea || !enableBodyCollisions)
            {
                return;
            }

            //reset the headset x rotation so the forward ray is always horizontal regardless of the headset rotation
            Quaternion storedRotation = headset.rotation;

            headset.rotation = new Quaternion(0f, headset.rotation.y, headset.rotation.z, headset.rotation.w);

            float forwardLengthAddition = 0.05f;
            float forwardLength         = bodyCollider.radius + forwardLengthAddition;

            Ray        forwardRay = new Ray(headset.position, headset.forward);
            RaycastHit forwardRayCollision;

            // Cast a ray forward just outside the body collider radius to see if anything is blocking your path
            if (!VRTK_CustomRaycast.Raycast(customRaycast, forwardRay, out forwardRayCollision, layersToIgnore, forwardLength))
            {
                if (standingDownRayHit)
                {
                    Vector3    rayDownStartPosition = headset.position + headset.forward * forwardLength;
                    Ray        downRay = new Ray(rayDownStartPosition, -playArea.up);
                    RaycastHit downRayCollision;

                    //Cast a ray down from the end of the forward ray position
                    if (VRTK_CustomRaycast.Raycast(customRaycast, downRay, out downRayCollision, layersToIgnore, Mathf.Infinity))
                    {
                        float distancePrecision     = 1000f;
                        float rayDownDelta          = (Mathf.Round((standingDownRayCollision.distance - downRayCollision.distance) * distancePrecision) / distancePrecision);
                        float playAreaPositionDelta = Mathf.Round(Vector3.Distance(playArea.transform.position, lastPlayAreaPosition) * distancePrecision) / distancePrecision;

                        //If the play area is not moving and the delta between the down rays is greater than 0 then you're probably walking forward over something you can stand on
                        isMoving = (onGround && playAreaPositionDelta <= 0.002f && rayDownDelta > 0f ? true : isMoving);

                        //If the item your standing over is too high to walk on top of then allow leaning over it.
                        isLeaning = (onGround && rayDownDelta > leanYThreshold ? true : false);
                    }
                }
            }

            //put the headset rotation back
            headset.rotation = storedRotation;
        }
Exemplo n.º 7
0
        protected virtual float ControllerHeightCheck(GameObject controllerObj)
        {
            Ray        ray = new Ray(controllerObj.transform.position, -playArea.up);
            RaycastHit rayCollidedWith;

            VRTK_CustomRaycast.Raycast(customRaycast, ray, out rayCollidedWith, layersToIgnore, Mathf.Infinity);
            return(controllerObj.transform.position.y - rayCollidedWith.distance);
        }
        protected override float CastRayForward()
        {
            Transform  origin         = GetOrigin();
            Ray        pointerRaycast = new Ray(origin.position, origin.forward);
            RaycastHit pointerCollidedWith;
            bool       rayHit = VRTK_CustomRaycast.Raycast(customRaycast, pointerRaycast, out pointerCollidedWith, defaultIgnoreLayer, maximumLength);

            CheckRayMiss(rayHit, pointerCollidedWith);
            CheckRayHit(rayHit, pointerCollidedWith);

            float actualLength = maximumLength;

            if (rayHit && pointerCollidedWith.distance < maximumLength)
            {
                actualLength = pointerCollidedWith.distance;
            }

            //当たってる対象がAnimationWindowならマウス操作
            if (rayHit && pointerCollidedWith.collider.tag == "AnimationWindow")
            {
                var mousePosInEditorWindow = animationWindowController.GetMousePosInEditorWindowFromUV(pointerCollidedWith.textureCoord);
                if (mousePosInEditorWindow != null && editorWindowCapture != null)
                {
                    //pointer.position = desktopPos.Value;
                    pointerPos = mousePosInEditorWindow.Value;

                    if (state == TouchState.Release)
                    {
                        //GetPointer();
                        //pointer.Hover();
                        state = TouchState.Hover;
                        editorWindowCapture.SendEvent(pointerPos, EventType.MouseMove);
                    }
                    else
                    {
                        editorWindowCapture.SendEvent(pointerPos, EventType.MouseDrag);
                    }
                }

                GetComponent <VRTK.VRTK_Pointer>().Toggle(true);
            }
            //UIに当たってればUI操作
            else if (uiPointer.pointerEventData.pointerEnter)
            {
                GetComponent <VRTK.VRTK_Pointer>().Toggle(true);
            }
            //AnimationWindowにもUIにも当たっていない
            else
            {
                state = TouchState.Release;
                GetComponent <VRTK.VRTK_Pointer>().Toggle(false);
                GetComponent <VRTK.VRTK_Pointer>().pointerRenderer.Toggle(false, false);
            }

            return(OverrideBeamLength(actualLength));
        }
        protected virtual void AdjustForEarlyCollisions(Vector3 jointPosition, Vector3 downPosition)
        {
            Vector3 newDownPosition  = downPosition;
            Vector3 newJointPosition = jointPosition;

            //  Debug.Log("Exit1");

            if (collisionCheckFrequency > 0 && actualTracer != null)
            {
                collisionCheckFrequency = Mathf.Clamp(collisionCheckFrequency, 0, tracerDensity);
                Vector3[] beamPoints = new Vector3[]
                {
                    GetOrigin().position,
                    jointPosition + new Vector3(0f, curveOffset, 0f),
                    downPosition,
                    downPosition,
                };

                Vector3[] checkPoints    = actualTracer.GetPoints(beamPoints);
                int       checkFrequency = tracerDensity / collisionCheckFrequency;

                for (int i = 0; i < tracerDensity - checkFrequency; i += checkFrequency)
                {
                    Vector3 currentPoint       = checkPoints[i];
                    Vector3 nextPoint          = (i + checkFrequency < checkPoints.Length ? checkPoints[i + checkFrequency] : checkPoints[checkPoints.Length - 1]);
                    Vector3 nextPointDirection = (nextPoint - currentPoint).normalized;
                    float   nextPointDistance  = Vector3.Distance(currentPoint, nextPoint);

                    Ray        checkCollisionRay = new Ray(currentPoint, nextPointDirection);
                    RaycastHit checkCollisionHit;

#pragma warning disable 0618
                    if (VRTK_CustomRaycast.Raycast(customRaycast, checkCollisionRay, out checkCollisionHit, layersToIgnore, nextPointDistance))
#pragma warning restore 0618
                    {
                        Vector3    collisionPoint   = checkCollisionRay.GetPoint(checkCollisionHit.distance);
                        Ray        downwardCheckRay = new Ray(collisionPoint + (Vector3.up * 0.01f), Vector3.down);
                        RaycastHit downwardCheckHit;

#pragma warning disable 0618
                        if (VRTK_CustomRaycast.Raycast(customRaycast, downwardCheckRay, out downwardCheckHit, layersToIgnore, float.PositiveInfinity))
#pragma warning restore 0618
                        {
                            destinationHit   = downwardCheckHit;
                            newDownPosition  = downwardCheckRay.GetPoint(downwardCheckHit.distance);;
                            newJointPosition = (newDownPosition.y < jointPosition.y ? new Vector3(newDownPosition.x, jointPosition.y, newDownPosition.z) : jointPosition);
                            break;
                        }
                    }
                }
            }

            DisplayCurvedBeam(newJointPosition, newDownPosition);
            SetPointerCursor();
        }
Exemplo n.º 10
0
 protected virtual void AdjustForParentOffset()
 {
     if (snapToNearestFloor && applyPlayareaParentOffset && playArea != null && playArea.parent != null)
     {
         Ray        ray = new Ray(playArea.parent.position, -playArea.up);
         RaycastHit rayCollidedWith;
         if (VRTK_CustomRaycast.Raycast(customRaycast, ray, out rayCollidedWith, Physics.IgnoreRaycastLayer, Mathf.Infinity, QueryTriggerInteraction.Ignore))
         {
             playArea.position = new Vector3(playArea.position.x, playArea.position.y + rayCollidedWith.point.y, playArea.position.z);
         }
     }
 }
Exemplo n.º 11
0
        protected virtual Vector3 ProjectForwardBeam()
        {
            Transform origin           = GetOrigin();
            float     attachedRotation = Vector3.Dot(Vector3.up, origin.forward.normalized);
            float     calculatedLength = maximumLength.x;
            Vector3   useForward       = origin.forward;

            if ((attachedRotation * 100f) > heightLimitAngle)
            {
                useForward = new Vector3(useForward.x, fixedForwardBeamForward.y, useForward.z);
                float controllerRotationOffset = 1f - (attachedRotation - (heightLimitAngle / 100f));
                calculatedLength = (maximumLength.x * controllerRotationOffset) * controllerRotationOffset;
            }
            else
            {
                fixedForwardBeamForward = origin.forward;
            }

            float actualLength   = calculatedLength;
            Ray   pointerRaycast = new Ray(origin.position, useForward);

            RaycastHit collidedWith;

#pragma warning disable 0618
            bool hasRayHit = VRTK_CustomRaycast.Raycast(customRaycast, pointerRaycast, out collidedWith, layersToIgnore, calculatedLength);
#pragma warning restore 0618

            float contactDistance = 0f;
            //reset if beam not hitting or hitting new target
            if (!hasRayHit || (destinationHit.collider && destinationHit.collider != collidedWith.collider))
            {
                contactDistance = 0f;
            }

            //check if beam has hit a new target
            if (hasRayHit)
            {
                contactDistance = collidedWith.distance;
            }

            //adjust beam length if something is blocking it
            if (hasRayHit && contactDistance < calculatedLength)
            {
                actualLength = contactDistance;
            }

            //Use BEAM_ADJUST_OFFSET to move point back and up a bit to prevent beam clipping at collision point
            return(pointerRaycast.GetPoint(actualLength - BEAM_ADJUST_OFFSET) + (Vector3.up * BEAM_ADJUST_OFFSET));
        }
        protected virtual float GetTeleportY(Transform target, Vector3 tipPosition)
        {
            float newY         = playArea.position.y;
            float heightOffset = 0.1f;
            //Check to see if the tip is on top of an object
            Vector3    rayStartPositionOffset = Vector3.up * heightOffset;
            Ray        ray = new Ray(tipPosition + rayStartPositionOffset, -playArea.up);
            RaycastHit rayCollidedWith;

            if (target && VRTK_CustomRaycast.Raycast(customRaycast, ray, out rayCollidedWith, layersToIgnore, Mathf.Infinity))
            {
                newY = (tipPosition.y - rayCollidedWith.distance) + heightOffset;
            }
            return(newY);
        }
Exemplo n.º 13
0
        // Token: 0x060018C5 RID: 6341 RVA: 0x000840CC File Offset: 0x000822CC
        protected virtual float CastRayForward()
        {
            Transform  origin = base.GetOrigin(true);
            Ray        ray    = new Ray(origin.position, origin.forward);
            RaycastHit pointerCollidedWith;
            bool       flag = VRTK_CustomRaycast.Raycast(this.customRaycast, ray, out pointerCollidedWith, this.layersToIgnore, this.maximumLength, QueryTriggerInteraction.UseGlobal);

            this.CheckRayMiss(flag, pointerCollidedWith);
            this.CheckRayHit(flag, pointerCollidedWith);
            float distance = this.maximumLength;

            if (flag && pointerCollidedWith.distance < this.maximumLength)
            {
                distance = pointerCollidedWith.distance;
            }
            return(this.OverrideBeamLength(distance));
        }
Exemplo n.º 14
0
        // Token: 0x060017DA RID: 6106 RVA: 0x0007F1DC File Offset: 0x0007D3DC
        protected virtual float GetTeleportY(Transform target, Vector3 tipPosition)
        {
            if (!this.snapToNearestFloor || !this.ValidRigObjects())
            {
                return(tipPosition.y);
            }
            float      result = this.playArea.position.y;
            float      num    = 0.1f;
            Vector3    b      = Vector3.up * num;
            Ray        ray    = new Ray(tipPosition + b, -this.playArea.up);
            RaycastHit raycastHit;

            if (target != null && VRTK_CustomRaycast.Raycast(this.customRaycast, ray, out raycastHit, this.layersToIgnore, float.PositiveInfinity, QueryTriggerInteraction.Ignore))
            {
                result = tipPosition.y - raycastHit.distance + num;
            }
            return(result);
        }
Exemplo n.º 15
0
        // Token: 0x060018B4 RID: 6324 RVA: 0x000837DC File Offset: 0x000819DC
        protected virtual void AdjustForEarlyCollisions(Vector3 jointPosition, Vector3 downPosition)
        {
            Vector3 vector         = downPosition;
            Vector3 jointPosition2 = jointPosition;

            if (this.collisionCheckFrequency > 0 && this.actualTracer != null)
            {
                this.collisionCheckFrequency = Mathf.Clamp(this.collisionCheckFrequency, 0, this.tracerDensity);
                Vector3[] controlPoints = new Vector3[]
                {
                    base.GetOrigin(true).position,
                    jointPosition + new Vector3(0f, this.curveOffset, 0f),
                    downPosition,
                    downPosition
                };
                Vector3[] points = this.actualTracer.GetPoints(controlPoints);
                int       num    = this.tracerDensity / this.collisionCheckFrequency;
                for (int i = 0; i < this.tracerDensity - num; i += num)
                {
                    Vector3    vector2    = points[i];
                    Vector3    vector3    = (i + num < points.Length) ? points[i + num] : points[points.Length - 1];
                    Vector3    normalized = (vector3 - vector2).normalized;
                    float      length     = Vector3.Distance(vector2, vector3);
                    Ray        ray        = new Ray(vector2, normalized);
                    RaycastHit raycastHit;
                    if (VRTK_CustomRaycast.Raycast(this.customRaycast, ray, out raycastHit, this.layersToIgnore, length, QueryTriggerInteraction.UseGlobal))
                    {
                        Vector3    point = ray.GetPoint(raycastHit.distance);
                        Ray        ray2  = new Ray(point + Vector3.up * 0.01f, Vector3.down);
                        RaycastHit destinationHit;
                        if (VRTK_CustomRaycast.Raycast(this.customRaycast, ray2, out destinationHit, this.layersToIgnore, float.PositiveInfinity, QueryTriggerInteraction.UseGlobal))
                        {
                            this.destinationHit = destinationHit;
                            vector         = ray2.GetPoint(destinationHit.distance);
                            jointPosition2 = ((vector.y < jointPosition.y) ? new Vector3(vector.x, jointPosition.y, vector.z) : jointPosition);
                            break;
                        }
                    }
                }
            }
            this.DisplayCurvedBeam(jointPosition2, vector);
            this.SetPointerCursor();
        }
Exemplo n.º 16
0
        protected virtual void SnapToNearestFloor()
        {
            if (!preventSnapToFloor && (enableBodyCollisions || enableTeleport) && headset && headset.transform.position.y > playArea.position.y)
            {
                Ray        ray = new Ray(headset.transform.position, -playArea.up);
                RaycastHit rayCollidedWith;
                bool       rayHit = VRTK_CustomRaycast.Raycast(customRaycast, ray, out rayCollidedWith, layersToIgnore, Mathf.Infinity);
                hitFloorYDelta = playArea.position.y - rayCollidedWith.point.y;

                if (initialFloorDrop && (ValidDrop(rayHit, rayCollidedWith, rayCollidedWith.point.y) || retogglePhysicsOnCanFall))
                {
                    storedCurrentPhysics      = ArePhysicsEnabled();
                    resetPhysicsAfterTeleport = false;
                    TogglePhysics(false);

                    HandleFall(rayCollidedWith.point.y, rayCollidedWith);
                }
                initialFloorDrop = true;
                lastFrameFloorY  = rayCollidedWith.point.y;
            }
        }
Exemplo n.º 17
0
        protected virtual float CastRayForward()
        {
            Transform  origin         = GetOrigin();
            Ray        pointerRaycast = new Ray(origin.position, origin.forward);
            RaycastHit pointerCollidedWith;

#pragma warning disable 0618
            bool rayHit = VRTK_CustomRaycast.Raycast(customRaycast, pointerRaycast, out pointerCollidedWith, layersToIgnore, maximumLength);
#pragma warning restore 0618

            CheckRayMiss(rayHit, pointerCollidedWith);
            CheckRayHit(rayHit, pointerCollidedWith);

            float actualLength = maximumLength;
            if (rayHit && pointerCollidedWith.distance < maximumLength)
            {
                actualLength = pointerCollidedWith.distance;
            }

            return(OverrideBeamLength(actualLength));
        }
Exemplo n.º 18
0
        protected virtual void CheckLean()
        {
            //Cast a ray down from the current standing position
            Vector3    standingDownRayStartPosition = (headset != null ? new Vector3(currentStandingPosition.x, headset.position.y, currentStandingPosition.y) : Vector3.zero);
            Vector3    rayDirection    = (playArea != null ? -playArea.up : Vector3.zero);
            Ray        standingDownRay = new Ray(standingDownRayStartPosition, rayDirection);
            RaycastHit standingDownRayCollision;

            //Determine the current valid floor that the user is standing over
#pragma warning disable 0618
            currentValidFloorObject = (VRTK_CustomRaycast.Raycast(customRaycast, standingDownRay, out standingDownRayCollision, layersToIgnore, Mathf.Infinity) ? standingDownRayCollision.collider.gameObject : null);
#pragma warning restore 0618

            //Don't bother checking for lean if body collisions are disabled
            if (headset == null || playArea == null || !enableBodyCollisions)
            {
                return;
            }

            //reset the headset x rotation so the forward ray is always horizontal regardless of the headset rotation
            Quaternion storedRotation = headset.rotation;
            headset.rotation = new Quaternion(0f, headset.rotation.y, headset.rotation.z, headset.rotation.w);

            Ray        forwardRay = new Ray(headset.position, headset.forward);
            RaycastHit forwardRayCollision;
            //Determine the maximum forward distance to cast the forward ray
            float forwardLength = bodyCollider.radius + leanForwardLengthAddition;

            // Cast a ray forward just outside the body collider radius to see if anything is blocking your path
            // If nothing is blocking your path and you're currently standing over a valid floor
#pragma warning disable 0618
            if (!VRTK_CustomRaycast.Raycast(customRaycast, forwardRay, out forwardRayCollision, layersToIgnore, forwardLength) && currentValidFloorObject != null)
#pragma warning restore 0618
            {
                CalculateLean(standingDownRayStartPosition, forwardLength, standingDownRayCollision.distance);
            }

            //put the headset rotation back
            headset.rotation = storedRotation;
        }
        protected virtual float GetTeleportY(Transform target, Vector3 tipPosition)
        {
            if (!snapToNearestFloor || !ValidRigObjects())
            {
                return(tipPosition.y);
            }

            float newY         = playArea.position.y;
            float heightOffset = 0.1f;
            //Check to see if the tip is on top of an object
            Vector3    rayStartPositionOffset = Vector3.up * heightOffset;
            Ray        ray = new Ray(tipPosition + rayStartPositionOffset, -playArea.up);
            RaycastHit rayCollidedWith;

#pragma warning disable 0618
            if (target != null && VRTK_CustomRaycast.Raycast(customRaycast, ray, out rayCollidedWith, layersToIgnore, Mathf.Infinity, QueryTriggerInteraction.Ignore))
#pragma warning restore 0618
            {
                newY = (tipPosition.y - rayCollidedWith.distance) + heightOffset;
            }
            return(newY);
        }
Exemplo n.º 20
0
        // Token: 0x060018B2 RID: 6322 RVA: 0x000835D0 File Offset: 0x000817D0
        protected virtual Vector3 ProjectForwardBeam()
        {
            Transform origin  = base.GetOrigin(true);
            float     num     = Vector3.Dot(Vector3.up, origin.forward.normalized);
            float     num2    = this.maximumLength.x;
            Vector3   forward = origin.forward;

            if (num * 100f > this.heightLimitAngle)
            {
                forward = new Vector3(forward.x, this.fixedForwardBeamForward.y, forward.z);
                float num3 = 1f - (num - this.heightLimitAngle / 100f);
                num2 = this.maximumLength.x * num3 * num3;
            }
            else
            {
                this.fixedForwardBeamForward = origin.forward;
            }
            float      num4 = num2;
            Ray        ray  = new Ray(origin.position, forward);
            RaycastHit raycastHit;
            bool       flag = VRTK_CustomRaycast.Raycast(this.customRaycast, ray, out raycastHit, this.layersToIgnore, num2, QueryTriggerInteraction.UseGlobal);
            float      num5 = 0f;

            if (!flag || (this.destinationHit.collider && this.destinationHit.collider != raycastHit.collider))
            {
                num5 = 0f;
            }
            if (flag)
            {
                num5 = raycastHit.distance;
            }
            if (flag && num5 < num2)
            {
                num4 = num5;
            }
            return(ray.GetPoint(num4 - 0.0001f) + Vector3.up * 0.0001f);
        }
Exemplo n.º 21
0
        // Token: 0x060018B3 RID: 6323 RVA: 0x00083714 File Offset: 0x00081914
        protected virtual Vector3 ProjectDownBeam(Vector3 jointPosition)
        {
            Vector3    result = Vector3.zero;
            Ray        ray    = new Ray(jointPosition, Vector3.down);
            RaycastHit raycastHit;
            bool       flag = VRTK_CustomRaycast.Raycast(this.customRaycast, ray, out raycastHit, this.layersToIgnore, this.maximumLength.y, QueryTriggerInteraction.UseGlobal);

            if (!flag || (this.destinationHit.collider && this.destinationHit.collider != raycastHit.collider))
            {
                if (this.destinationHit.collider != null)
                {
                    this.PointerExit(this.destinationHit);
                }
                this.destinationHit = default(RaycastHit);
                result = ray.GetPoint(0f);
            }
            if (flag)
            {
                result = ray.GetPoint(raycastHit.distance);
                this.PointerEnter(raycastHit);
                this.destinationHit = raycastHit;
            }
            return(result);
        }
Exemplo n.º 22
0
        protected virtual float CastRayForward()
        {
            Transform  origin         = GetOrigin();
            Ray        pointerRaycast = new Ray(origin.position, origin.forward);
            RaycastHit pointerCollidedWith;

            //Debug.Log(origin.position);
            // Debug.Log(origin.forward);
#pragma warning disable 0618
            bool rayHit = VRTK_CustomRaycast.Raycast(customRaycast, pointerRaycast, out pointerCollidedWith, layersToIgnore, maximumLength);
#pragma warning restore 0618

            CheckRayMiss(rayHit, pointerCollidedWith);
            CheckRayHit(rayHit, pointerCollidedWith);

            float actualLength = maximumLength;
            if (rayHit && pointerCollidedWith.distance < maximumLength)
            {
                actualLength = pointerCollidedWith.distance;
            }

            /*      GameObject volumesum = GameObject.Find("model/default");
             *    MeshCalculator vol = volumesum.GetComponent<MeshCalculator>();
             *    float volume = vol.sum;
             *    float surface = vol.sum1;
             *    areaLine = GetComponent<LineRenderer>();
             *    areaLine.SetColors(Color.yellow, Color.yellow);
             *    areaLine.SetWidth(0.01f, 0.01f);
             *    Button disButton = distenceButton.GetComponent<Button>();
             *    disButton.onClick.AddListener(distenceButtonClicked);
             *    Button areaButtonFinish = areaButton.GetComponent<Button>();
             *    areaButtonFinish.onClick.AddListener(areaButtonClicked);
             *    if (Input.GetKeyDown(KeyCode.B))
             *    {
             *         test1 = true;
             *         test2 = false;
             *    }
             *    if (Input.GetKeyDown(KeyCode.N))
             *    {
             *         test2 = true;
             *         test1 = false;
             *    }
             *    if (distenceButtonClick == true||test1==true)
             *    {
             *
             *        if (Input.GetMouseButtonDown(0))
             *        {
             *
             *            if (Physics.Raycast(pointerRaycast, out pointerCollidedWith))
             *            {
             *                position = pointerCollidedWith.point;
             *                LengthOfLineRenderer++;
             *       //       if (LengthOfLineRenderer <= 6)
             *        //      {
             *                    areaLine.SetVertexCount(LengthOfLineRenderer);
             *                    areaLine.SetPosition(LengthOfLineRenderer - 1, position);
             *                    // areaLine.positionCount = dis.Length;
             *                    dis[LengthOfLineRenderer - 1] = position;
             *                 // dis[LengthOfLineRenderer - 1] = position;
             *                    if (LengthOfLineRenderer >= 2)
             *                        distance = distance + Vector3.Distance(dis[LengthOfLineRenderer - 2], dis[LengthOfLineRenderer - 1]);
             *                    else
             *                        distance = 0;
             *        //      }
             *          }
             *            if (Input.GetKeyDown(KeyCode.R))
             *            {
             *                LengthOfLineRenderer = 0;
             *                distance = 0;
             *                areaNumber = 0;
             *                volume = 0;
             *                surface = 0;
             *            }
             *            distenceN1.text = "distence:" + distance * m;
             *        }
             *
             *    }
             *    if (areaButtonClick == true||test2==true)
             *    {
             *
             *        if (Input.GetMouseButtonDown(0))
             *        {
             *
             *            if (Physics.Raycast(pointerRaycast, out pointerCollidedWith))
             *            {
             *                position = pointerCollidedWith.point;
             *                LengthOfLineRenderer++;
             *                if (LengthOfLineRenderer <= 6)
             *                {
             *                    areaLine.SetVertexCount(LengthOfLineRenderer);
             *                    areaLine.SetPosition(LengthOfLineRenderer - 1, position);
             *
             *                    dis[LengthOfLineRenderer - 1] = position;
             *                    if (LengthOfLineRenderer == 3)
             *                    {
             *                        areaLine.loop = true;
             *                        //Debug.Log(dis[0]);
             *                        // side[LengthOfLineRenderer - 1] = System.Math.Sqrt(System.Math.Pow(dis[LengthOfLineRenderer].x - dis[LengthOfLineRenderer - 1].x, 2)
             *                        //     + System.Math.Pow(dis[LengthOfLineRenderer].y - dis[LengthOfLineRenderer - 1].y, 2)
             *                        //     + System.Math.Pow(dis[LengthOfLineRenderer].z - dis[LengthOfLineRenderer - 1].z, 2));
             *                        side[0] = System.Math.Sqrt(System.Math.Pow(dis[1].x - dis[0].x, 2)
             + System.Math.Pow(dis[1].y - dis[0].y, 2)
             + System.Math.Pow(dis[1].z - dis[0].z, 2));
             +                        side[1] = System.Math.Sqrt(System.Math.Pow(dis[2].x - dis[1].x, 2)
             + System.Math.Pow(dis[2].y - dis[1].y, 2)
             + System.Math.Pow(dis[2].z - dis[1].z, 2));
             +                        side[2] = System.Math.Sqrt(System.Math.Pow(dis[0].x - dis[2].x, 2)
             + System.Math.Pow(dis[0].y - dis[2].y, 2)
             + System.Math.Pow(dis[0].z - dis[2].z, 2));
             +
             +                        if (side[0] + side[1] <= side[2] || side[0] + side[2] <= side[1] || side[1] + side[2] <= side[0])
             +                        {
             +                            areaNumber = 0;
             +                        }
             +                        else
             +                        {
             +                            double p = (side[0] + side[1] + side[2]) / 2;
             +                            //Debug.Log(p);
             +                            areaNumber = System.Math.Sqrt(p * (p - side[0]) * (p - side[1]) * (p - side[2]));
             +                        }
             +                        //Debug.Log(dis[LengthOfLineRenderer].x);
             +                        //Debug.Log(side[0]);
             +                        // Debug.Log(areaNumber);
             +                    }
             +                    if (LengthOfLineRenderer == 4)
             +                    {
             +                        areaLine.loop = true;
             +                        side[0] = System.Math.Sqrt(System.Math.Pow(dis[1].x - dis[0].x, 2)
             + System.Math.Pow(dis[1].y - dis[0].y, 2)
             + System.Math.Pow(dis[1].z - dis[0].z, 2));
             +                        side[1] = System.Math.Sqrt(System.Math.Pow(dis[2].x - dis[1].x, 2)
             + System.Math.Pow(dis[2].y - dis[1].y, 2)
             + System.Math.Pow(dis[2].z - dis[1].z, 2));
             +                        side[2] = System.Math.Sqrt(System.Math.Pow(dis[0].x - dis[2].x, 2)
             + System.Math.Pow(dis[0].y - dis[2].y, 2)
             + System.Math.Pow(dis[0].z - dis[2].z, 2));
             +                        side[3] = System.Math.Sqrt(System.Math.Pow(dis[3].x - dis[2].x, 2)
             + System.Math.Pow(dis[3].y - dis[2].y, 2)
             + System.Math.Pow(dis[3].z - dis[2].z, 2));
             +                        side[4] = System.Math.Sqrt(System.Math.Pow(dis[0].x - dis[3].x, 2)
             + System.Math.Pow(dis[0].y - dis[3].y, 2)
             + System.Math.Pow(dis[0].z - dis[3].z, 2));
             +                        double p1 = (side[0] + side[1] + side[2]) / 2;
             +                        double p2 = (side[2] + side[3] + side[4]) / 2;
             +                        areaNumber = System.Math.Sqrt(p1 * (p1 - side[0]) * (p1 - side[1]) * (p1 - side[2]))
             + System.Math.Sqrt(p2 * (p2 - side[2]) * (p2 - side[3]) * (p2 - side[4]));
             +                    }
             +                    if (LengthOfLineRenderer == 5)
             +                    {
             +                        areaLine.loop = true;
             +                        side[0] = System.Math.Sqrt(System.Math.Pow(dis[1].x - dis[0].x, 2)
             + System.Math.Pow(dis[1].y - dis[0].y, 2)
             + System.Math.Pow(dis[1].z - dis[0].z, 2));
             +                        side[1] = System.Math.Sqrt(System.Math.Pow(dis[2].x - dis[1].x, 2)
             + System.Math.Pow(dis[2].y - dis[1].y, 2)
             + System.Math.Pow(dis[2].z - dis[1].z, 2));
             +                        side[2] = System.Math.Sqrt(System.Math.Pow(dis[0].x - dis[2].x, 2)
             + System.Math.Pow(dis[0].y - dis[2].y, 2)
             + System.Math.Pow(dis[0].z - dis[2].z, 2));
             +                        side[3] = System.Math.Sqrt(System.Math.Pow(dis[3].x - dis[2].x, 2)
             + System.Math.Pow(dis[3].y - dis[2].y, 2)
             + System.Math.Pow(dis[3].z - dis[2].z, 2));
             +                        side[4] = System.Math.Sqrt(System.Math.Pow(dis[0].x - dis[3].x, 2)
             + System.Math.Pow(dis[0].y - dis[3].y, 2)
             + System.Math.Pow(dis[0].z - dis[3].z, 2));
             +                        side[5] = System.Math.Sqrt(System.Math.Pow(dis[4].x - dis[3].x, 2)
             + System.Math.Pow(dis[4].y - dis[3].y, 2)
             + System.Math.Pow(dis[4].z - dis[3].z, 2));
             +                        side[6] = System.Math.Sqrt(System.Math.Pow(dis[0].x - dis[4].x, 2)
             + System.Math.Pow(dis[0].y - dis[4].y, 2)
             + System.Math.Pow(dis[0].z - dis[4].z, 2));
             +
             +                        double p1 = (side[0] + side[1] + side[2]) / 2;
             +                        double p2 = (side[2] + side[3] + side[4]) / 2;
             +                        double p3 = (side[4] + side[5] + side[6]) / 2;
             +                        areaNumber = System.Math.Sqrt(p1 * (p1 - side[0]) * (p1 - side[1]) * (p1 - side[2]))
             + System.Math.Sqrt(p2 * (p2 - side[2]) * (p2 - side[3]) * (p2 - side[4]))
             + System.Math.Sqrt(p3 * (p3 - side[4]) * (p3 - side[5]) * (p3 - side[6]));
             +                    }
             +
             +                }
             +            }
             +        if (Input.GetKeyDown(KeyCode.R))
             +        {
             +            LengthOfLineRenderer = 0;
             +            areaNumber = 0;
             +                volume = 0;
             +                surface = 0;
             +            }
             +
             +        areaN1.text = "area:" + areaNumber * m;
             +        }
             +
             +    }
             +
             +    if (Input.GetMouseButtonDown(0))
             +    {
             +
             +        if (Physics.Raycast(pointerRaycast, out pointerCollidedWith) && pointerCollidedWith.transform.tag == "model")
             +        {
             +            if (pointerCollidedWith.transform.tag == "model")
             +            {
             +                volumeText.text = "Volume= " + Mathf.Abs(volume);
             +                surfaceText.text = "Surface area = " + surface;
             +                //Debug.Log("Volume= " + Mathf.Abs(volume));
             +                // Debug.Log("Area = " + surface);
             +            }
             +        }
             +        if (Input.GetKeyDown(KeyCode.R))
             +        {
             +            LengthOfLineRenderer = 0;
             +            areaNumber = 0;
             +            volume = 0;
             +            surface = 0;
             +        }
             +
             +    }
             +
             +    // GameObject.Find("model/default").SendMessage("MeshCalculator", "sum");
             */
            return(OverrideBeamLength(actualLength));
        }
Exemplo n.º 23
0
        protected virtual float CastRayForward()
        {
            Transform  origin         = GetOrigin();
            Ray        pointerRaycast = new Ray(origin.position, origin.forward);
            RaycastHit pointerCollidedWith;

#pragma warning disable 0618
            bool rayHit = VRTK_CustomRaycast.Raycast(customRaycast, pointerRaycast, out pointerCollidedWith, layersToIgnore, maximumLength);
#pragma warning restore 0618

            CheckRayMiss(rayHit, pointerCollidedWith);
            CheckRayHit(rayHit, pointerCollidedWith);

            float actualLength = maximumLength;
            if (rayHit && pointerCollidedWith.distance < maximumLength)
            {
                actualLength = pointerCollidedWith.distance;
            }

            /*
             * areaLine = GetComponent<LineRenderer>();
             * areaLine.SetColors(Color.yellow, Color.yellow);
             * areaLine.SetWidth(0.01f, 0.01f);
             * Button disButton = distenceButton.GetComponent<Button>();
             * disButton.onClick.AddListener(distenceButtonClicked);
             * Button areaButtonFinish = areaButton.GetComponent<Button>();
             * areaButtonFinish.onClick.AddListener(areaButtonClicked);
             *
             * if (distenceButtonClick == true)
             * {
             *
             *  if (Input.GetMouseButtonDown(0))
             *  {
             *
             *      if (Physics.Raycast(pointerRaycast, out pointerCollidedWith))
             *      {
             *          position = pointerCollidedWith.point;
             *          LengthOfLineRenderer++;
             *          //       if (LengthOfLineRenderer <= 6)
             *          //      {
             *          areaLine.SetVertexCount(LengthOfLineRenderer);
             *          areaLine.SetPosition(LengthOfLineRenderer - 1, position);
             *          // areaLine.positionCount = dis.Length;
             *          dis[LengthOfLineRenderer - 1] = position;
             *          // dis[LengthOfLineRenderer - 1] = position;
             *          if (LengthOfLineRenderer >= 2)
             *              distance = distance + Vector3.Distance(dis[LengthOfLineRenderer - 2], dis[LengthOfLineRenderer - 1]);
             *          else
             *              distance = 0;
             *          //      }
             *      }
             *      if (Input.GetKeyDown(KeyCode.R))
             *      {
             *          LengthOfLineRenderer = 0;
             *          distance = 0;
             *      }
             *      distenceN1.text = "distence:" + distance * m;
             *  }
             *
             * }
             * if (areaButtonClick == true)
             * {
             *
             *  if (Input.GetMouseButtonDown(0))
             *  {
             *
             *      if (Physics.Raycast(pointerRaycast, out pointerCollidedWith))
             *      {
             *          position = pointerCollidedWith.point;
             *          LengthOfLineRenderer++;
             *          if (LengthOfLineRenderer <= 6)
             *          {
             *              areaLine.SetVertexCount(LengthOfLineRenderer);
             *              areaLine.SetPosition(LengthOfLineRenderer - 1, position);
             *
             *              dis[LengthOfLineRenderer - 1] = position;
             *              if (LengthOfLineRenderer == 3)
             *              {
             *                  areaLine.loop = true;
             *                  //Debug.Log(dis[0]);
             *                  // side[LengthOfLineRenderer - 1] = System.Math.Sqrt(System.Math.Pow(dis[LengthOfLineRenderer].x - dis[LengthOfLineRenderer - 1].x, 2)
             *                  //     + System.Math.Pow(dis[LengthOfLineRenderer].y - dis[LengthOfLineRenderer - 1].y, 2)
             *                  //     + System.Math.Pow(dis[LengthOfLineRenderer].z - dis[LengthOfLineRenderer - 1].z, 2));
             *                  side[0] = System.Math.Sqrt(System.Math.Pow(dis[1].x - dis[0].x, 2)
             + System.Math.Pow(dis[1].y - dis[0].y, 2)
             + System.Math.Pow(dis[1].z - dis[0].z, 2));
             +                  side[1] = System.Math.Sqrt(System.Math.Pow(dis[2].x - dis[1].x, 2)
             + System.Math.Pow(dis[2].y - dis[1].y, 2)
             + System.Math.Pow(dis[2].z - dis[1].z, 2));
             +                  side[2] = System.Math.Sqrt(System.Math.Pow(dis[0].x - dis[2].x, 2)
             + System.Math.Pow(dis[0].y - dis[2].y, 2)
             + System.Math.Pow(dis[0].z - dis[2].z, 2));
             +
             +                  if (side[0] + side[1] <= side[2] || side[0] + side[2] <= side[1] || side[1] + side[2] <= side[0])
             +                  {
             +                      areaNumber = 0;
             +                  }
             +                  else
             +                  {
             +                      double p = (side[0] + side[1] + side[2]) / 2;
             +                      //Debug.Log(p);
             +                      areaNumber = System.Math.Sqrt(p * (p - side[0]) * (p - side[1]) * (p - side[2]));
             +                  }
             +                  //Debug.Log(dis[LengthOfLineRenderer].x);
             +                  //Debug.Log(side[0]);
             +                  // Debug.Log(areaNumber);
             +              }
             +              if (LengthOfLineRenderer == 4)
             +              {
             +                  areaLine.loop = true;
             +                  side[0] = System.Math.Sqrt(System.Math.Pow(dis[1].x - dis[0].x, 2)
             + System.Math.Pow(dis[1].y - dis[0].y, 2)
             + System.Math.Pow(dis[1].z - dis[0].z, 2));
             +                  side[1] = System.Math.Sqrt(System.Math.Pow(dis[2].x - dis[1].x, 2)
             + System.Math.Pow(dis[2].y - dis[1].y, 2)
             + System.Math.Pow(dis[2].z - dis[1].z, 2));
             +                  side[2] = System.Math.Sqrt(System.Math.Pow(dis[0].x - dis[2].x, 2)
             + System.Math.Pow(dis[0].y - dis[2].y, 2)
             + System.Math.Pow(dis[0].z - dis[2].z, 2));
             +                  side[3] = System.Math.Sqrt(System.Math.Pow(dis[3].x - dis[2].x, 2)
             + System.Math.Pow(dis[3].y - dis[2].y, 2)
             + System.Math.Pow(dis[3].z - dis[2].z, 2));
             +                  side[4] = System.Math.Sqrt(System.Math.Pow(dis[0].x - dis[3].x, 2)
             + System.Math.Pow(dis[0].y - dis[3].y, 2)
             + System.Math.Pow(dis[0].z - dis[3].z, 2));
             +                  double p1 = (side[0] + side[1] + side[2]) / 2;
             +                  double p2 = (side[2] + side[3] + side[4]) / 2;
             +                  areaNumber = System.Math.Sqrt(p1 * (p1 - side[0]) * (p1 - side[1]) * (p1 - side[2]))
             + System.Math.Sqrt(p2 * (p2 - side[2]) * (p2 - side[3]) * (p2 - side[4]));
             +              }
             +              if (LengthOfLineRenderer == 5)
             +              {
             +                  areaLine.loop = true;
             +                  side[0] = System.Math.Sqrt(System.Math.Pow(dis[1].x - dis[0].x, 2)
             + System.Math.Pow(dis[1].y - dis[0].y, 2)
             + System.Math.Pow(dis[1].z - dis[0].z, 2));
             +                  side[1] = System.Math.Sqrt(System.Math.Pow(dis[2].x - dis[1].x, 2)
             + System.Math.Pow(dis[2].y - dis[1].y, 2)
             + System.Math.Pow(dis[2].z - dis[1].z, 2));
             +                  side[2] = System.Math.Sqrt(System.Math.Pow(dis[0].x - dis[2].x, 2)
             + System.Math.Pow(dis[0].y - dis[2].y, 2)
             + System.Math.Pow(dis[0].z - dis[2].z, 2));
             +                  side[3] = System.Math.Sqrt(System.Math.Pow(dis[3].x - dis[2].x, 2)
             + System.Math.Pow(dis[3].y - dis[2].y, 2)
             + System.Math.Pow(dis[3].z - dis[2].z, 2));
             +                  side[4] = System.Math.Sqrt(System.Math.Pow(dis[0].x - dis[3].x, 2)
             + System.Math.Pow(dis[0].y - dis[3].y, 2)
             + System.Math.Pow(dis[0].z - dis[3].z, 2));
             +                  side[5] = System.Math.Sqrt(System.Math.Pow(dis[4].x - dis[3].x, 2)
             + System.Math.Pow(dis[4].y - dis[3].y, 2)
             + System.Math.Pow(dis[4].z - dis[3].z, 2));
             +                  side[6] = System.Math.Sqrt(System.Math.Pow(dis[0].x - dis[4].x, 2)
             + System.Math.Pow(dis[0].y - dis[4].y, 2)
             + System.Math.Pow(dis[0].z - dis[4].z, 2));
             +
             +                  double p1 = (side[0] + side[1] + side[2]) / 2;
             +                  double p2 = (side[2] + side[3] + side[4]) / 2;
             +                  double p3 = (side[4] + side[5] + side[6]) / 2;
             +                  areaNumber = System.Math.Sqrt(p1 * (p1 - side[0]) * (p1 - side[1]) * (p1 - side[2]))
             + System.Math.Sqrt(p2 * (p2 - side[2]) * (p2 - side[3]) * (p2 - side[4]))
             + System.Math.Sqrt(p3 * (p3 - side[4]) * (p3 - side[5]) * (p3 - side[6]));
             +              }
             +          }
             +      }
             +  }
             + }
             */

            return(OverrideBeamLength(actualLength));
        }