source: nanovis/branches/1.1/vrmath/BPlane.cpp @ 4923

Last change on this file since 4923 was 3492, checked in by ldelgass, 11 years ago

Fix camera reset for nanovis. Includes refactoring of vector/matrix classes
in nanovis to consolidate into vrmath library. Also add preliminary canonical
view control to clients for testing.

  • Property svn:eol-style set to native
File size: 1.3 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright (c) 2004-2013  HUBzero Foundation, LLC
4 *
5 * Author: Insoo Woo <iwoo@purdue.edu>
6 */
7
8#include <vrmath/BPlane.h>
9#include <vrmath/Vector3f.h>
10#include <vrmath/LineSegment.h>
11
12using namespace vrmath;
13
14void BPlane::makePts(const Vector3f& p1, const Vector3f& p2, const Vector3f& p3)
15{
16    normal = cross(p2 - p1, p3 - p1);
17    normal = normal.normalize();
18
19    point = p1;
20}
21
22void BPlane::makeNormalPt(const Vector3f& norm, const Vector3f& pos)
23{
24    normal = norm;
25    point = pos;
26}
27
28bool BPlane::intersect(const LineSegment &seg, float &d) const
29{
30    float tu, td;
31
32    tu = normal.x * (point.x - seg.pos.x) +
33         normal.y * (point.y - seg.pos.y) +
34         normal.z * (point.z - seg.pos.z);
35
36    td = normal.x * seg.dir.x +
37         normal.y * seg.dir.y +
38         normal.z * seg.dir.z;
39
40    if ( td == 0.0f ) return false;
41
42    d = tu / td;
43
44    return true;
45}
46
47double BPlane::distance(const Vector3f& pos) const
48{
49    Vector3f plane_point = crossPoint(pos);
50
51    return pos.distance(plane_point);
52}
53
54Vector3f BPlane::crossPoint(const Vector3f& pos) const
55{
56    LineSegment seg;
57
58    seg.pos.set(pos.x, pos.y, pos.z, 1);
59    seg.dir = normal;
60
61    float t = 0;
62    intersect(seg, t);
63
64    return seg.getPoint(t);
65}
Note: See TracBrowser for help on using the repository browser.