Line | |
---|
1 | #ifndef __RECTANGLE3_H
|
---|
2 | #define __RECTANGLE3_H
|
---|
3 | #include <iostream>
|
---|
4 | using namespace std;
|
---|
5 | #include "Vector3.h"
|
---|
6 |
|
---|
7 | namespace GtpVisibilityPreprocessor {
|
---|
8 |
|
---|
9 | /// rectangle vertices
|
---|
10 | // 3 2
|
---|
11 | // 0 1
|
---|
12 | class Rectangle3 {
|
---|
13 | public:
|
---|
14 | Vector3 mVertices[4];
|
---|
15 |
|
---|
16 | Vector3 GetVertex(const int i) const { return mVertices[i]; }
|
---|
17 | Rectangle3() {}
|
---|
18 |
|
---|
19 | Rectangle3(const Vector3 &v0,
|
---|
20 | const Vector3 &v1,
|
---|
21 | const Vector3 &v2,
|
---|
22 | const Vector3 &v3) {
|
---|
23 | mVertices[0] = v0;
|
---|
24 | mVertices[1] = v1;
|
---|
25 | mVertices[2] = v2;
|
---|
26 | mVertices[3] = v3;
|
---|
27 | }
|
---|
28 |
|
---|
29 | Vector3 GetNormal() const {
|
---|
30 | return Normalize(CrossProd(mVertices[0]-mVertices[1],
|
---|
31 | mVertices[2]-mVertices[1]
|
---|
32 | ));
|
---|
33 | }
|
---|
34 |
|
---|
35 | Vector3 GetCenter() const {
|
---|
36 | return (mVertices[0] + mVertices[1] + mVertices[2] + mVertices[3])/4.0f;
|
---|
37 | }
|
---|
38 |
|
---|
39 | int DominantAxis() const {
|
---|
40 | if (SqrMagnitude(mVertices[0] - mVertices[1]) > SqrMagnitude(mVertices[0] - mVertices[3]))
|
---|
41 | return 0;
|
---|
42 | else
|
---|
43 | return 1;
|
---|
44 | }
|
---|
45 |
|
---|
46 | float GetArea() const {
|
---|
47 | Vector3 v = CrossProd(mVertices[3], mVertices[0]);
|
---|
48 |
|
---|
49 | for (int i=0; i < 3; i++)
|
---|
50 | v += CrossProd(mVertices[i], mVertices[i+1]);
|
---|
51 |
|
---|
52 | return 0.5f*abs(DotProd(GetNormal(), v));
|
---|
53 | }
|
---|
54 |
|
---|
55 | void
|
---|
56 | Split(const int axis,
|
---|
57 | Rectangle3 &r1,
|
---|
58 | Rectangle3 &r2
|
---|
59 | ) const;
|
---|
60 |
|
---|
61 | friend ostream& operator<< (ostream &s, const Rectangle3 &r) {
|
---|
62 | return s<<"Rectangle3:"<<r.mVertices[0]<<r.mVertices[1]<<r.mVertices[2]<<r.mVertices[3];
|
---|
63 | }
|
---|
64 |
|
---|
65 | };
|
---|
66 |
|
---|
67 | }
|
---|
68 |
|
---|
69 | #endif
|
---|
Note: See
TracBrowser
for help on using the repository browser.