1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | /* |
---|
3 | * ---------------------------------------------------------------------- |
---|
4 | * Plane.h: 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 | #ifndef _PLANE_H_ |
---|
17 | #define _PLANE_H_ |
---|
18 | |
---|
19 | #include "Vector3.h" |
---|
20 | #include "Mat4x4.h" |
---|
21 | |
---|
22 | class Plane |
---|
23 | { |
---|
24 | float a, b, c, d; |
---|
25 | public: |
---|
26 | |
---|
27 | Plane(float a, float b, float c, float d); |
---|
28 | |
---|
29 | Plane(float coeffs[4]); |
---|
30 | |
---|
31 | Plane() |
---|
32 | {} |
---|
33 | |
---|
34 | void get_point(Vector3& point); |
---|
35 | |
---|
36 | //bool clips(float point[3]) const { return !retains(point); } |
---|
37 | |
---|
38 | void transform(const Mat4x4& mat); |
---|
39 | |
---|
40 | void transform(float *m) |
---|
41 | { |
---|
42 | Mat4x4 mat(m); |
---|
43 | transform(mat); |
---|
44 | } |
---|
45 | |
---|
46 | bool retains(const Vector3& point) const |
---|
47 | { |
---|
48 | return ((a*point.x + b*point.y + c*point.z + d) >= 0); |
---|
49 | } |
---|
50 | |
---|
51 | Vector4 get_coeffs() const |
---|
52 | { |
---|
53 | return Vector4(a, b, c, d); |
---|
54 | } |
---|
55 | |
---|
56 | void set_coeffs(float a_val, float b_val, float c_val, float d_val) |
---|
57 | { |
---|
58 | a = a_val, b = b_val, c = c_val, d = d_val; |
---|
59 | } |
---|
60 | |
---|
61 | void get_normal(Vector3& normal) const |
---|
62 | { |
---|
63 | normal.x = a; |
---|
64 | normal.y = b; |
---|
65 | normal.z = c; |
---|
66 | } |
---|
67 | }; |
---|
68 | |
---|
69 | |
---|
70 | #endif |
---|