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