source: trunk/packages/vizservers/nanovis/Plane.cpp @ 3464

Last change on this file since 3464 was 3177, checked in by mmc, 7 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

  • Property svn:eol-style set to native
File size: 1.5 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * ----------------------------------------------------------------------
4 * Plane.cpp: plane class
5 *
6 * ======================================================================
7 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
8 *           Purdue Rendering and Perceptualization Lab (PURPL)
9 *
10 *  Copyright (c) 2004-2012  HUBzero Foundation, LLC
11 *
12 *  See the file "license.terms" for information on usage and
13 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 * ======================================================================
15 */
16#include <assert.h>
17
18#include "Plane.h"
19
20Plane::Plane(float _a, float _b, float _c, float _d) :
21    a(_a),
22    b(_b),
23    c(_c),
24    d(_d)
25{
26    assert(a != 0 || b != 0 || c != 0);
27}
28
29Plane::Plane(float coeffs[4])
30{
31    a = coeffs[0];
32    b = coeffs[1];
33    c = coeffs[2];
34    d = coeffs[3];
35
36    assert(a != 0 || b != 0 || c != 0);
37}
38
39void
40Plane::transform(const Mat4x4& mat)
41{
42    Vector4 coeffs(a, b, c, d);
43
44    Mat4x4 inv = mat.inverse();
45    Vector4 new_coeffs = inv.multiplyRowVector(coeffs);
46    a = new_coeffs.x;
47    b = new_coeffs.y;
48    c = new_coeffs.z;
49    d = new_coeffs.w;
50}
51
52void
53Plane::getPoint(Vector3& point)
54{
55    if (a != 0) {
56        point.x = -d/a;
57        point.y = 0;
58        point.z = 0;
59    } else if (b != 0) {
60        point.y = -d/b;
61        point.x = 0;
62        point.z = 0;
63    } else if (c != 0) {
64        point.z = -d /c;
65        point.y = 0;
66        point.x = 0;
67    } else {
68        assert(false);
69    }
70}
Note: See TracBrowser for help on using the repository browser.