Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IceRay.cpp
Go to the documentation of this file.
1 
8 
11 
18 
20 /*
21  O = Origin = impact point
22  i = normalized vector along the x axis
23  j = normalized vector along the y axis = actually the normal vector in O
24  D = Direction vector, norm |D| = 1
25  N = Projection of D on y axis, norm |N| = normal reaction
26  T = Projection of D on x axis, norm |T| = tangential reaction
27  R = Reflexion vector
28 
29  ^y
30  |
31  |
32  |
33  _ _ _| _ _ _
34  * * *|
35  \ | /
36  \ |N / |
37  R\ | /D
38  \ | / |
39  \ | /
40  _________\|/______*_______>x
41  O T
42 
43  Let define theta = angle between D and N. Then cos(theta) = |N| / |D| = |N| since D is normalized.
44 
45  j|D = |j|*|D|*cos(theta) => |N| = j|D
46 
47  Then we simply have:
48 
49  D = N + T
50 
51  To compute tangential reaction :
52 
53  T = D - N
54 
55  To compute reflexion vector :
56 
57  R = N - T = N - (D-N) = 2*N - D
58 */
59 
61 // Precompiled Header
62 #include "Stdafx.h"
63 
64 
65 using namespace Opcode;
66 
67 float Ray::SquareDistance(const Point& point, float* t) const
68 {
69  Point Diff = point - mOrig;
70  float fT = Diff | mDir;
71 
72  if(fT<=0.0f)
73  {
74  fT = 0.0f;
75  }
76  else
77  {
78  fT /= mDir.SquareMagnitude();
79  Diff -= fT*mDir;
80  }
81 
82  if(t) *t = fT;
83 
84  return Diff.SquareMagnitude();
85 }
86