[226] | 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(){}
|
---|
| 19 |
|
---|
| 20 | Plane::Plane(float _a, float _b, float _c, float _d) {
|
---|
| 21 | this->a = _a;
|
---|
| 22 | this->b = _b;
|
---|
| 23 | this->c = _c;
|
---|
| 24 | this->d = _d;
|
---|
| 25 |
|
---|
| 26 | assert(a != 0 || b != 0 || c != 0);
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | Plane::Plane(float coeffs[4]) {
|
---|
| 30 | a = coeffs[0];
|
---|
| 31 | b = coeffs[1];
|
---|
| 32 | c = coeffs[2];
|
---|
| 33 | d = coeffs[3];
|
---|
| 34 |
|
---|
| 35 | assert(a != 0 || b != 0 || c != 0);
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | void Plane::get_normal(Vector3 &normal){
|
---|
| 39 | normal.x = a;
|
---|
| 40 | normal.y = b;
|
---|
| 41 | normal.z = c;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | void Plane::get_point(Vector3 &point){
|
---|
| 45 | if(a != 0){
|
---|
| 46 | point.x = -d/a;
|
---|
| 47 | point.y = 0;
|
---|
| 48 | point.z = 0;
|
---|
| 49 | }
|
---|
| 50 | else if(b != 0){
|
---|
| 51 | point.y = -d/b;
|
---|
| 52 | point.x = 0;
|
---|
| 53 | point.z = 0;
|
---|
| 54 | }
|
---|
| 55 | else if(c != 0){
|
---|
| 56 | point.z = -d /c;
|
---|
| 57 | point.y = 0;
|
---|
| 58 | point.x = 0;
|
---|
| 59 | }
|
---|
| 60 | else{
|
---|
| 61 | assert(false);
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | Vector4 Plane::get_coeffs(){
|
---|
| 66 | Vector4 ret(a, b, c, d);
|
---|
| 67 | return ret;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | void Plane::set_coeffs(float _a, float _b, float _c, float _d){
|
---|
| 71 | a = _a;
|
---|
| 72 | b = _b;
|
---|
| 73 | c = _c;
|
---|
| 74 | d = _d;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | void Plane::transform(Mat4x4 mat) {
|
---|
| 78 | Vector4 coeffs(a, b, c, d);
|
---|
| 79 | Mat4x4 inv = mat.inverse();
|
---|
| 80 | Vector4 new_coeffs = inv.multiply_row_vector(coeffs);
|
---|
| 81 |
|
---|
| 82 | a = new_coeffs.x;
|
---|
| 83 | b = new_coeffs.y;
|
---|
| 84 | c = new_coeffs.z;
|
---|
| 85 | d = new_coeffs.w;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | void Plane::transform(float *m){
|
---|
| 89 | Mat4x4 mat(m);
|
---|
| 90 | transform(mat);
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | bool Plane::retains(Vector3 point){
|
---|
| 94 | return (a * point.x + b * point.y + c * point.z + d >= 0);
|
---|
| 95 | }
|
---|