Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
colmathplane.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 : WWMath *
24 * *
25 * $Archive:: /Commando/Code/wwmath/colmathplane.h $*
26 * *
27 * Original Author:: Greg Hjelstrom *
28 * *
29 * $Author:: Greg_h $*
30 * *
31 * $Modtime:: 3/29/00 4:42p $*
32 * *
33 * $Revision:: 2 $*
34 * *
35 *---------------------------------------------------------------------------------------------*
36 * Functions: *
37 * get_far_extent -- gets extents of a box projected onto an axis *
38 * CollisionMath::Overlap_Test -- Tests overlap between a plane and a point *
39 * CollisionMath::Overlap_Test -- Tests overlap between a plane and an AABox *
40 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
41
42
43#ifndef COLMATHPLANE_H
44#define COLMATHPLANE_H
45
46#include "always.h"
47#include "plane.h"
48#include "aabox.h"
49
50/*
51** Inline collision functions dealing with planes
52** This module is meant to be included only in .CPP files after you include colmath.h
53** It is not automatically included in order to reduce file dependencies...
54*/
55
56/***********************************************************************************************
57 * get_far_extent -- gets extents of a box projected onto an axis *
58 * *
59 * INPUT: *
60 * *
61 * OUTPUT: *
62 * *
63 * WARNINGS: *
64 * *
65 * HISTORY: *
66 * 3/29/2000 gth : Created. *
67 *=============================================================================================*/
68inline void get_far_extent(const Vector3 & normal,const Vector3 & extent,Vector3 * posfarpt)
69{
71 posfarpt->X = extent.X;
72 } else {
73 posfarpt->X = -extent.X;
74 }
75
77 posfarpt->Y = extent.Y;
78 } else {
79 posfarpt->Y = -extent.Y;
80 }
81
83 posfarpt->Z = extent.Z;
84 } else {
85 posfarpt->Z = -extent.Z;
86 }
87}
88
89
90/***********************************************************************************************
91 * CollisionMath::Overlap_Test -- Tests overlap between a plane and a point *
92 * *
93 * INPUT: *
94 * *
95 * OUTPUT: *
96 * *
97 * WARNINGS: *
98 * *
99 * HISTORY: *
100 * 3/29/2000 gth : Created. *
101 *=============================================================================================*/
102inline
105{
106 float delta = Vector3::Dot_Product(point,plane.N) - plane.D;
107 if (delta > COINCIDENCE_EPSILON) {
108 return POS;
109 }
110 if (delta < -COINCIDENCE_EPSILON) {
111 return NEG;
112 }
113 return ON;
114}
115
116
117/***********************************************************************************************
118 * CollisionMath::Overlap_Test -- Tests overlap between a plane and an AABox *
119 * *
120 * INPUT: *
121 * *
122 * OUTPUT: *
123 * *
124 * WARNINGS: *
125 * *
126 * HISTORY: *
127 * 3/29/2000 gth : Created. *
128 *=============================================================================================*/
129inline
132{
133 // First, we determine the the near and far points of the box in the
134 // direction of the plane normal
135 Vector3 posfarpt;
136 Vector3 negfarpt;
137
138 get_far_extent(plane.N,box.Extent,&posfarpt);
139
140 negfarpt = -posfarpt;
141 posfarpt += box.Center;
142 negfarpt += box.Center;
143 if (Overlap_Test(plane,negfarpt) == POS) {
144 return POS;
145 }
146 if (Overlap_Test(plane,posfarpt) == NEG) {
147 return NEG;
148 }
149 return BOTH;
150}
151
152
153#endif
154
Vector3 Center
Definition aabox.h:123
Vector3 Extent
Definition aabox.h:124
static OverlapType Overlap_Test(const AAPlaneClass &plane, const Vector3 &point)
Vector3 N
Definition plane.h:67
float D
Definition plane.h:68
static WWINLINE float Dot_Product(const Vector3 &a, const Vector3 &b)
Definition vector3.h:293
float X
Definition vector3.h:90
float Z
Definition vector3.h:92
float Y
Definition vector3.h:91
static bool Fast_Is_Float_Positive(const float &val)
Definition wwmath.h:193
void get_far_extent(const Vector3 &normal, const Vector3 &extent, Vector3 *posfarpt)