Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
colmathfrustum.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : WWMath *
24 * *
25 * $Archive:: /Commando/Code/wwmath/colmathfrustum.cpp $*
26 * *
27 * Author:: Greg Hjelstrom *
28 * *
29 * $Modtime:: 3/29/00 5:40p $*
30 * *
31 * $Revision:: 7 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37
38#include "colmath.h"
39#include "colmathinlines.h"
40#include "aaplane.h"
41#include "plane.h"
42#include "lineseg.h"
43#include "tri.h"
44#include "sphere.h"
45#include "aabox.h"
46#include "obbox.h"
47#include "frustum.h"
48#include "wwdebug.h"
49
50
51// TODO: Most of these overlap functions actually do not catch all cases of when
52// the primitive is outside of the frustum...
53
54
55// Frustum functions
57CollisionMath::Overlap_Test(const FrustumClass & frustum,const Vector3 & point)
58{
59 int mask = 0;
60
61 for (int i = 0; i < 6; i++) {
62 int result = CollisionMath::Overlap_Test(frustum.Planes[i],point);
63 if (result == OUTSIDE) {
64 return OUTSIDE;
65 }
66 mask |= result;
67 }
68
69 if (mask == INSIDE) {
70 return INSIDE;
71 }
72 return OVERLAPPED;
73}
74
77{
78 int mask = 0;
79
80 // TODO: doesn't catch all cases...
81 for (int i = 0; i < 6; i++) {
82 int result = CollisionMath::Overlap_Test(frustum.Planes[i],tri);
83 if (result == OUTSIDE) {
84 return OUTSIDE;
85 }
86 mask |= result;
87 }
88
89 if (mask == INSIDE) {
90 return INSIDE;
91 }
92 return OVERLAPPED;
93}
94
97{
98 int mask = 0;
99
100 // TODO: doesn't catch all cases...
101 for (int i = 0; i < 6; i++) {
102 int result = CollisionMath::Overlap_Test(frustum.Planes[i],sphere);
103 if (result == OUTSIDE) {
104 return OUTSIDE;
105 }
106 mask |= result;
107 }
108
109 if (mask == INSIDE) {
110 return INSIDE;
111 }
112 return OVERLAPPED;
113}
114
117{
118 int mask = 0;
119
120 // TODO: doesn't catch all cases...
121 for (int i = 0; i < 6; i++) {
122 int result = CollisionMath::Overlap_Test(frustum.Planes[i],box);
123 if (result == OUTSIDE) {
124 return OUTSIDE;
125 }
126 mask |= result;
127 }
128
129 if (mask == INSIDE) {
130 return INSIDE;
131 }
132 return OVERLAPPED;
133}
134
135
138{
139 int mask = 0;
140
141 // TODO: doesn't catch all cases...
142 for (int i = 0; i < 6; i++) {
143 int result = CollisionMath::Overlap_Test(frustum.Planes[i],box);
144 if (result == OUTSIDE) {
145 return OUTSIDE;
146 }
147 mask |= result;
148 }
149
150 if (mask == INSIDE) {
151 return INSIDE;
152 }
153 return OVERLAPPED;
154}
155
156
158CollisionMath::Overlap_Test(const FrustumClass & frustum,const OBBoxClass & box,int & planes_passed)
159{
160 int mask = 0;
161
162 // TODO: doesn't catch all cases...
163 for (int i = 0; i < 6; i++) {
164
165 int plane_bit = (1<<i);
166
167 // only check this plane if we have to
168 if ((planes_passed & plane_bit) == 0) {
169
170 int result = CollisionMath::Overlap_Test(frustum.Planes[i],box);
171 if (result == OUTSIDE) {
172 return OUTSIDE;
173 } else if (result == INSIDE) {
174 planes_passed |= plane_bit;
175 }
176 mask |= result;
177
178 } else {
179
180 mask |= INSIDE;
181
182 }
183 }
184
185 if (mask == INSIDE) {
186 return INSIDE;
187 }
188 return OVERLAPPED;
189}
190
static OverlapType Overlap_Test(const AAPlaneClass &plane, const Vector3 &point)
PlaneClass Planes[6]
Definition frustum.h:64
Definition tri.h:61