Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
coltest.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:: /VSS_Sync/ww3d2/coltest.h $*
26 * *
27 * Org Author:: Greg Hjelstrom *
28 * *
29 * Author : Kenny Mitchell *
30 * *
31 * $Modtime:: 07/01/02 12:45p $*
32 * *
33 * $Revision:: 5 $*
34 * *
35 * 07/01/02 KM Coltype enum change to avoid MAX conflicts *
36 *---------------------------------------------------------------------------------------------*
37 * Functions: *
38 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
39
40
41#if defined(_MSC_VER)
42#pragma once
43#endif
44
45#ifndef COLTEST_H
46#define COLTEST_H
47
48#include "always.h"
49#include "castres.h"
50#include "lineseg.h"
51#include "aabox.h"
52#include "obbox.h"
53#include "tri.h"
54#include "colmath.h"
55#include "coltype.h"
56
57class RenderObjClass;
58
59
61// CollisionTestClass
62//
63// Each type of collision test will have an associated class which
64// ties together all of the information necessary for the test.
65// These classes also provide a perfect place to add any information
66// which can be pre-calculated.
67//
68// The base class: CollisionTestClass simply contains a pointer to
69// the user's CastResultStruct which will contain the results of
70// the collision test. I store a pointer to a result structure
71// because in some cases, new CollisionTestClasses are created in
72// the process of checking (e.g. if the test needs to be transformed
73// into another coordinate system) and I did not want to be
74// constantly copying the result structure around. So, the user
75// must allocate a result structure (usually on the stack) and keep it
76// until the CollisionTestClass is discarded.
77//
78// Every CollisionTestClass should have the following functions:
79//
80// bool Cull(const Vector3 & min,const Vector3 & max);
81// bool Cull(const AABoxClass & box);
82// bool Cast_To_Triangle(const TriClass & tri);
83//
84// These are not virtual because I don't want to pay the price of virtual function
85// calls at the point in the code where these are used. It may be possible to
86// write template functions if we use these exact function prototpyes for all
87// collision test classes though.
88//
89//
102
103
105 Result(res),
106 CollisionType(collision_type),
108{
109}
110
117
118
120// RayCollisionTestClass
121//
122// Contains a linesegment to be tested and of course the inherited
123// pointer to a CollisionStruct for the result
124//
127{
128public:
129
130 RayCollisionTestClass(const LineSegClass & ray,CastResultStruct * res,int collision_type = COLL_TYPE_0,bool check_translucent=false, bool check_hidden=false);
131 RayCollisionTestClass(const RayCollisionTestClass & raytest,const Matrix3D & tm);
132
133 bool Cull(const Vector3 & min,const Vector3 & max);
134 bool Cull(const AABoxClass & box);
135 bool Cast_To_Triangle(const TriClass & tri);
136
137public:
138
142
143private:
144
145 // not implemented
147 RayCollisionTestClass & operator = (const RayCollisionTestClass &);
148
149};
150
151
152inline RayCollisionTestClass::RayCollisionTestClass(const LineSegClass & ray,CastResultStruct * res,int collision_type,bool check_translucent, bool check_hidden) :
153 CollisionTestClass(res,collision_type),
154 Ray(ray),
155 CheckTranslucent(check_translucent),
156 CheckHidden(check_hidden)
157{
158}
159
161 CollisionTestClass(raytest),
162 Ray(raytest.Ray,tm),
164 CheckHidden(raytest.CheckHidden)
165{
166}
167
172
174{
176}
177
179{
181}
182
183
185// AABoxCollisionTestClass
186//
187// Contains an Axis Aligned Box and a movement vector to be tested
188// for collision. Also adds Min and Max vectors both for the initial
189// box and for the volume swept out by the box.
190//
193{
194public:
195
196 AABoxCollisionTestClass(const AABoxClass & aabox,const Vector3 & move,CastResultStruct * res,int collision_type = COLL_TYPE_0);
198
206
207 bool Cull(const Vector3 & min,const Vector3 & max);
208 bool Cull(const AABoxClass & box);
209 bool Cast_To_Triangle(const TriClass & tri);
210
211 void Translate(const Vector3 & translation);
212 void Rotate(ROTATION_TYPE rotation);
213 void Transform(const Matrix3D & tm);
214
215public:
216
219
222
223private:
224
225 // not implemented
227
228};
229
230
231inline void AABoxCollisionTestClass::Translate(const Vector3 & translation)
232{
233 // translate the test by the desired translation vector
234 Box.Center += translation;
235 SweepMin += translation;
236 SweepMax += translation;
237}
238
240{
241 if ((SweepMin.X > max.X) || (SweepMax.X < min.X)) {
242 return true;
243 }
244
245 if ((SweepMin.Y > max.Y) || (SweepMax.Y < min.Y)) {
246 return true;
247 }
248
249 if ((SweepMin.Z > max.Z) || (SweepMax.Z < min.Z)) {
250 return true;
251 }
252 return false;
253}
254
259
260
262// OBBoxCollisionTestClass
263//
264// Contains an Oriented Bounding Box and a movement vector to be tested
265// for collision. Also adds Min and Max vectors (axis aligned box)
266// both for the initial box and for the volume swept out by the box.
267//
270{
271public:
272
273 OBBoxCollisionTestClass(const OBBoxClass & obbox,const Vector3 & move,CastResultStruct * res,int type = COLL_TYPE_0);
277
278 bool Cull(const Vector3 & min,const Vector3 & max);
279 bool Cull(const AABoxClass & box);
280 bool Cast_To_Triangle(const TriClass & tri);
281
282public:
283
288
289private:
290 // not implemented
292};
293
294
296{
297 if ((SweepMin.X > max.X) || (SweepMax.X < min.X)) {
298 return true;
299 }
300
301 if ((SweepMin.Y > max.Y) || (SweepMax.Y < min.Y)) {
302 return true;
303 }
304
305 if ((SweepMin.Z > max.Z) || (SweepMax.Z < min.Z)) {
306 return true;
307 }
308 return false;
309}
310
312{
313 return CollisionMath::Collide(Box,Move,tri,Vector3(0,0,0),Result);
314}
315
316
317#endif
#define NULL
Definition BaseType.h:92
#define min(x, y)
Definition BaseType.h:101
#define max(x, y)
Definition BaseType.h:105
void Translate(const Vector3 &translation)
Definition coltest.h:231
void Transform(const Matrix3D &tm)
Definition coltest.cpp:229
AABoxCollisionTestClass(const AABoxClass &aabox, const Vector3 &move, CastResultStruct *res, int collision_type=COLL_TYPE_0)
Definition coltest.cpp:50
bool Cast_To_Triangle(const TriClass &tri)
Definition coltest.h:255
bool Cull(const Vector3 &min, const Vector3 &max)
Definition coltest.h:239
void Rotate(ROTATION_TYPE rotation)
Definition coltest.cpp:99
static bool Collide(const LineSegClass &line, const AAPlaneClass &plane, CastResultStruct *result)
static OverlapType Overlap_Test(const AAPlaneClass &plane, const Vector3 &point)
CollisionTestClass(CastResultStruct *res, int collision_type)
Definition coltest.h:104
CastResultStruct * Result
Definition coltest.h:98
RenderObjClass * CollidedRenderObj
Definition coltest.h:100
bool Cull(const Vector3 &min, const Vector3 &max)
Definition coltest.h:295
OBBoxCollisionTestClass(const OBBoxClass &obbox, const Vector3 &move, CastResultStruct *res, int type=COLL_TYPE_0)
Definition coltest.cpp:281
bool Cast_To_Triangle(const TriClass &tri)
Definition coltest.h:311
LineSegClass Ray
Definition coltest.h:139
bool Cull(const Vector3 &min, const Vector3 &max)
Definition coltest.h:168
RayCollisionTestClass(const LineSegClass &ray, CastResultStruct *res, int collision_type=COLL_TYPE_0, bool check_translucent=false, bool check_hidden=false)
Definition coltest.h:152
bool Cast_To_Triangle(const TriClass &tri)
Definition coltest.h:178
Definition tri.h:61
@ COLL_TYPE_0
Definition coltype.h:76