aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ode-0.9/OPCODE/Ice/IceRay.cpp
diff options
context:
space:
mode:
authordan miller2007-10-19 05:20:48 +0000
committerdan miller2007-10-19 05:20:48 +0000
commitd48ea5bb797037069d641da41da0f195f0124491 (patch)
tree40ff433d94859d629aac933d5ec73b382f62ba1a /libraries/ode-0.9/OPCODE/Ice/IceRay.cpp
parentdont ask (diff)
downloadopensim-SC-d48ea5bb797037069d641da41da0f195f0124491.zip
opensim-SC-d48ea5bb797037069d641da41da0f195f0124491.tar.gz
opensim-SC-d48ea5bb797037069d641da41da0f195f0124491.tar.bz2
opensim-SC-d48ea5bb797037069d641da41da0f195f0124491.tar.xz
one more for the gipper
Diffstat (limited to 'libraries/ode-0.9/OPCODE/Ice/IceRay.cpp')
-rw-r--r--libraries/ode-0.9/OPCODE/Ice/IceRay.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/libraries/ode-0.9/OPCODE/Ice/IceRay.cpp b/libraries/ode-0.9/OPCODE/Ice/IceRay.cpp
new file mode 100644
index 0000000..6cf0330
--- /dev/null
+++ b/libraries/ode-0.9/OPCODE/Ice/IceRay.cpp
@@ -0,0 +1,84 @@
1///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2/**
3 * Contains code for rays.
4 * \file IceRay.cpp
5 * \author Pierre Terdiman
6 * \date April, 4, 2000
7 */
8///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
9
10///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11/**
12 * Ray class.
13 * A ray is a half-line P(t) = mOrig + mDir * t, with 0 <= t <= +infinity
14 * \class Ray
15 * \author Pierre Terdiman
16 * \version 1.0
17 */
18///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
19
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
60///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
61// Precompiled Header
62#include "Stdafx.h"
63
64using namespace IceMaths;
65
66float Ray::SquareDistance(const Point& point, float* t) const
67{
68 Point Diff = point - mOrig;
69 float fT = Diff | mDir;
70
71 if(fT<=0.0f)
72 {
73 fT = 0.0f;
74 }
75 else
76 {
77 fT /= mDir.SquareMagnitude();
78 Diff -= fT*mDir;
79 }
80
81 if(t) *t = fT;
82
83 return Diff.SquareMagnitude();
84}