Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
v3_rnd.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 : G *
24 * *
25 * $Archive:: /Commando/Code/wwmath/v3_rnd.cpp $*
26 * *
27 * $Author:: Greg_h $*
28 * *
29 * $Modtime:: 7/09/99 9:49a $*
30 * *
31 * $Revision:: 4 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37#include "v3_rnd.h"
38#include "vector2.h"
39
40const float Vector3Randomizer::OOIntMax = 1.0f / (float)INT_MAX;
41const float Vector3Randomizer::OOUIntMax = 1.0f / (float)UINT_MAX;
43
45{
46 Extents.X = MAX(extents.X, 0.0f);
47 Extents.Y = MAX(extents.Y, 0.0f);
48 Extents.Z = MAX(extents.Z, 0.0f);
49}
50
52{
53 vector.X = Get_Random_Float_Minus1_To_1() * Extents.X;
54 vector.Y = Get_Random_Float_Minus1_To_1() * Extents.Y;
55 vector.Z = Get_Random_Float_Minus1_To_1() * Extents.Z;
56}
57
59{
60 float max = MAX(Extents.X, Extents.Y);
61 max = MAX(max, Extents.Z);
62 return max;
63}
64
66{
67 scale = MAX(scale, 0.0f);
68 Extents.X *= scale;
69 Extents.Y *= scale;
70 Extents.Z *= scale;
71}
72
73
75{
76 Radius = MAX(radius, 0.0f);
77}
78
80{
81 // Generate vectors in a cube and discard the ones not in a sphere
82 float rad_squared = Radius * Radius;
83 for (;;) {
84 vector.X = Get_Random_Float_Minus1_To_1() * Radius;
85 vector.Y = Get_Random_Float_Minus1_To_1() * Radius;
86 vector.Z = Get_Random_Float_Minus1_To_1() * Radius;
87 if (vector.Length2() <= rad_squared) break;
88 }
89}
90
92{
93 return Radius;
94}
95
97{
98 scale = MAX(scale, 0.0f);
99 Radius *= scale;
100}
101
102
104{
105 Radius = MAX(radius, 0.0f);
106}
107
109{
110 // Generate vectors in a 2x2x2 origin-centered cube, discard the ones not in a unit-radius
111 // sphere and scale the result to Radius.
112 float v_l2;
113 for (;;) {
117 v_l2 = vector.Length2();
118 if (v_l2 <= 1.0f && v_l2 > 0.0f) break;
119 }
120
121 float scale = Radius * WWMath::Inv_Sqrt(v_l2);
122
123 vector.X *= scale;
124 vector.Y *= scale;
125 vector.Z *= scale;
126}
127
129{
130 return Radius;
131}
132
134{
135 scale = MAX(scale, 0.0f);
136 Radius *= scale;
137}
138
139
141{
142 Extent = MAX(extent, 0.0f);
143 Radius = MAX(radius, 0.0f);
144}
145
147{
148 vector.X = Get_Random_Float_Minus1_To_1() * Extent;
149
150 // Generate 2D vectors in a square and discard the ones not in a circle
151 Vector2 vec2;
152 float rad_squared = Radius * Radius;
153 for (;;) {
154 vec2.X = Get_Random_Float_Minus1_To_1() * Radius;
155 vec2.Y = Get_Random_Float_Minus1_To_1() * Radius;
156 if (vec2.Length2() <= rad_squared) break;
157 }
158
159 vector.Y = vec2.X;
160 vector.Z = vec2.Y;
161}
162
164{
165 return MAX(Extent, Radius);
166}
167
169{
170 scale = MAX(scale, 0.0f);
171 Extent *= scale;
172 Radius *= scale;
173}
#define max(x, y)
Definition BaseType.h:105
Color scale(const Color &a, const Color &b)
Definition GameMtl.cpp:722
#define MAX(a, b)
Definition always.h:185
float Y
Definition vector2.h:79
float X
Definition vector2.h:74
WWINLINE float Length2(void) const
Definition vector2.h:378
virtual void Scale(float scale)
Definition v3_rnd.cpp:133
virtual float Get_Maximum_Extent(void)
Definition v3_rnd.cpp:128
virtual void Get_Vector(Vector3 &vector)
Definition v3_rnd.cpp:108
Vector3HollowSphereRandomizer(float radius)
Definition v3_rnd.cpp:103
float X
Definition vector3.h:90
WWINLINE float Length2(void) const
Definition vector3.h:469
float Z
Definition vector3.h:92
float Y
Definition vector3.h:91
static Random3Class Randomizer
Definition v3_rnd.h:99
static const float OOIntMax
Definition v3_rnd.h:97
float Get_Random_Float_Minus1_To_1()
Definition v3_rnd.h:94
static const float OOUIntMax
Definition v3_rnd.h:98
virtual void Get_Vector(Vector3 &vector)
Definition v3_rnd.cpp:51
virtual void Scale(float scale)
Definition v3_rnd.cpp:65
Vector3SolidBoxRandomizer(const Vector3 &extents)
Definition v3_rnd.cpp:44
virtual float Get_Maximum_Extent(void)
Definition v3_rnd.cpp:58
virtual void Scale(float scale)
Definition v3_rnd.cpp:168
Vector3SolidCylinderRandomizer(float extent, float radius)
Definition v3_rnd.cpp:140
virtual float Get_Maximum_Extent(void)
Definition v3_rnd.cpp:163
virtual void Get_Vector(Vector3 &vector)
Definition v3_rnd.cpp:146
Vector3SolidSphereRandomizer(float radius)
Definition v3_rnd.cpp:74
virtual float Get_Maximum_Extent(void)
Definition v3_rnd.cpp:91
virtual void Get_Vector(Vector3 &vector)
Definition v3_rnd.cpp:79
virtual void Scale(float scale)
Definition v3_rnd.cpp:96
static float Inv_Sqrt(float a)
Definition wwmath.h:651