Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
gridsnapmodifier.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 : Max2W3d *
24 * *
25 * $Archive:: /Commando/Code/Tools/max2w3d/gridsnapmodifier.cpp $*
26 * *
27 * Original Author:: Greg Hjelstrom *
28 * *
29 * $Author:: Greg_h $*
30 * *
31 * $Modtime:: 5/01/01 8:29p $*
32 * *
33 * $Revision:: 1 $*
34 * *
35 *---------------------------------------------------------------------------------------------*
36 * Functions: *
37 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
38
39
40
41#include "Max.h"
42#include "resource.h"
43#include "simpmod.h"
44#include "dllmain.h"
45#include "iparamb2.h"
46
47
48/*
49
50 WARNING WARNING WARNING PLEASE READ - This modifier was an experiment to see if we could
51 solve cracks in adjacent meshes by snapping to a world-space grid. It didn't work for a
52 few reasons:
53 - I couldn't implement the world space snapping; the SimpleMod code seems to always force
54 you to work relative to each object.
55 - Snapping to a grid won't always snap vertices to the same grid. The probability that
56 it will work is a function of the distance between the points and the grid spacing
57
58*/
59
60
61
62#define GRIDSNAPMOD_CLASSID Class_ID(0x7a2d399b, 0x1e3d2004)
63
64
71class GridSnapModifierClass : public SimpleMod2
72{
73public:
74
76
77 // From Animatable
78 void DeleteThis() { delete this; }
80 virtual Class_ID ClassID() { return GRIDSNAPMOD_CLASSID; }
81 void BeginEditParams( IObjParam *ip, ULONG flags,Animatable *prev);
82 void EndEditParams( IObjParam *ip,ULONG flags,Animatable *next);
83 RefTargetHandle Clone(RemapDir& remap = NoRemap());
85 IOResult Load(ILoad *iload);
86
87 // Direct paramblock access
88 int NumParamBlocks() { return 1; }
89 IParamBlock2* GetParamBlock(int i) { return pblock2; }
90 IParamBlock2* GetParamBlockByID(BlockID id) { return (pblock2->ID() == id) ? pblock2 : NULL; }
91
92 // From simple mod
93 Deformer& GetDeformer(TimeValue t,ModContext &mc,Matrix3& mat,Matrix3& invmat);
94 Interval GetValidity(TimeValue t);
95
96 //RefTargetHandle GetReference(int i)
97 //void SetReference(int i,RefTargetHandle rtar)
98 //Animatable * SubAnim(int i)
99};
100
107class GridSnapDeformerClass : public Deformer
108{
109public:
110 GridSnapDeformerClass(void) : GridDimension(0.001f) {}
111
112 void Set_Grid_Dimension(float grid_dim) { GridDimension = grid_dim; }
113 float Get_Grid_Dimension(void) { return GridDimension; }
114
115 void Set_Matrices(const Matrix3 & tm,const Matrix3 & invtm) { Transform = tm; InvTransform = invtm; }
116
117 virtual Point3 Map(int i,Point3 p)
118 {
119 p = p*Transform;
120 p.x = floor(p.x / GridDimension) * GridDimension;
121 p.y = floor(p.y / GridDimension) * GridDimension;
122 p.z = floor(p.z / GridDimension) * GridDimension;
123 p = p*InvTransform;
124
125 return p;
126 }
127
128private:
129 float GridDimension;
130 Matrix3 Transform;
131 Matrix3 InvTransform;
132};
133
134
140class GridSnapModifierClassDesc:public ClassDesc2
141{
142public:
143 int IsPublic() { return 1; }
144 void * Create(BOOL loading = FALSE) { return new GridSnapModifierClass; }
145 const TCHAR * ClassName() { return _T("Grid Snap Modifier"); }
146 SClass_ID SuperClassID() { return OSM_CLASS_ID; }
147 Class_ID ClassID() { return GRIDSNAPMOD_CLASSID; }
148 const TCHAR* Category() { return _T("Westwood Modifiers");}
149 HINSTANCE HInstance() { return AppInstance; }
150 const TCHAR * InternalName() { return _T("Westwood GridSnap"); }
151};
152
153static GridSnapModifierClassDesc _GridSnapModifierDesc;
154
156{
157 return &_GridSnapModifierDesc;
158}
159
160
161/*
162** ParamBlock2 Setup
163*/
164enum
165{
167};
168
169enum
170{
172};
173
174static ParamBlockDesc2 _GridSnapParamBlockDesc
175(
176 // parameter block settings
177 GSM_PARAMS,_T("GridSnap Parameters"), 0, &_GridSnapModifierDesc, P_AUTO_CONSTRUCT + P_AUTO_UI, SIMPMOD_PBLOCKREF,
178
179 // dialog box
181
182 // parameters
183 GSM_PARAM_GRIDDIMENSION, _T("Grid Dimension"), TYPE_FLOAT, P_RESET_DEFAULT, IDS_GRID_DIMENSION,
184 p_default, 0.001f,
185 p_range, 0.0001f, 10.0f,
186 p_ui, TYPE_SPINNER, EDITTYPE_FLOAT, IDC_GRIDDIM_EDIT, IDC_GRIDDIM_SPIN, 0.0001f,
187 end,
188
189 end
190);
191
192
193/********************************************************************************************
194**
195** GridSnapModifierClass Implementation
196**
197********************************************************************************************/
198
200{
201 // create the parameter block, storing in the base-class's pblock variable
202 _GridSnapModifierDesc.MakeAutoParamBlocks(this);
203 assert(pblock2);
204}
205
206void GridSnapModifierClass::BeginEditParams( IObjParam *ip, ULONG flags,Animatable *prev)
207{
208 this->ip = ip;
209
210 SimpleMod2::BeginEditParams(ip,flags,prev);
211 _GridSnapModifierDesc.BeginEditParams(ip, this, flags, prev);
212}
213
214void GridSnapModifierClass::EndEditParams( IObjParam *ip,ULONG flags,Animatable *next)
215{
216 SimpleMod2::EndEditParams(ip,flags,next);
217 _GridSnapModifierDesc.EndEditParams(ip, this, flags, next);
218
219 this->ip = NULL;
220}
221
222RefTargetHandle GridSnapModifierClass::Clone(RemapDir& remap)
223{
225 newmod->ReplaceReference(SIMPMOD_PBLOCKREF,pblock2->Clone(remap));
226 newmod->SimpleModClone(this);
227 return(newmod);
228}
229
230IOResult GridSnapModifierClass::Load(ILoad *iload)
231{
232 Modifier::Load(iload);
233 return IO_OK;
234}
235
236Deformer& GridSnapModifierClass::GetDeformer(TimeValue t,ModContext &mc,Matrix3& mat,Matrix3& invmat)
237{
238 float dimension = 0.0f; Interval valid = FOREVER;
239 pblock2->GetValue(GSM_PARAM_GRIDDIMENSION, t, dimension, FOREVER);
240
241 static GridSnapDeformerClass deformer;
242 deformer.Set_Grid_Dimension(dimension);
243 deformer.Set_Matrices(mat,invmat);
244 return deformer;
245}
246
248{
249 float f;
250 Interval valid = FOREVER;
251 pblock2->GetValue(GSM_PARAM_GRIDDIMENSION, t, f, valid);
252 return valid;
253}
254
255RefTargetHandle SimpleMod2::GetReference(int i)
256{
257 switch (i) {
258 case 0: return tmControl;
259 case 1: return posControl;
260 case 2: return pblock2;
261 default: return NULL;
262 }
263}
264
265void SimpleMod2::SetReference(int i,RefTargetHandle rtarg)
266{
267 switch (i) {
268 case 0: tmControl = (Control*)rtarg; break;
269 case 1: posControl = (Control*)rtarg; break;
270 case 2: pblock2 = (IParamBlock2*)rtarg; break;
271 }
272}
273
274Animatable * SimpleMod2::SubAnim(int i)
275{
276 switch (i) {
277 case 0: return posControl;
278 case 1: return tmControl;
279 case 2: return pblock2;
280 default: return NULL;
281 }
282}
#define NULL
Definition BaseType.h:92
#define FALSE
Definition BaseType.h:113
@ FOREVER
Definition GameCommon.h:196
unsigned long ULONG
Definition bittype.h:64
#define IDS_GRID_DIMENSION
Definition resource.h:429
#define IDD_GRIDSNAP_PARAMS
Definition resource.h:113
#define IDC_GRIDDIM_EDIT
Definition resource.h:389
#define IDS_GRIDSNAP_TITLE
Definition resource.h:428
#define IDC_GRIDDIM_SPIN
Definition resource.h:390
#define IDS_GRIDSNAPMODIFIER
Definition resource.h:427
#define BOOL
Definition Wnd_File.h:57
void Set_Matrices(const Matrix3 &tm, const Matrix3 &invtm)
void Set_Grid_Dimension(float grid_dim)
virtual Point3 Map(int i, Point3 p)
void * Create(BOOL loading=FALSE)
IParamBlock2 * GetParamBlockByID(BlockID id)
IParamBlock2 * GetParamBlock(int i)
void BeginEditParams(IObjParam *ip, ULONG flags, Animatable *prev)
IOResult Load(ILoad *iload)
Interval GetValidity(TimeValue t)
RefTargetHandle Clone(RemapDir &remap=NoRemap())
Deformer & GetDeformer(TimeValue t, ModContext &mc, Matrix3 &mat, Matrix3 &invmat)
void EndEditParams(IObjParam *ip, ULONG flags, Animatable *next)
virtual Class_ID ClassID()
HINSTANCE AppInstance
Definition dllmain.cpp:67
TCHAR * Get_String(int id)
Definition dllmain.cpp:198
#define GRIDSNAPMOD_CLASSID
@ GSM_PARAM_GRIDDIMENSION
ClassDesc * Get_Grid_Snap_Modifier_Desc(void)
@ GSM_PARAMS