VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
override void AVR.Motion.AVR_MovementRay.UpdateRay ( )
inlineprotectedvirtual

Updates the ray. Called from Monobehaviour.Update()

An brief explanation on the math done here: Say alpha is the angle between RayForward and the y-axis. We want a minium alpha of 30°. Basic trigonometry tells us, that alpha >= 30° is equivalent with RayForward.y <= cos(30°). Consequently, RayForward.y will be clamped to exaclty cos(30°). What remains is setting the xz vector accordingly. Since the whole vector is normalized, the hypotenuse is 1. So pythagoras => 1^2 = |RayForward.xz|^2 + Rayforward.y^2 As a result, the length of RayForward.xz is equal to |RayForward.xz| = sqrt(1-RayForward.y^2) And since RayForward.y = cos(30°): |RayForward.xz| = sqrt(1-cos(30°)^2) = sin(30°) And this is what we do here. If the condition is violated, we set y=0, then multiply the normalized vector with sin(alpha) and finally set y to cos(alpha).

Reimplemented from AVR.Core.AVR_SolidRay.

Definition at line 71 of file AVR_MovementRay.cs.

71  {
72  if(isHidden) return;
73 
74  base.UpdateRay();
75 
76  // Check if object is valid
77  _valid = objectHit && this.filter(hitPosition);
78 
79  // Set reticule
80  if(reticule) {
81  reticule.transform.position = hitPosition.point;
82  reticule.transform.forward = new Vector3(Camera.main.transform.forward.x, 0.0f, Camera.main.transform.forward.z);
83  reticule.SetActive(objectHit && isValid);
84  }
85  else {
86  reticule.SetActive(false);
87  }
88 
89  // Set invalid reticule
90  if(invalid_reticule) {
91  invalid_reticule.transform.position = hitPosition.point;
92  invalid_reticule.transform.forward = new Vector3(Camera.main.transform.forward.x, 0.0f, Camera.main.transform.forward.z);
93  invalid_reticule.SetActive(objectHit && !isValid);
94  }
95  else {
96  invalid_reticule.SetActive(false);
97  }
98 
99  // Set gradient
100  if(isValid) {
101  lr.colorGradient = m_ValidColorGradient;
102  }
103  else {
104  lr.colorGradient = m_InvalidColorGradient;
105  }
106  }
GameObject reticule
Reticule object displayed when a valid surface is hit
GameObject invalid_reticule
Reticule object displayed when an invalid surface is hit
RaycastHit hitPosition
Raycasthit where the ray hit something. Contains the last hit the ray did if AVR_SolidRay.objectHit is false. null if the ray hasn't hit a single object in its lifetime. /summary>
Definition: AVR_SolidRay.cs:25
bool objectHit
True if the ray hit some object this frame. Use AVR_SolidRay.hitPosition to get the respective Raycas...
Definition: AVR_SolidRay.cs:32
bool isHidden
Is this ray hidden
Definition: AVR_Ray.cs:61
bool isValid
Is this ray valid. The validity of a Raycasthit is determined on whether if AVR_MovementRay.filter satisfies the current hit.