Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
distlod.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/distlod.h $*
26 * *
27 * Author:: Greg Hjelstrom *
28 * *
29 * $Modtime:: 1/25/01 2:46p $*
30 * *
31 * $Revision:: 2 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37
38#if defined(_MSC_VER)
39#pragma once
40#endif
41
42#ifndef DISTLOD_H
43#define DISTLOD_H
44
45#include "proto.h"
46#include "rendobj.h"
47#include "composite.h"
48#include "w3derr.h"
49
50class ChunkLoadClass;
52class DistLODDefClass;
53
54
55/*
56** DistLODClass
57** Distance based LOD switching. This is a simple LOD object which switches models
58** based on the pre-set distances. Note that the models are stored in order of
59** descending resolution; i.e. the highest res model will be in index 0.
60** Most functions in this class simply pass the call on to all of the LODs.
61**
62** When the level of detail is changed, the LOD which was being used must be
63** notified that it is being removed from the scene and the new LOD must be
64** notified that it is being added. This allows us to correctly handle lights
65** and particle emitters in LODs...
66*/
68{
69public:
70
71 DistLODClass(const DistLODDefClass & desc);
72 DistLODClass(const DistLODClass & that);
73 virtual ~DistLODClass(void);
74 virtual RenderObjClass * Clone(void) const { return W3DNEW DistLODClass(*this); }
75 virtual int Class_ID(void) const { return CLASSID_DISTLOD; }
76 virtual int Get_Num_Polys(void) const;
77
79 // Render Object Interface - Rendering
81 virtual void Render(RenderInfoClass & rinfo);
82 virtual void Special_Render(SpecialRenderInfoClass & rinfo);
83
85 // Render Object Interface - "Scene Graph"
86 // Access each LOD individually through Get_Sub_Object.
88 virtual void Set_Transform(const Matrix3D &m);
89 virtual void Set_Position(const Vector3 &v);
90
91 virtual int Get_Num_Sub_Objects(void) const;
92 virtual RenderObjClass * Get_Sub_Object(int index) const;
93
94 virtual int Add_Sub_Object_To_Bone(RenderObjClass * subobj,int bone_index);
95
97 // Render Object Interface - Hierarchical Animation
98 // Here again, these functions are passed on to all LODs. Each LOD is
99 // assumed to use the same HTree (or have no HTree, this is so that LODs are
100 // animation-compatible) so the bone query functions simply pass to the top
101 // LOD.
103 virtual void Set_Animation( void );
104 virtual void Set_Animation( HAnimClass * motion, float frame, int anim_mode = ANIM_MODE_MANUAL);
105 virtual void Set_Animation( HAnimClass * motion0,float frame0,HAnimClass * motion1,float frame1,float percentage);
106 virtual void Set_Animation( HAnimComboClass * anim_combo);
107 virtual HAnimClass * Peek_Animation( void );
108 virtual int Get_Num_Bones(void);
109 virtual const char * Get_Bone_Name(int bone_index);
110 virtual int Get_Bone_Index(const char * bonename);
111 virtual const Matrix3D & Get_Bone_Transform(const char * bonename);
112 virtual const Matrix3D & Get_Bone_Transform(int boneindex);
113 virtual void Capture_Bone(int bindex);
114 virtual void Release_Bone(int bindex);
115 virtual bool Is_Bone_Captured(int bindex) const;
116 virtual void Control_Bone(int bindex,const Matrix3D & tm,bool world_space_translation = false);
117
119 // Render Object Interface - Collision Detection, Ray Tracing
120 // Collision tests are performed on the top-level LOD.
122 virtual bool Cast_Ray(RayCollisionTestClass & raytest);
123 virtual bool Cast_AABox(AABoxCollisionTestClass & boxtest);
124 virtual bool Cast_OBBox(OBBoxCollisionTestClass & boxtest);
125
127 // Render Object Interface - Attributes, Options, Properties, etc
129 virtual int Get_Num_Snap_Points(void);
130 virtual void Get_Snap_Point(int index,Vector3 * set);
131 virtual void Scale(float scale);
132 virtual void Scale(float scalex, float scaley, float scalez);
133
135 // DistLOD Interface
137 virtual float Get_Switch_Up_Dist(int index) const { return Lods[index].ResUpDist; }
138 virtual float Get_Switch_Down_Dist(int index) const { return Lods[index].ResDownDist; }
139 virtual void Set_Switch_Up_Dist(int index, float dist) { Lods[index].ResUpDist = dist; }
140 virtual void Set_Switch_Down_Dist(int index, float dist) { Lods[index].ResDownDist = dist; }
141
142private:
143
144 enum { HIGHEST_LOD = 0 };
145
146 void Free(void);
147 void Update_Lod(const CameraClass & camera);
148 void Increment_Lod(void);
149 void Decrement_Lod(void);
150
151 struct LODNodeClass
152 {
153 RenderObjClass * Model;
154 float ResUpDist;
155 float ResDownDist;
156 };
157
158 int LodCount; // how many models are in this LOD object
159 int CurLod; // which model is currently used for rendering
160 int VpPushLod; // which model was used for the vp->push (in CurLod changes before the pop)
161 LODNodeClass * Lods; // one LODNodeClass for each level
162};
163
164
165/*
166** Loaders for DistLODClass
167*/
169{
170public:
171
172 virtual int Chunk_Type (void) { return W3D_CHUNK_LODMODEL; }
173 virtual PrototypeClass * Load_W3D(ChunkLoadClass & cload);
174};
175
176/*
177** DistLODModelDefStruct
178** Describes a single model in a Distance-Based LOD Object
179*/
181{
183
184 char * Name;
187};
188
189/*
190** DistLODDefClass
191** Description of a Distance-Based LOD Object. These are similar
192** to the HModelDef's that are used by the asset manager to construct
193** HModels.
194*/
196{
197public:
198
199 DistLODDefClass(void);
200 DistLODDefClass(const char * name,int lodcount,DistLODNodeDefStruct * lods);
201 ~DistLODDefClass(void);
202
204 const char * Get_Name(void) const { return Name; }
205
206private:
207
208 char * Name;
209
210 int LodCount;
212
213 void Free(void);
214 bool read_header(ChunkLoadClass & cload);
215 bool read_node(ChunkLoadClass & cload,DistLODNodeDefStruct * node);
216
217 friend class DistLODClass;
218};
219
220/*
221** Prototype for Dist-LOD objects
222*/
224{
226public:
227 DistLODPrototypeClass( DistLODDefClass *def ) { Definition = def; }
228
229 virtual const char * Get_Name(void) const { return Definition->Get_Name(); }
230 virtual int Get_Class_ID(void) const { return RenderObjClass::CLASSID_DISTLOD; }
231 virtual RenderObjClass * Create(void);
232 virtual void DeleteSelf() { delete this; }
233
234protected:
235 virtual ~DistLODPrototypeClass(void) { delete Definition; }
236
237private:
238 DistLODDefClass * Definition;
239};
240
241/*
242** Instance of the loaders which the asset manager install
243*/
245
246#endif
#define NULL
Definition BaseType.h:92
Color scale(const Color &a, const Color &b)
Definition GameMtl.cpp:722
@ W3D_CHUNK_LODMODEL
Definition w3d_file.h:426
#define W3DMPO_GLUE(ARGCLASS)
Definition always.h:120
#define W3DNEW
Definition always.h:109
virtual int Get_Bone_Index(const char *bonename)
Definition distlod.cpp:811
virtual void Set_Switch_Down_Dist(int index, float dist)
Definition distlod.h:140
virtual const char * Get_Bone_Name(int bone_index)
Definition distlod.cpp:793
virtual int Get_Num_Polys(void) const
Definition distlod.cpp:506
virtual void Capture_Bone(int bindex)
Definition distlod.cpp:868
virtual void Render(RenderInfoClass &rinfo)
Definition distlod.cpp:524
virtual bool Is_Bone_Captured(int bindex) const
Definition distlod.cpp:910
virtual void Control_Bone(int bindex, const Matrix3D &tm, bool world_space_translation=false)
Definition distlod.cpp:929
virtual RenderObjClass * Get_Sub_Object(int index) const
Definition distlod.cpp:584
virtual void Set_Switch_Up_Dist(int index, float dist)
Definition distlod.h:139
virtual ~DistLODClass(void)
Definition distlod.cpp:457
virtual float Get_Switch_Down_Dist(int index) const
Definition distlod.h:138
virtual bool Cast_AABox(AABoxCollisionTestClass &boxtest)
Definition distlod.cpp:975
virtual int Class_ID(void) const
Definition distlod.h:75
DistLODClass(const DistLODDefClass &desc)
Definition distlod.cpp:389
virtual void Get_Snap_Point(int index, Vector3 *set)
Definition distlod.cpp:1037
virtual HAnimClass * Peek_Animation(void)
Definition distlod.cpp:757
virtual float Get_Switch_Up_Dist(int index) const
Definition distlod.h:137
virtual void Set_Transform(const Matrix3D &m)
Definition distlod.cpp:627
virtual int Get_Num_Snap_Points(void)
Definition distlod.cpp:1019
virtual bool Cast_Ray(RayCollisionTestClass &raytest)
Definition distlod.cpp:951
virtual int Get_Num_Bones(void)
Definition distlod.cpp:775
virtual const Matrix3D & Get_Bone_Transform(const char *bonename)
Definition distlod.cpp:830
virtual int Get_Num_Sub_Objects(void) const
Definition distlod.cpp:566
virtual void Set_Position(const Vector3 &v)
Definition distlod.cpp:651
virtual int Add_Sub_Object_To_Bone(RenderObjClass *subobj, int bone_index)
Definition distlod.cpp:597
virtual bool Cast_OBBox(OBBoxCollisionTestClass &boxtest)
Definition distlod.cpp:997
virtual void Special_Render(SpecialRenderInfoClass &rinfo)
Definition distlod.cpp:547
virtual void Scale(float scale)
Definition distlod.cpp:1055
virtual RenderObjClass * Clone(void) const
Definition distlod.h:74
virtual void Set_Animation(void)
Definition distlod.cpp:673
virtual void Release_Bone(int bindex)
Definition distlod.cpp:889
const char * Get_Name(void) const
Definition distlod.h:204
DistLODDefClass(void)
Definition distlod.cpp:170
~DistLODDefClass(void)
Definition distlod.cpp:224
WW3DErrorType Load_W3D(ChunkLoadClass &cload)
Definition distlod.cpp:273
friend class DistLODClass
Definition distlod.h:217
virtual int Chunk_Type(void)
Definition distlod.h:172
virtual PrototypeClass * Load_W3D(ChunkLoadClass &cload)
Definition distlod.cpp:133
virtual int Get_Class_ID(void) const
Definition distlod.h:230
DistLODPrototypeClass(DistLODDefClass *def)
Definition distlod.h:227
virtual void DeleteSelf()
Definition distlod.h:232
virtual RenderObjClass * Create(void)
Definition distlod.cpp:99
virtual const char * Get_Name(void) const
Definition distlod.h:229
virtual ~DistLODPrototypeClass(void)
Definition distlod.h:235
PrototypeClass(void)
Definition proto.h:90
PrototypeLoaderClass(void)
Definition proto.h:139
RenderObjClass(void)
Definition rendobj.cpp:170
DistLODLoaderClass _DistLODLoader
Definition distlod.cpp:96
DistLODNodeDefStruct(void)
Definition distlod.h:182
WW3DErrorType
Definition w3derr.h:51