VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
virtual void AVR.Core.AVR_Ray.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 in AVR.Motion.AVR_MovementRay, and AVR.Core.AVR_SolidRay.

Definition at line 85 of file AVR_Ray.cs.

85  {
86  if(isHidden) return;
87 
88  // This paragraph deals with the min_y_angle parameter.
89  /// An brief explanation on the math done here:
90  /// Say alpha is the angle between RayForward and the y-axis. We want a minium alpha of 30°.
91  /// Basic trigonometry tells us, that alpha >= 30° is equivalent with RayForward.y <= cos(30°).
92  /// Consequently, RayForward.y will be clamped to exaclty cos(30°). What remains is setting the xz vector accordingly.
93  /// Since the whole vector is normalized, the hypotenuse is 1. So pythagoras => 1^2 = |RayForward.xz|^2 + Rayforward.y^2
94  /// As a result, the length of RayForward.xz is equal to |RayForward.xz| = sqrt(1-RayForward.y^2)
95  /// And since RayForward.y = cos(30°): |RayForward.xz| = sqrt(1-cos(30°)^2) = sin(30°)
96  /// And this is what we do here. If the condition is violated, we set y=0, then multiply the normalized vector with sin(alpha)
97  /// and finally set y to cos(alpha).
98  RayForward = transform.forward;
99  float ang = Mathf.Deg2Rad * min_y_angle;
100  if(RayForward.y > Mathf.Cos(ang)) {
101  RayForward.y = 0;
102  RayForward = RayForward.normalized * Mathf.Sin(ang);
103  RayForward.y = Mathf.Cos(ang);
104  }
105 
106  switch (mode)
107  {
108  // Straight beam
109  case RayMode.STRAIGHT: {
111  break;
112  }
113 
114  // Parabolic projectile motion, affected by gravity
115  case RayMode.PROJECTILE_MOTION: {
117  break;
118  }
119  default: {
120  AVR.Core.AVR_DevConsole.warn("RayMode type of AVR_Ray object "+gameObject.name+" has not been implemented.");
121  break;
122  }
123  }
124  }
RayMode mode
What type of ray should be used
Definition: AVR_Ray.cs:23
Vector3 RayForward
Definition: AVR_Ray.cs:53
float min_y_angle
Will restrict the minium angle of the Ray with the y-Axis.
Definition: AVR_Ray.cs:47
virtual void UpdateStraightRay()
Updates a ray with mode==STRAIGHT
Definition: AVR_Ray.cs:127
virtual void UpdateProjectileRay()
Updates a ray with mode==PROJECTILE
Definition: AVR_Ray.cs:148
bool isHidden
Is this ray hidden
Definition: AVR_Ray.cs:61