Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
colmathplane.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/colmathplane.cpp $*
26 * *
27 * Org Author:: Greg Hjelstrom *
28 * *
29 * Author : Kenny Mitchell *
30 * *
31 * $Modtime:: 06/26/02 4:04p $*
32 * *
33 * $Revision:: 10 $*
34 * *
35 * 06/26/02 KM Matrix name change to avoid MAX conflicts *
36 *---------------------------------------------------------------------------------------------*
37 * Functions: *
38 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
39
40
41#include "colmath.h"
42#include "colmathplane.h"
43#include "aaplane.h"
44#include "plane.h"
45#include "lineseg.h"
46#include "tri.h"
47#include "sphere.h"
48#include "aabox.h"
49#include "obbox.h"
50#include "wwdebug.h"
51
52
53
56{
57 float delta = point[plane.Normal] - plane.Dist;
58 if (delta > COINCIDENCE_EPSILON) {
59 return POS;
60 }
61 if (delta < -COINCIDENCE_EPSILON) {
62 return NEG;
63 }
64 return ON;
65}
66
69{
70 int mask = 0;
71 mask |= CollisionMath::Overlap_Test(plane,line.Get_P0());
72 mask |= CollisionMath::Overlap_Test(plane,line.Get_P1());
73 return eval_overlap_mask(mask);
74}
75
78{
79 int mask = 0;
80 mask |= CollisionMath::Overlap_Test(plane,*tri.V[0]);
81 mask |= CollisionMath::Overlap_Test(plane,*tri.V[1]);
82 mask |= CollisionMath::Overlap_Test(plane,*tri.V[2]);
83 return eval_overlap_mask(mask);
84}
85
88{
89 float delta = sphere.Center[plane.Normal] - plane.Dist;
90 if (delta > sphere.Radius) {
91 return POS;
92 }
93 if (delta < sphere.Radius) {
94 return NEG;
95 }
96 return BOTH;
97}
98
101{
102 float delta;
103 int mask = 0;
104
105 // check the 'min' side of the box
106 delta = (box.Center[plane.Normal] - box.Extent[plane.Normal]) - plane.Dist;
107 if (delta > WWMATH_EPSILON) {
108 mask |= POS;
109 } else if (delta < -WWMATH_EPSILON) {
110 mask |= NEG;
111 } else {
112 mask |= ON;
113 }
114
115 // check the 'max' side of the box
116 delta = (box.Center[plane.Normal] + box.Extent[plane.Normal]) - plane.Dist;
117 if (delta > WWMATH_EPSILON) {
118 mask |= POS;
119 } else if (delta < -WWMATH_EPSILON) {
120 mask |= NEG;
121 } else {
122 mask |= ON;
123 }
124
125 return eval_overlap_mask(mask);
126}
127
128
130CollisionMath::Overlap_Test(const AAPlaneClass & /*plane*/,const OBBoxClass & /*box*/)
131{
132// TODO
133 WWASSERT(0);
134 return POS;
135}
136
137
138// Plane functions. Where is operand B with respect to the plane
139
142{
143 int mask = 0;
144 mask |= CollisionMath::Overlap_Test(plane,line.Get_P0());
145 mask |= CollisionMath::Overlap_Test(plane,line.Get_P1());
146 return eval_overlap_mask(mask);
147}
148
151{
152 int mask = 0;
153 mask |= CollisionMath::Overlap_Test(plane,*tri.V[0]);
154 mask |= CollisionMath::Overlap_Test(plane,*tri.V[1]);
155 mask |= CollisionMath::Overlap_Test(plane,*tri.V[2]);
156 return eval_overlap_mask(mask);
157}
158
161{
162 float dist = Vector3::Dot_Product(sphere.Center,plane.N) - plane.D;
163 if (dist > sphere.Radius) {
164 return POS;
165 }
166 if (dist < -sphere.Radius) {
167 return NEG;
168 }
169 return BOTH;
170}
171
174{
175 // rotate the plane normal into box coordinates
176 Vector3 local_normal;
177 Vector3 posfarpt;
178 Vector3 negfarpt;
179 Matrix3x3::Transpose_Rotate_Vector(box.Basis,plane.N,&local_normal);
180
181 get_far_extent(local_normal,box.Extent,&posfarpt);
182
183 // transform the two extreme box coordinates into world space
184 Matrix3x3::Rotate_Vector(box.Basis,posfarpt,&posfarpt);
185 negfarpt = -posfarpt;
186 posfarpt += box.Center;
187 negfarpt += box.Center;
188
189 // overlap test
190 if (Overlap_Test(plane,negfarpt) == POS) {
191 return POS;
192 }
193 if (Overlap_Test(plane,posfarpt) == NEG) {
194 return NEG;
195 }
196 return BOTH;
197}
#define WWASSERT
#define WWMATH_EPSILON
Definition wwmath.h:54
Vector3 Center
Definition aabox.h:123
Vector3 Extent
Definition aabox.h:124
float Dist
Definition aaplane.h:67
AxisEnum Normal
Definition aaplane.h:66
static OverlapType Overlap_Test(const AAPlaneClass &plane, const Vector3 &point)
const Vector3 & Get_P1() const
Definition lineseg.h:71
const Vector3 & Get_P0() const
Definition lineseg.h:70
static WWINLINE void Rotate_Vector(const Matrix3x3 &tm, const Vector3 &in, Vector3 *out)
Definition matrix3.h:982
static WWINLINE void Transpose_Rotate_Vector(const Matrix3x3 &tm, const Vector3 &in, Vector3 *out)
Definition matrix3.h:1000
Vector3 Extent
Definition obbox.h:114
Matrix3x3 Basis
Definition obbox.h:112
Vector3 Center
Definition obbox.h:113
Vector3 N
Definition plane.h:67
float D
Definition plane.h:68
float Radius
Definition sphere.h:91
Vector3 Center
Definition sphere.h:90
Definition tri.h:61
const Vector3 * V[3]
Definition tri.h:65
static WWINLINE float Dot_Product(const Vector3 &a, const Vector3 &b)
Definition vector3.h:293
void get_far_extent(const Vector3 &normal, const Vector3 &extent, Vector3 *posfarpt)