Line | |
---|
1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | #include <vrmath/vrPlane2.h> |
---|
3 | |
---|
4 | void vrPlane2::makePts(const vrVector3f& p1, const vrVector3f& p2, const vrVector3f& p3) |
---|
5 | { |
---|
6 | normal.cross(p2 - p1, p3 - p1); |
---|
7 | normal.normalize(); |
---|
8 | |
---|
9 | point = p1; |
---|
10 | } |
---|
11 | |
---|
12 | void vrPlane2::makeNormalPt(const vrVector3f& norm, const vrVector3f& pos) |
---|
13 | { |
---|
14 | normal = norm; |
---|
15 | point = pos; |
---|
16 | } |
---|
17 | |
---|
18 | bool vrPlane2::intersect(const vrLineSegment &seg, float &d) const |
---|
19 | { |
---|
20 | // STEVE |
---|
21 | // 2005-09-07 |
---|
22 | |
---|
23 | float tu, td; |
---|
24 | |
---|
25 | tu = normal.x * (point.x - seg.pos.x) + normal.y * (point.y - seg.pos.y) |
---|
26 | + normal.z * (point.z - seg.pos.z); |
---|
27 | |
---|
28 | td = normal.x * seg.dir.x + normal.y * seg.dir.y + normal.z * seg.dir.z; |
---|
29 | |
---|
30 | if ( td == 0.0f ) return false; |
---|
31 | |
---|
32 | d = tu / td; |
---|
33 | |
---|
34 | return true; |
---|
35 | } |
---|
36 | |
---|
37 | float vrPlane2::distance(const vrVector3f& pos) const |
---|
38 | { |
---|
39 | vrVector3f plane_point = crossPoint( pos ); |
---|
40 | |
---|
41 | return pos.distance( plane_point ); |
---|
42 | } |
---|
43 | |
---|
44 | vrVector3f vrPlane2::crossPoint(const vrVector3f& pos) const |
---|
45 | { |
---|
46 | vrLineSegment seg; |
---|
47 | |
---|
48 | seg.pos = pos; |
---|
49 | seg.dir = normal; |
---|
50 | |
---|
51 | float t = 0; |
---|
52 | intersect(seg, t); |
---|
53 | |
---|
54 | return seg.getPoint(t); |
---|
55 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.