Rev | Line | |
---|
[1699] | 1 | #include <vrmath/vrPlane2.h>
|
---|
| 2 |
|
---|
| 3 | void vrPlane2::makePts(const vrVector3f& p1, const vrVector3f& p2, const vrVector3f& p3) {
|
---|
| 4 |
|
---|
| 5 | normal.cross(p2 - p1, p3 - p1);
|
---|
| 6 | normal.normalize();
|
---|
| 7 |
|
---|
| 8 | point = p1;
|
---|
| 9 |
|
---|
| 10 | }
|
---|
| 11 |
|
---|
| 12 | void vrPlane2::makeNormalPt(const vrVector3f& norm, const vrVector3f& pos) {
|
---|
| 13 | normal = norm;
|
---|
| 14 | point = pos;
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | bool vrPlane2::intersect(const vrLineSegment &seg, float &d) const
|
---|
| 18 | {
|
---|
| 19 | // STEVE
|
---|
| 20 | // 2005-09-07
|
---|
| 21 |
|
---|
| 22 | float tu, td;
|
---|
| 23 |
|
---|
| 24 | tu = normal.x * (point.x - seg.pos.x) + normal.y * (point.y - seg.pos.y)
|
---|
| 25 | + normal.z * (point.z - seg.pos.z);
|
---|
| 26 |
|
---|
| 27 | td = normal.x * seg.dir.x + normal.y * seg.dir.y + normal.z * seg.dir.z;
|
---|
| 28 |
|
---|
| 29 | if ( td == 0.0f ) return false;
|
---|
| 30 |
|
---|
| 31 | d = tu / td;
|
---|
| 32 |
|
---|
| 33 | return true;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | float vrPlane2::distance(const vrVector3f& pos) const
|
---|
| 37 | {
|
---|
| 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.