Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
inttest.h
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 : WW3D *
24 * *
25 * $Archive:: /Commando/Code/ww3d2/inttest.h $*
26 * *
27 * Original Author:: Greg Hjelstrom *
28 * *
29 * $Author:: Greg_h $*
30 * *
31 * $Modtime:: 3/14/01 9:19a $*
32 * *
33 * $Revision:: 2 $*
34 * *
35 *---------------------------------------------------------------------------------------------*
36 * Functions: *
37 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
38
39#if defined(_MSC_VER)
40#pragma once
41#endif
42
43#ifndef INTTEST_H
44#define INTTEST_H
45
46#include "always.h"
47#include "aabox.h"
48#include "obbox.h"
49#include "tri.h"
50#include "colmath.h"
51#include "coltype.h"
52
53
55// IntersectionTestClass
56//
57// This is the base class for all of the 'Intersection' functions. The intersection tests are
58// purely boolean tests. The base class only contains the CollisionType of the test.
59//
60// Every IntersectionTestClass should have the following functions:
61//
62// bool Cull(const Vector3 & min,const Vector3 & max);
63// bool Cull(const AABoxClass & box);
64// bool Intersect_Triangle(const TriClass & tri);
65//
66// These are not virtual because I don't want to pay the price of virtual function
67// calls at the point in the code where these are used. It may be possible to
68// write template functions if we use these exact function prototpyes for all
69// collision test classes though.
70//
73{
74public:
75 IntersectionTestClass(int collision_type) : CollisionType(collision_type) { }
77
78public:
80};
81
82
84// AABoxIntersectionTestClass
85//
86// This is an intersection test which uses an Axis-Aligned Box
87//
90{
91public:
92 AABoxIntersectionTestClass(const AABoxClass & box,int collision_type) :
93 IntersectionTestClass(collision_type),
94 Box(box)
95 {
96 }
97
103
104 bool Cull(const Vector3 & cull_min,const Vector3 & cull_max);
105 bool Cull(const AABoxClass & cull_box);
106 bool Intersect_Triangle(const TriClass & tri);
107
108public:
109 AABoxClass Box; // world space aabox that we want to test with
110
111};
112
113inline bool AABoxIntersectionTestClass::Cull(const Vector3 & cull_min,const Vector3 & cull_max)
114{
115 Vector3 box_min;
116 Vector3::Subtract(Box.Center,Box.Extent,&box_min);
117
118 Vector3 box_max;
119 Vector3::Add(Box.Center,Box.Extent,&box_max);
120
121 if ((box_min.X > cull_max.X) || (box_max.X < cull_min.X)) return true;
122 if ((box_min.Y > cull_max.Y) || (box_max.Y < cull_min.Y)) return true;
123 if ((box_min.Z > cull_max.Z) || (box_max.Z < cull_min.Z)) return true;
124
125 return false;
126}
127
128inline bool AABoxIntersectionTestClass::Cull(const AABoxClass & cull_box)
129{
130 Vector3 dc;
131 Vector3 r;
132 Vector3::Subtract(cull_box.Center,Box.Center,&dc);
133 Vector3::Add(cull_box.Extent,Box.Extent,&r);
134
135 if (WWMath::Fabs(dc.X) > r.X) return true;
136 if (WWMath::Fabs(dc.Y) > r.Y) return true;
137 if (WWMath::Fabs(dc.Z) > r.Z) return true;
138
139 return false;
140}
141
146
147
149// OBBoxIntersectionTestClass
150//
151// This is an intersection test which uses an Axis-Aligned Box
152//
155{
156public:
157
158 OBBoxIntersectionTestClass(const OBBoxClass & box,int collision_type);
162
163 bool Cull(const Vector3 & min,const Vector3 & max);
164 bool Cull(const AABoxClass & box);
165 bool Intersect_Triangle(const TriClass & tri);
166
167protected:
168 void update_bounding_box(void);
169
170public:
171 OBBoxClass Box; // world space obbox that we want to test with
172 AABoxClass BoundingBox; // axis aligned w-s bounding box
173};
174
175
177 IntersectionTestClass(collision_type),
178 Box(box)
179{
181}
182
189
200
202(
203 const AABoxIntersectionTestClass & that,
204 const Matrix3D & tm
205) :
207{
208 Matrix3D::Transform_Vector(tm,that.Box.Center,&(Box.Center));
209 Box.Extent = that.Box.Extent;
210 Box.Basis = tm; // copies the 3x3 rotation portion of the transform
212}
213
214inline bool OBBoxIntersectionTestClass::Cull(const Vector3 & cull_min,const Vector3 & cull_max)
215{
216 Vector3 box_min;
217 Vector3::Subtract(BoundingBox.Center,BoundingBox.Extent,&box_min);
218
219 Vector3 box_max;
220 Vector3::Add(BoundingBox.Center,BoundingBox.Extent,&box_max);
221
222 if ((box_min.X > cull_max.X) || (box_max.X < cull_min.X)) return true;
223 if ((box_min.Y > cull_max.Y) || (box_max.Y < cull_min.Y)) return true;
224 if ((box_min.Z > cull_max.Z) || (box_max.Z < cull_min.Z)) return true;
225
226 return false;
227}
228
229inline bool OBBoxIntersectionTestClass::Cull(const AABoxClass & cull_box)
230{
231 Vector3 dc;
232 Vector3 r;
233 Vector3::Subtract(cull_box.Center,BoundingBox.Center,&dc);
234 Vector3::Add(cull_box.Extent,BoundingBox.Extent,&r);
235
236 if (WWMath::Fabs(dc.X) > r.X) return true;
237 if (WWMath::Fabs(dc.Y) > r.Y) return true;
238 if (WWMath::Fabs(dc.Z) > r.Z) return true;
239
240 return false;
241}
242
247
249{
250 BoundingBox.Center = Box.Center;
251 Box.Basis.Rotate_AABox_Extent(Box.Extent,&BoundingBox.Extent);
252}
253
254
255
256#endif
#define min(x, y)
Definition BaseType.h:101
#define max(x, y)
Definition BaseType.h:105
Vector3 Center
Definition aabox.h:123
Vector3 Extent
Definition aabox.h:124
AABoxIntersectionTestClass(const AABoxIntersectionTestClass &that)
Definition inttest.h:98
bool Intersect_Triangle(const TriClass &tri)
Definition inttest.h:142
AABoxIntersectionTestClass(const AABoxClass &box, int collision_type)
Definition inttest.h:92
bool Cull(const Vector3 &cull_min, const Vector3 &cull_max)
Definition inttest.h:113
static bool Intersection_Test(const AABoxClass &box, const TriClass &tri)
IntersectionTestClass(int collision_type)
Definition inttest.h:75
IntersectionTestClass(const IntersectionTestClass &that)
Definition inttest.h:76
static WWINLINE void Transform_Vector(const Matrix3D &tm, const Vector3 &in, Vector3 *out)
Definition matrix3d.h:1742
static void Transform(const Matrix3D &tm, const OBBoxClass &in, OBBoxClass *out)
Definition obbox.h:161
bool Cull(const Vector3 &min, const Vector3 &max)
Definition inttest.h:214
bool Intersect_Triangle(const TriClass &tri)
Definition inttest.h:243
OBBoxIntersectionTestClass(const OBBoxClass &box, int collision_type)
Definition inttest.h:176
void update_bounding_box(void)
Definition inttest.h:248
Definition tri.h:61
float X
Definition vector3.h:90
float Z
Definition vector3.h:92
float Y
Definition vector3.h:91
static WWINLINE void Subtract(const Vector3 &a, const Vector3 &b, Vector3 *c)
Definition vector3.h:576
static WWINLINE void Add(const Vector3 &a, const Vector3 &b, Vector3 *c)
Definition vector3.h:555
static WWINLINE float Fabs(float val)
Definition wwmath.h:113