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