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

Last change on this file since 2804 was 2798, checked in by ldelgass, 12 years ago

Add emacs mode magic line in preparation for indentation cleanup

  • 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-2006  Purdue Research Foundation
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#include "Plane.h"
18
19Plane::Plane(float _a, float _b, float _c, float _d) {
20    this->a = _a;
21    this->b = _b;
22    this->c = _c;
23    this->d = _d;
24
25    assert(a != 0 || b != 0 || c != 0);
26}
27
28Plane::Plane(float coeffs[4]) {
29    a = coeffs[0];
30    b = coeffs[1];
31    c = coeffs[2];
32    d = coeffs[3];
33
34    assert(a != 0 || b != 0 || c != 0);
35}
36
37
38void
39Plane::transform(Mat4x4 mat) {
40    Vector4 coeffs(a, b, c, d);
41
42    Mat4x4 inv = mat.inverse();
43    Vector4 new_coeffs = inv.multiply_row_vector(coeffs);
44    a = new_coeffs.x;
45    b = new_coeffs.y;
46    c = new_coeffs.z;
47    d = new_coeffs.w;
48}
49
50void
51Plane::get_point(Vector3 &point){
52    if (a != 0) {
53        point.x = -d/a;
54        point.y = 0;
55        point.z = 0;
56    } else if (b != 0) {
57        point.y = -d/b;
58        point.x = 0;
59        point.z = 0;
60    } else if (c != 0) {
61        point.z = -d /c;
62        point.y = 0;
63        point.x = 0;
64    } else{
65        assert(false);
66    }
67}
Note: See TracBrowser for help on using the repository browser.