|
11 | 11 |
|
12 | 12 | #include "xrCore/fixedvector.h" |
13 | 13 |
|
14 | | -#pragma pack(push,4) |
| 14 | +#pragma pack(push, 4) |
15 | 15 |
|
16 | | -enum EFC_Visible { |
17 | | - fcvNone = 0, |
18 | | - fcvPartial, |
19 | | - fcvFully, |
20 | | - fcv_forcedword = u32(-1) |
| 16 | +enum EFC_Visible |
| 17 | +{ |
| 18 | + fcvNone = 0, |
| 19 | + fcvPartial, |
| 20 | + fcvFully, |
| 21 | + fcv_forcedword = u32(-1) |
21 | 22 | }; |
22 | 23 |
|
| 24 | +#define FRUSTUM_MAXPLANES 12 |
| 25 | +#define FRUSTUM_P_LEFT (1 << 0) |
| 26 | +#define FRUSTUM_P_RIGHT (1 << 1) |
| 27 | +#define FRUSTUM_P_TOP (1 << 2) |
| 28 | +#define FRUSTUM_P_BOTTOM (1 << 3) |
| 29 | +#define FRUSTUM_P_NEAR (1 << 4) |
| 30 | +#define FRUSTUM_P_FAR (1 << 5) |
23 | 31 |
|
24 | | -#define FRUSTUM_MAXPLANES 12 |
25 | | -#define FRUSTUM_P_LEFT (1<<0) |
26 | | -#define FRUSTUM_P_RIGHT (1<<1) |
27 | | -#define FRUSTUM_P_TOP (1<<2) |
28 | | -#define FRUSTUM_P_BOTTOM (1<<3) |
29 | | -#define FRUSTUM_P_NEAR (1<<4) |
30 | | -#define FRUSTUM_P_FAR (1<<5) |
31 | | - |
32 | | -#define FRUSTUM_P_LRTB (FRUSTUM_P_LEFT|FRUSTUM_P_RIGHT|FRUSTUM_P_TOP|FRUSTUM_P_BOTTOM) |
33 | | -#define FRUSTUM_P_ALL (FRUSTUM_P_LRTB|FRUSTUM_P_NEAR|FRUSTUM_P_FAR) |
| 32 | +#define FRUSTUM_P_LRTB (FRUSTUM_P_LEFT | FRUSTUM_P_RIGHT | FRUSTUM_P_TOP | FRUSTUM_P_BOTTOM) |
| 33 | +#define FRUSTUM_P_ALL (FRUSTUM_P_LRTB | FRUSTUM_P_NEAR | FRUSTUM_P_FAR) |
34 | 34 |
|
35 | | -#define FRUSTUM_SAFE (FRUSTUM_MAXPLANES*4) |
36 | | -typedef svector<Fvector,FRUSTUM_SAFE> sPoly; |
37 | | -extern u32 frustum_aabb_remap[8][6]; |
| 35 | +#define FRUSTUM_SAFE (FRUSTUM_MAXPLANES * 4) |
| 36 | +typedef svector<Fvector, FRUSTUM_SAFE> sPoly; |
| 37 | +extern u32 frustum_aabb_remap[8][6]; |
38 | 38 |
|
39 | | -class XRCDB_API CFrustum |
| 39 | +class XRCDB_API CFrustum |
40 | 40 | { |
41 | 41 | public: |
42 | | - struct fplane : public Fplane |
43 | | - { |
44 | | - u32 aabb_overlap_id; // [0..7] |
45 | | - void cache (); |
46 | | - }; |
47 | | - fplane planes [FRUSTUM_MAXPLANES]; |
48 | | - int p_count; |
49 | | - |
50 | | -public: |
51 | | - ICF EFC_Visible AABB_OverlapPlane (const fplane& P, const float* mM) const |
52 | | - { |
53 | | - // calc extreme pts (neg,pos) along normal axis (pos in dir of norm, etc.) |
54 | | - u32* id = frustum_aabb_remap[P.aabb_overlap_id]; |
55 | | - |
56 | | - Fvector Neg; |
57 | | - Neg.set (mM[id[3]],mM[id[4]],mM[id[5]]); |
58 | | - if (P.classify(Neg) > 0) return fcvNone; |
59 | | - |
60 | | - Fvector Pos; |
61 | | - Pos.set (mM[id[0]],mM[id[1]],mM[id[2]]); |
62 | | - if (P.classify(Pos) <= 0) return fcvFully; |
| 42 | + struct fplane : public Fplane |
| 43 | + { |
| 44 | + u32 aabb_overlap_id; // [0..7] |
| 45 | + void cache(); |
| 46 | + }; |
| 47 | + fplane planes[FRUSTUM_MAXPLANES]; |
| 48 | + int p_count; |
63 | 49 |
|
64 | | - return fcvPartial; |
65 | | - } |
66 | 50 | public: |
67 | | - IC void _clear () { p_count=0; } |
68 | | - void _add (Fplane &P); |
69 | | - void _add (Fvector& P1, Fvector& P2, Fvector& P3); |
70 | | - |
71 | | - void SimplifyPoly_AABB (sPoly* P, Fplane& plane); |
72 | | - |
73 | | - void CreateOccluder (Fvector* p, int count, Fvector& vBase, CFrustum& clip); |
74 | | - BOOL CreateFromClipPoly (Fvector* p, int count, Fvector& vBase, CFrustum& clip); // returns 'false' if creation failed |
75 | | - void CreateFromPoints (Fvector* p, int count, Fvector& vBase ); |
76 | | - void CreateFromMatrix (Fmatrix &M, u32 mask); |
77 | | - void CreateFromPortal (sPoly* P, Fvector& vPN, Fvector& vBase, Fmatrix& mFullXFORM); |
78 | | - void CreateFromPlanes (Fplane* p, int count); |
| 51 | + ICF EFC_Visible AABB_OverlapPlane(const fplane& P, const float* mM) const |
| 52 | + { |
| 53 | + // calc extreme pts (neg,pos) along normal axis (pos in dir of norm, etc.) |
| 54 | + u32* id = frustum_aabb_remap[P.aabb_overlap_id]; |
79 | 55 |
|
80 | | - sPoly* ClipPoly (sPoly& src, sPoly& dest) const; |
| 56 | + Fvector Neg; |
| 57 | + Neg.set(mM[id[3]], mM[id[4]], mM[id[5]]); |
| 58 | + if (P.classify(Neg) > 0) return fcvNone; |
81 | 59 |
|
82 | | - u32 getMask () const { return (1<<p_count)-1; } |
| 60 | + Fvector Pos; |
| 61 | + Pos.set(mM[id[0]], mM[id[1]], mM[id[2]]); |
| 62 | + if (P.classify(Pos) <= 0) return fcvFully; |
83 | 63 |
|
84 | | - EFC_Visible testSphere (Fvector& c, float r, u32& test_mask) const; |
85 | | - BOOL testSphere_dirty (Fvector& c, float r) const; |
86 | | - EFC_Visible testAABB (const float* mM, u32& test_mask) const; |
87 | | - EFC_Visible testSAABB (Fvector& c, float r, const float* mM, u32& test_mask) const; |
88 | | - BOOL testPolyInside_dirty(Fvector* p, int count) const; |
| 64 | + return fcvPartial; |
| 65 | + } |
89 | 66 |
|
90 | | - IC BOOL testPolyInside (sPoly& src) const |
| 67 | +public: |
| 68 | + IC void _clear() { p_count = 0; } |
| 69 | + void _add(Fplane& P); |
| 70 | + void _add(Fvector& P1, Fvector& P2, Fvector& P3); |
| 71 | + |
| 72 | + void SimplifyPoly_AABB(sPoly* P, Fplane& plane); |
| 73 | + |
| 74 | + void CreateOccluder(Fvector* p, int count, Fvector& vBase, CFrustum& clip); |
| 75 | + BOOL CreateFromClipPoly( |
| 76 | + Fvector* p, int count, Fvector& vBase, CFrustum& clip); // returns 'false' if creation failed |
| 77 | + void CreateFromPoints(Fvector* p, int count, Fvector& vBase); |
| 78 | + void CreateFromMatrix(Fmatrix& M, u32 mask); |
| 79 | + void CreateFromPortal(sPoly* P, Fvector& vPN, Fvector& vBase, Fmatrix& mFullXFORM); |
| 80 | + void CreateFromPlanes(Fplane* p, int count); |
| 81 | + |
| 82 | + sPoly* ClipPoly(sPoly& src, sPoly& dest) const; |
| 83 | + |
| 84 | + u32 getMask() const { return (1 << p_count) - 1; } |
| 85 | + EFC_Visible testSphere(Fvector& c, float r, u32& test_mask) const; |
| 86 | + BOOL testSphere_dirty(Fvector& c, float r) const; |
| 87 | + EFC_Visible testAABB(const float* mM, u32& test_mask) const; |
| 88 | + EFC_Visible testSAABB(Fvector& c, float r, const float* mM, u32& test_mask) const; |
| 89 | + BOOL testPolyInside_dirty(Fvector* p, int count) const; |
| 90 | + |
| 91 | + IC BOOL testPolyInside(sPoly& src) const |
91 | 92 | { |
92 | | - sPoly d; |
93 | | - return !!ClipPoly(src,d); |
| 93 | + sPoly d; |
| 94 | + return !!ClipPoly(src, d); |
94 | 95 | } |
95 | | - IC BOOL testPolyInside (Fvector* p, int count) const |
| 96 | + IC BOOL testPolyInside(Fvector* p, int count) const |
96 | 97 | { |
97 | | - sPoly src(p,count); |
| 98 | + sPoly src(p, count); |
98 | 99 | return testPolyInside(src); |
99 | 100 | } |
100 | 101 | }; |
101 | 102 | #pragma pack(pop) |
102 | 103 |
|
103 | | -#endif // !defined(AFX_FRUSTUM_H__E66ED755_F741_49CF_8B2A_404CCF7067F2__INCLUDED_) |
| 104 | +#endif // !defined(AFX_FRUSTUM_H__E66ED755_F741_49CF_8B2A_404CCF7067F2__INCLUDED_) |
0 commit comments