Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
colmathobbox.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/colmathobbox.cpp $*
26 * *
27 * Org Author:: Greg Hjelstrom *
28 * *
29 * Author : Kenny Mitchell *
30 * *
31 * $Modtime:: 06/26/02 4:04p $*
32 * *
33 * $Revision:: 9 $*
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 "aaplane.h"
43#include "plane.h"
44#include "lineseg.h"
45#include "tri.h"
46#include "sphere.h"
47#include "aabox.h"
48#include "obbox.h"
49#include "wwdebug.h"
50
51
52
53// OBBox functions, where is operand B with respect to the OBBox
56{
57 // transform point into box coordinate system
58 Vector3 localpoint;
59 Matrix3x3::Transpose_Rotate_Vector(box.Basis,(point - box.Center),&localpoint);
60
61 // if the point is outside any of the extents, it is outside the box
62 if (WWMath::Fabs(localpoint.X) > box.Extent.X) {
63 return OUTSIDE;
64 }
65 if (WWMath::Fabs(localpoint.Y) > box.Extent.Y) {
66 return OUTSIDE;
67 }
68 if (WWMath::Fabs(localpoint.Z) > box.Extent.Z) {
69 return OUTSIDE;
70 }
71 return INSIDE;
72}
73
76{
78 Collide(line,box,&res);
79 return eval_overlap_collision(res);
80}
81
84{
86 Collide(box,Vector3(0,0,0),tri,Vector3(0,0,0),&res);
87 return eval_overlap_collision(res);
88}
89
92{
93 if (CollisionMath::Intersection_Test(aabox,obbox)) {
94 return BOTH; // inside or overlapping
95 } else {
96 return OUTSIDE;
97 }
98}
99
102{
103 if (CollisionMath::Intersection_Test(obbox,aabox)) {
104 return BOTH; // inside or overlapping
105 } else {
106 return OUTSIDE;
107 }
108}
109
110
113{
115 Collide(box,Vector3(0,0,0),box2,Vector3(0,0,0),&res);
116 return eval_overlap_collision(res);
117}
118
120(
121 const OBBoxClass & box,
122 const Vector3 & move_vector,
123 const PlaneClass & plane,
124 CastResultStruct * result
125)
126{
127 float frac;
128
129 float extent = box.Project_To_Axis(plane.N);
130 float dist = Vector3::Dot_Product(plane.N,box.Center) + plane.D;
131 float move = Vector3::Dot_Product(plane.N,move_vector);
132
133 if (dist > extent) {
134 if (dist + move > extent) {
135 // entire move ok!
136 frac = 1.0f;
137 } else {
138 // partial move allowed
139 frac = (extent - dist) / move;
140 }
141
142 } else if (dist < -extent) {
143 if (dist + move < -extent) {
144 // entire move ok!
145 frac = 1.0f;
146 } else {
147 // partial move allowed
148 frac = (-extent - dist) / move;
149 }
150 } else {
151 result->StartBad = true;
152 result->Normal = plane.N;
153 return true;
154 }
155
156 if (frac < result->Fraction) {
157 result->Fraction = frac;
158 result->Normal = plane.N;
159 if (result->ComputeContactPoint) {
160
161 Vector3 move_dir(move_vector);
162 move_dir.Normalize();
163 float move_extent = Vector3::Dot_Product(move_dir,box.Extent);
164 result->ContactPoint = box.Center + result->Fraction*move_vector + move_extent*move_dir;
165
166 }
167 return true;
168 }
169 return false;
170}
171
static bool Collide(const LineSegClass &line, const AAPlaneClass &plane, CastResultStruct *result)
static OverlapType Overlap_Test(const AAPlaneClass &plane, const Vector3 &point)
static bool Intersection_Test(const AABoxClass &box, const TriClass &tri)
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
float Project_To_Axis(const Vector3 &axis) const
Definition obbox.h:137
Vector3 N
Definition plane.h:67
float D
Definition plane.h:68
Definition tri.h:61
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
void Normalize(void)
Definition vector3.h:417
static WWINLINE float Fabs(float val)
Definition wwmath.h:113
Vector3 ContactPoint
Definition castres.h:70
bool ComputeContactPoint
Definition castres.h:69
Vector3 Normal
Definition castres.h:66