Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
sphereobj.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 : WW3D *
24 * *
25 * $Archive:: /Commando/Code/ww3d2/sphereobj.h $*
26 * *
27 * Author:: Jason Andersen *
28 * *
29 * $Modtime:: 11/24/01 6:21p $*
30 * *
31 * $Revision:: 7 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37#if defined(_MSC_VER)
38#pragma once
39#endif
40
41#ifndef SPHEREOBJ_H
42#define SPHEREOBJ_H
43
44#include "always.h"
45#include "rendobj.h"
46#include "w3d_file.h"
47#include "shader.h"
48#include "proto.h"
49#include "obbox.h"
50#include "vector3i.h"
51#include "quat.h"
52#include "prim_anim.h"
53#include "meshgeometry.h"
54
55class TextureClass;
56
58{
60 : angle (true),
61 intensity (1.0F) { }
62 AlphaVectorStruct (const AlphaVectorStruct &src) { *this = src; }
63
64 bool operator== (const AlphaVectorStruct &src) { return (angle.X == src.angle.X) && (angle.Y == src.angle.Y) && (angle.Z == src.angle.Z) && (intensity == src.intensity); }
65 bool operator!= (const AlphaVectorStruct &src) { return ! operator== (src); }
66
67 const AlphaVectorStruct & operator= (const AlphaVectorStruct &src) { angle = src.angle; intensity = src.intensity; return *this; }
68
70 float intensity;
71};
72
73class AlphaVectorChannel : public PrimitiveAnimationChannelClass<AlphaVectorStruct>
74{
75public:
77 {
78 int key_count = m_Data.Count ();
79 AlphaVectorStruct value = m_Data[key_count - 1].Get_Value ();
80
81 //
82 // Don't interpolate past the last keyframe
83 //
84 if (time < m_Data[key_count - 1].Get_Time ()) {
85
86 // Check to see if the last key index is valid
87 if (time < m_Data[m_LastIndex].Get_Time ()) {
88 m_LastIndex = 0;
89 }
90
91 KeyClass *key1 = &m_Data[m_LastIndex];
92 KeyClass *key2 = &m_Data[key_count - 1];
93
94 //
95 // Search, using last_key as our starting point
96 //
97 for (int keyidx = m_LastIndex; keyidx < (key_count - 1); keyidx ++) {
98
99 if (time < m_Data[keyidx+1].Get_Time ()) {
100 key1 = &m_Data[keyidx];
101 key2 = &m_Data[keyidx+1];
102 m_LastIndex = keyidx;
103 break;
104 }
105 }
106
107 // Calculate the linear percent between the two keys
108 float percent = (time - key1->Get_Time ()) / (key2->Get_Time () - key1->Get_Time ());
109
110 // Slerp the quaternions and lerp the intensities
111 value.intensity = (key1->Get_Value ().intensity + (key2->Get_Value ().intensity - key1->Get_Value ().intensity) * percent);
112 Fast_Slerp (value.angle, key1->Get_Value ().angle, key2->Get_Value ().angle, percent);
113 }
114
115 return value;
116 }
117};
118
120{
121 uint32 Version; // file format version
122 uint32 Attributes; // sphere attributes (above #define's)
123 char Name[2*W3D_NAME_LEN]; // name is in the form <containername>.<spherename>
124
125 W3dVectorStruct Center; // center of the sphere
126 W3dVectorStruct Extent; // extent of the sphere
127
128 float AnimDuration; // Animation time (in seconds)
129
134
137
138 //
139 // Note this structure is followed by a series of
140 // W3dSphereKeyArrayStruct structures which define the
141 // variable set of keyframes for each channel.
142 //
143};
144
149//typedef AlphaVectorChannel ;
150
152
153
155{
157
158public:
159 // Constructor
160 SphereMeshClass(void);
161 SphereMeshClass(float radius, int slices, int stacks);
162 // Destructor
163 ~SphereMeshClass(void);
164
165 void Generate (float radius, int slices, int stacks);
166 int Get_Num_Polys (void) { return face_ct; };
167 void Set_Alpha_Vector (const AlphaVectorStruct &v, bool inverse, bool is_additive, bool force = false);
168
169private:
170
171 void Set_DCG (bool is_additive, int index, float value);
172
173 void Free(void);
174
175 float Radius;
176 int Slices;
177 int Stacks;
178 int face_ct; // # of faces
179
180 int Vertex_ct; // vertex count
181 Vector3 *vtx; // array of vertices
182 Vector3 *vtx_normal; // array of vertex normals
183 Vector2 *vtx_uv; // array of vertex uv coordinates
184 Vector4 *dcg;
185
186 AlphaVectorStruct alpha_vector; // vector last used to computer vtx_alpha array
187 bool inverse_alpha; // inverse alpha, or not
188 bool IsAdditive;
189
190 int strip_ct; // number of strips
191 int strip_size; // size of each strip
192 int *strips; // array of vertex indices for each strip (# stripbs x sizeof strip)
193
194 int fan_ct; // number of fans
195 int fan_size; // size of each fan
196 int *fans; // array of vertex indices for each fan (# of fans by fan_size)
197
198 TriIndex *tri_poly; // array of triangle poly's, vertex indices (can be discard if switched to strips + fans)
199
200};
201
202inline void
203SphereMeshClass::Set_DCG (bool is_additive, int index, float value)
204{
205 if (is_additive) {
206 dcg[index].X = value;
207 dcg[index].Y = value;
208 dcg[index].Z = value;
209 dcg[index].W = 0;
210 } else {
211 dcg[index].X = 1.0F;
212 dcg[index].Y = 1.0F;
213 dcg[index].Z = 1.0F;
214 dcg[index].W = value;
215 }
216
217 return ;
218}
219
220// Note: SPHERE_NUM_LOD does not include the NULL LOD.
221#define SPHERE_NUM_LOD (10)
222#define SPHERE_LOWEST_LOD (7)
223#define SPHERE_HIGHEST_LOD (17)
224
225/*
226** SphereRenderObjClass: Procedurally generated render spheres
227**
228*/
230{
231
232public:
233
234 // These are bit masks, so they should enum 1,2,4,8,10,20,40 etc...
236 USE_ALPHA_VECTOR = 0x00000001,
237 USE_CAMERA_ALIGN = 0x00000002,
238 USE_INVERSE_ALPHA = 0x00000004,
240 };
241
247
249 // Render Object Interface
251 virtual RenderObjClass * Clone(void) const;
252 virtual int Class_ID(void) const;
253 virtual void Render(RenderInfoClass & rinfo);
254 virtual void Special_Render(SpecialRenderInfoClass & rinfo);
255 virtual void Set_Transform(const Matrix3D &m);
256 virtual void Set_Position(const Vector3 &v);
257 virtual void Get_Obj_Space_Bounding_Sphere(SphereClass & sphere) const;
258 virtual void Get_Obj_Space_Bounding_Box(AABoxClass & aabox) const;
259
260 virtual void Prepare_LOD(CameraClass &camera);
261 virtual void Increment_LOD(void);
262 virtual void Decrement_LOD(void);
263 virtual float Get_Cost(void) const;
264 virtual float Get_Value(void) const;
265 virtual float Get_Post_Increment_Value(void) const;
266 virtual void Set_LOD_Level(int lod);
267 virtual int Get_LOD_Level(void) const;
268 virtual int Get_LOD_Count(void) const;
269 virtual void Set_LOD_Bias(float bias) { LODBias = MAX(bias, 0.0f); }
270 virtual int Calculate_Cost_Value_Arrays(float screen_area, float *values, float *costs) const;
271
272 virtual void Scale(float scale);
273 virtual void Scale(float scalex, float scaley, float scalez);
274 virtual void Set_Hidden(int onoff) { RenderObjClass::Set_Hidden (onoff); Update_On_Visibilty (); }
275 virtual void Set_Visible(int onoff) { RenderObjClass::Set_Visible (onoff); Update_On_Visibilty (); }
278
279
280 const AABoxClass & Get_Box(void);
281
282 virtual int Get_Num_Polys(void) const;
283 virtual const char * Get_Name(void) const;
284 virtual void Set_Name(const char * name);
285
286 unsigned int Get_Flags(void) { return Flags; }
287 void Set_Flags(unsigned int flags) { Flags = flags; }
288 void Set_Flag(unsigned int flag, bool onoff) { Flags &= (~flag); if (onoff) Flags |= flag; }
289
290 // Animation access
291 bool Is_Animating (void) { return IsAnimating; }
292 void Start_Animating (void) { IsAnimating = true; anim_time = 0; }
293 void Stop_Animating (void) { IsAnimating = false; anim_time = 0; }
294
295 // Current state access
296 void Set_Color(const Vector3 & color) { CurrentColor = color; }
297 void Set_Alpha(float alpha) { CurrentAlpha = alpha; }
300
301 const Vector3 & Get_Color(void) const { return CurrentColor; }
302 float Get_Alpha(void) const { return CurrentAlpha; }
303 const Vector3 & Get_Scale(void) const { return CurrentScale; }
304 const AlphaVectorStruct & Get_Vector(void) const { return CurrentVector; }
305
306 Vector3 Get_Default_Color(void) const;
307 float Get_Default_Alpha(void) const;
308 Vector3 Get_Default_Scale(void) const;
310
311 // Size/position methods
312 void Set_Extent (const Vector3 &extent);
313 void Set_Local_Center_Extent(const Vector3 & center,const Vector3 & extent);
314 void Set_Local_Min_Max(const Vector3 & min,const Vector3 & max);
315
316 // Texture access
317 void Set_Texture(TextureClass *tf);
320 void Set_Shader(ShaderClass &shader) {SphereShader=shader;}
321
322 // Animation control
323 float Get_Animation_Duration (void) const { return AnimDuration; }
324 void Set_Animation_Duration (float time) { AnimDuration = time; Restart_Animation (); }
325 void Restart_Animation (void) { anim_time = 0; }
326
327 // Animatable channel access
330
333
336
339
344
345protected:
346
347 virtual void update_cached_box(void);
348 virtual void Update_Cached_Bounding_Volumes(void) const;
349 void Update_On_Visibilty(void);
350
351 // Initialization stuff
352 void Init_Material (void);
353 static void Generate_Shared_Mesh_Arrays (const AlphaVectorStruct &alphavector);
354
355 // Animation Stuff
356 void animate(void); // animation update function
357 float anim_time; // what time in seconds are we in the animation
360
361 // LOD Stuff
362 void calculate_value_array(float screen_area, float *values) const;
363 float LODBias;
365 float Value[SPHERE_NUM_LOD + 2];// Value array needs # of LODs + 1 (RING_NUM_LOD doesn't include null LOD)
366
371
372 void update_mesh_data(const Vector3 & center,const Vector3 & extent);
373 void render_sphere();
374 void vis_render_sphere(SpecialRenderInfoClass & rinfo,const Vector3 & center,const Vector3 & extent);
375
379
380 // Current State
385
387
388 // Flags
389 unsigned int Flags;
390
394
396
397 // Friend classes
399};
400
401inline void SphereRenderObjClass::Set_Extent (const Vector3 &extent)
402{
403 ObjSpaceExtent = extent;
406}
407
408inline void SphereRenderObjClass::Set_Local_Center_Extent(const Vector3 & center,const Vector3 & extent)
409{
410 ObjSpaceCenter = center;
411 ObjSpaceExtent = extent;
413}
414
416{
417 ObjSpaceCenter = (max + min) / 2.0f;
418 ObjSpaceExtent = (max - min) / 2.0f;
420}
421
422
424{
427 return CachedBox;
428}
429
430/*
431** Loader for spheres
432*/
434{
435public:
436 virtual int Chunk_Type (void) { return W3D_CHUNK_SPHERE; }
437 virtual PrototypeClass * Load_W3D(ChunkLoadClass & cload);
438};
439
440/*
441** Prototype for Sphere objects
442*/
444{
446public:
449
450 virtual const char * Get_Name(void) const;
451 virtual int Get_Class_ID(void) const;
452 virtual RenderObjClass * Create(void);
453 virtual void DeleteSelf() { delete this; }
454
455 bool Load (ChunkLoadClass &cload);
456 bool Save (ChunkSaveClass &csave);
457
458protected:
460
461private:
462 W3dSphereStruct Definition;
463
464 SphereColorChannelClass ColorChannel;
465 SphereAlphaChannelClass AlphaChannel;
466 SphereScaleChannelClass ScaleChannel;
467 SphereVectorChannelClass VectorChannel;
468};
469
470/*
471** Instance of the loader which the asset manager installs
472*/
474
475#endif // SPHEREOBJ_H
476
477// EOF - sphereobj,h
478
479
#define min(x, y)
Definition BaseType.h:101
#define max(x, y)
Definition BaseType.h:105
void const char * value
Color scale(const Color &a, const Color &b)
Definition GameMtl.cpp:722
#define W3D_NAME_LEN
Definition w3d_file.h:319
@ W3D_CHUNK_SPHERE
Definition w3d_file.h:474
#define W3DMPO_GLUE(ARGCLASS)
Definition always.h:120
#define MAX(a, b)
Definition always.h:185
unsigned long uint32
Definition bittype.h:46
@ true
Definition bool.h:59
AlphaVectorStruct Evaluate(float time)
Definition sphereobj.h:76
PrototypeClass(void)
Definition proto.h:90
PrototypeLoaderClass(void)
Definition proto.h:139
float X
Definition quat.h:60
float Z
Definition quat.h:62
float Y
Definition quat.h:61
RenderObjClass(void)
Definition rendobj.cpp:170
virtual void Set_Visible(int onoff)
Definition rendobj.h:465
virtual void Set_Hidden(int onoff)
Definition rendobj.h:472
virtual void Set_Force_Visible(int onoff)
Definition rendobj.h:476
virtual void Validate_Transform(void) const
Definition rendobj.cpp:464
virtual void Set_Animation_Hidden(int onoff)
Definition rendobj.h:474
virtual PrototypeClass * Load_W3D(ChunkLoadClass &cload)
virtual int Chunk_Type(void)
Definition sphereobj.h:436
void Generate(float radius, int slices, int stacks)
int Get_Num_Polys(void)
Definition sphereobj.h:166
friend class SphereRenderObjClass
Definition sphereobj.h:156
void Set_Alpha_Vector(const AlphaVectorStruct &v, bool inverse, bool is_additive, bool force=false)
virtual RenderObjClass * Create(void)
virtual void DeleteSelf()
Definition sphereobj.h:453
virtual int Get_Class_ID(void) const
bool Load(ChunkLoadClass &cload)
bool Save(ChunkSaveClass &csave)
virtual const char * Get_Name(void) const
void Set_Alpha(float alpha)
Definition sphereobj.h:297
SphereRenderObjClass & operator=(const SphereRenderObjClass &)
AABoxClass CachedBox
Definition sphereobj.h:395
virtual void Set_LOD_Bias(float bias)
Definition sphereobj.h:269
void Set_Animation_Duration(float time)
Definition sphereobj.h:324
virtual void Scale(float scale)
virtual void Get_Obj_Space_Bounding_Sphere(SphereClass &sphere) const
virtual void Set_Visible(int onoff)
Definition sphereobj.h:275
TextureClass * SphereTexture
Definition sphereobj.h:393
virtual int Get_Num_Polys(void) const
virtual int Get_LOD_Level(void) const
SphereColorChannelClass & Get_Color_Channel(void)
Definition sphereobj.h:328
virtual int Class_ID(void) const
AlphaVectorStruct Get_Default_Vector(void) const
Vector3 Get_Default_Color(void) const
SphereVectorChannelClass & Get_Vector_Channel(void)
Definition sphereobj.h:337
virtual float Get_Post_Increment_Value(void) const
const SphereVectorChannelClass & Peek_Vector_Channel(void)
Definition sphereobj.h:338
AlphaVectorStruct CurrentVector
Definition sphereobj.h:384
TextureClass * Peek_Texture(void)
Definition sphereobj.h:318
float Value[SPHERE_NUM_LOD+2]
Definition sphereobj.h:365
void Set_Scale(const Vector3 &scale)
Definition sphereobj.h:298
unsigned int Flags
Definition sphereobj.h:389
void Set_Alpha_Channel(const SphereAlphaChannelClass &data)
Definition sphereobj.h:341
void Set_Scale_Channel(const SphereScaleChannelClass &data)
Definition sphereobj.h:342
float Get_Default_Alpha(void) const
virtual void Set_LOD_Level(int lod)
SphereAlphaChannelClass AlphaChannel
Definition sphereobj.h:368
SphereScaleChannelClass ScaleChannel
Definition sphereobj.h:369
void Start_Animating(void)
Definition sphereobj.h:292
friend class SpherePrototypeClass
Definition sphereobj.h:398
virtual const char * Get_Name(void) const
SphereColorChannelClass ColorChannel
Definition sphereobj.h:367
void Set_Vector(const AlphaVectorStruct &v)
Definition sphereobj.h:299
void Set_Vector_Channel(const SphereVectorChannelClass &data)
Definition sphereobj.h:343
static void Generate_Shared_Mesh_Arrays(const AlphaVectorStruct &alphavector)
void Set_Flag(unsigned int flag, bool onoff)
Definition sphereobj.h:288
void Set_Flags(unsigned int flags)
Definition sphereobj.h:287
virtual void Special_Render(SpecialRenderInfoClass &rinfo)
virtual void Render(RenderInfoClass &rinfo)
void update_mesh_data(const Vector3 &center, const Vector3 &extent)
SphereScaleChannelClass & Get_Scale_Channel(void)
Definition sphereobj.h:334
virtual void Update_Cached_Bounding_Volumes(void) const
virtual void Decrement_LOD(void)
bool Is_Animating(void)
Definition sphereobj.h:291
virtual int Get_LOD_Count(void) const
const SphereColorChannelClass & Peek_Color_Channel(void)
Definition sphereobj.h:329
virtual void Set_Hidden(int onoff)
Definition sphereobj.h:274
ShaderClass SphereShader
Definition sphereobj.h:392
SphereAlphaChannelClass & Get_Alpha_Channel(void)
Definition sphereobj.h:331
void Set_Local_Min_Max(const Vector3 &min, const Vector3 &max)
Definition sphereobj.h:415
float Get_Alpha(void) const
Definition sphereobj.h:302
virtual void Get_Obj_Space_Bounding_Box(AABoxClass &aabox) const
void Update_On_Visibilty(void)
virtual void Set_Position(const Vector3 &v)
virtual void Set_Animation_Hidden(int onoff)
Definition sphereobj.h:276
float Get_Animation_Duration(void) const
Definition sphereobj.h:323
virtual void update_cached_box(void)
SphereVectorChannelClass VectorChannel
Definition sphereobj.h:370
void Set_Local_Center_Extent(const Vector3 &center, const Vector3 &extent)
Definition sphereobj.h:408
virtual void Set_Transform(const Matrix3D &m)
char Name[2 *W3D_NAME_LEN]
Definition sphereobj.h:376
void Restart_Animation(void)
Definition sphereobj.h:325
Quaternion Orientation
Definition sphereobj.h:386
const SphereScaleChannelClass & Peek_Scale_Channel(void)
Definition sphereobj.h:335
void calculate_value_array(float screen_area, float *values) const
const SphereAlphaChannelClass & Peek_Alpha_Channel(void)
Definition sphereobj.h:332
VertexMaterialClass * SphereMaterial
Definition sphereobj.h:391
const AlphaVectorStruct & Get_Vector(void) const
Definition sphereobj.h:304
void Set_Texture(TextureClass *tf)
void Set_Shader(ShaderClass &shader)
Definition sphereobj.h:320
ShaderClass & Get_Shader(void)
Definition sphereobj.h:319
virtual int Calculate_Cost_Value_Arrays(float screen_area, float *values, float *costs) const
virtual float Get_Cost(void) const
const Vector3 & Get_Color(void) const
Definition sphereobj.h:301
virtual void Set_Force_Visible(int onoff)
Definition sphereobj.h:277
const Vector3 & Get_Scale(void) const
Definition sphereobj.h:303
void vis_render_sphere(SpecialRenderInfoClass &rinfo, const Vector3 &center, const Vector3 &extent)
unsigned int Get_Flags(void)
Definition sphereobj.h:286
virtual float Get_Value(void) const
void Init_Material(void)
void Set_Color_Channel(const SphereColorChannelClass &data)
Definition sphereobj.h:340
virtual void Increment_LOD(void)
const AABoxClass & Get_Box(void)
Definition sphereobj.h:423
void Stop_Animating(void)
Definition sphereobj.h:293
void Set_Color(const Vector3 &color)
Definition sphereobj.h:296
void Set_Extent(const Vector3 &extent)
Definition sphereobj.h:401
virtual void Prepare_LOD(CameraClass &camera)
virtual RenderObjClass * Clone(void) const
Vector3 Get_Default_Scale(void) const
virtual void Set_Name(const char *name)
Vector3i16 TriIndex
int percent
Definition patch.cpp:426
else return(RetVal)
void __cdecl Fast_Slerp(Quaternion &res, const Quaternion &p, const Quaternion &q, float alpha)
Definition quat.cpp:441
SphereLoaderClass _SphereLoader
LERPAnimationChannelClass< float > SphereAlphaChannelClass
Definition sphereobj.h:146
AlphaVectorChannel SphereVectorChannelClass
Definition sphereobj.h:148
#define SPHERE_NUM_LOD
Definition sphereobj.h:221
LERPAnimationChannelClass< Vector3 > SphereScaleChannelClass
Definition sphereobj.h:147
LERPAnimationChannelClass< Vector3 > SphereColorChannelClass
Definition sphereobj.h:145
Quaternion angle
Definition sphereobj.h:69
AlphaVectorStruct(const AlphaVectorStruct &src)
Definition sphereobj.h:62
bool operator!=(const AlphaVectorStruct &src)
Definition sphereobj.h:65
const AlphaVectorStruct & operator=(const AlphaVectorStruct &src)
Definition sphereobj.h:67
bool operator==(const AlphaVectorStruct &src)
Definition sphereobj.h:64
AlphaVectorStruct(void)
Definition sphereobj.h:59
AlphaVectorStruct DefaultVector
Definition sphereobj.h:133
char Name[2 *W3D_NAME_LEN]
Definition sphereobj.h:123
uint32 Attributes
Definition sphereobj.h:122
W3dVectorStruct DefaultScale
Definition sphereobj.h:132
W3dVectorStruct DefaultColor
Definition sphereobj.h:130
W3dVectorStruct Extent
Definition sphereobj.h:126
W3dShaderStruct Shader
Definition sphereobj.h:136
W3dVectorStruct Center
Definition sphereobj.h:125
char TextureName[2 *W3D_NAME_LEN]
Definition sphereobj.h:135
unsigned char flag
Definition vchannel.cpp:273