Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
motchan.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/* $Header: /Commando/Code/ww3d2/motchan.h 5 11/29/01 1:07p Jani_p $ */
20/***********************************************************************************************
21 *** Confidential - Westwood Studios ***
22 ***********************************************************************************************
23 * *
24 * Project Name : Commando / G 3D Library *
25 * *
26 * $Archive:: /Commando/Code/ww3d2/motchan.h $*
27 * *
28 * $Author:: Jani_p $*
29 * *
30 * $Modtime:: 11/28/01 5:43p $*
31 * *
32 * $Revision:: 5 $*
33 * *
34 *---------------------------------------------------------------------------------------------*
35 * Functions: *
36 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
37
38
39#if defined(_MSC_VER)
40#pragma once
41#endif
42
43#ifndef MOTCHAN_H
44#define MOTCHAN_H
45
46#include "always.h"
47#include "bittype.h"
48#include "w3d_file.h"
49#include "quat.h"
50
51class ChunkLoadClass;
52class Quaternion;
53
54/******************************************************************************
55
56 MotionChannelClass is used to store motion. Motion data
57 is broken into separate channels for X, Y, Z, and orientation.
58 Then if any of the channels are empty, they don't have to be stored.
59 The X,Y,Z channels all contain one-dimensional vectors and the
60 orientation channel contains four-dimensional vectors (quaternions).
61
62******************************************************************************/
63
65{
67
68public:
69 void Do_Data_Compression(int datasize);
70 void Get_Vector(int frame,float * setvec) const;
71
74
75 bool Load_W3D(ChunkLoadClass & cload);
76 WWINLINE int Get_Type(void) const { return Type; }
77 WWINLINE int Get_Pivot(void) const { return PivotIdx; }
78 WWINLINE void Set_Pivot(int idx) { PivotIdx=idx; }
79
80#define SPECIAL_GETVEC_AS_QUAT
81#ifdef SPECIAL_GETVEC_AS_QUAT
82 WWINLINE void Get_Vector_As_Quat(int frame, Quaternion& quat) const;
83#endif
84
85private:
86
87 uint32 PivotIdx; // what pivot is this channel applied to
88 uint32 Type; // what type of channel is this
89 int VectorLen; // size of each individual vector
90
91 float ValueOffset;
92 float ValueScale;
93 unsigned short* CompressedData;
94
95 float * Data; // pointer to the raw floating point data
96 int FirstFrame; // first frame which was non-identity
97 int LastFrame; // last frame which was non-identity
98 void Free(void);
99 WWINLINE void set_identity(float * setvec) const;
100
101// friend class HRawAnimClass;
102
103};
104
105WWINLINE void MotionChannelClass::set_identity(float * setvec) const
106{
107 if (Type == ANIM_CHANNEL_Q) {
108
109 setvec[0] = 0.0f;
110 setvec[1] = 0.0f;
111 setvec[2] = 0.0f;
112 setvec[3] = 1.0f;
113
114 } else {
115
116 setvec[0] = 0.0f;
117
118 }
119}
120
121WWINLINE void MotionChannelClass::Get_Vector(int frame,float * setvec) const
122{
123 if ((frame < FirstFrame) || (frame > LastFrame)) {
124
125 set_identity(setvec);
126
127 } else {
128
129 int vframe = frame - FirstFrame;
130
131 for (int i=0; i<VectorLen; i++) {
132 setvec[i] = Data[vframe * VectorLen + i];
133 }
134 }
135}
136
137#ifdef SPECIAL_GETVEC_AS_QUAT
139{
140 if ((frame < FirstFrame) || (frame > LastFrame)) {
141
142 quat.Set(0.0f, 0.0f, 0.0f, 1.0f);
143
144 } else {
145
146 const float* d = &Data[(frame - FirstFrame) * VectorLen];
147 quat.Set(d[0], d[1], d[2], d[3]);
148
149 }
150}
151#endif
152
153
154/******************************************************************************
155
156 BitChannelClass is used to store a boolean "on/off" value for each frame
157 in an animation.
158
159******************************************************************************/
160
162{
164
165public:
166
167 BitChannelClass(void);
168 ~BitChannelClass(void);
169
170 bool Load_W3D(ChunkLoadClass & cload);
171 WWINLINE int Get_Type(void) const { return Type; }
172 WWINLINE int Get_Pivot(void) const { return PivotIdx; }
173 WWINLINE int Get_Bit(int frame) const;
174
175private:
176
177 uint32 PivotIdx;
178 uint32 Type;
179 int DefaultVal;
180 int FirstFrame;
181 int LastFrame;
182
183 uint8 * Bits;
184
185 void Free(void);
186
187 friend class HRawAnimClass;
188};
189
190
192{
193 if ((frame < FirstFrame) || (frame > LastFrame)) {
194
195 return DefaultVal;
196
197 } else {
198
199 int bit = frame - FirstFrame;
200
201 uint8 mask = (uint8)(1 << (bit % 8));
202 return ((*(Bits + (bit/8)) & mask) != 0);
203
204 }
205}
206
207/******************************************************************************
208
209 TimeCodedMotionChannelClass is used to store motion. Motion data
210 is broken into separate channels for X, Y, Z, and orientation.
211 Then if any of the channels are empty, they don't have to be stored.
212 The X,Y,Z channels all contain one-dimensional vectors and the
213 orientation channel contains four-dimensional vectors (quaternions).
214
215******************************************************************************/
216
218{
220
221public:
222
225
226 bool Load_W3D(ChunkLoadClass & cload);
227 int Get_Type(void) { return Type; }
228 int Get_Pivot(void) { return PivotIdx; }
229 void Get_Vector(float32 frame, float * setvec);
230
232
233private:
234
235 uint32 PivotIdx; // what pivot is this channel applied to
236 uint32 Type; // what type of channel is this
237 int VectorLen; // size of each individual vector
238 uint32 PacketSize; // size of each packet
239
240 uint32 NumTimeCodes; // Number of packets
241
242 uint32 LastTimeCodeIdx; // absolute index to last time code
243 uint32 CachedIdx; // Last Index Used
244
245 uint32 * Data; // pointer to packet data
246
247 void Free(void);
248 void set_identity(float * setvec);
249 uint32 get_index(uint32 timecode);
250 uint32 binary_search_index(uint32 timecode);
251
253};
254
256{
258
259public:
260
263
264 bool Load_W3D(ChunkLoadClass & cload);
265 int Get_Type(void) { return Type; }
266 int Get_Pivot(void) { return PivotIdx; }
267 void Get_Vector(float32 frame, float * setvec);
268
270
271private:
272
273 uint32 PivotIdx; // what pivot is this channel applied to
274 uint32 Type; // what type of channel is this
275 int VectorLen; // size of each individual vector
276
277 uint32 NumFrames; // Number of frames
278
279 float Scale; // Scale Filter, this much
280
281 uint32 *Data; // pointer to packet data
282
283 uint32 CacheFrame;
284 float *CacheData; // the data for CachedFrame, and CachedFrame+1, x VectorLen
285
286 void Free(void);
287
288 float getframe(uint32 frame_idx, uint32 vector_idx=0);
289 void decompress(uint32 frame_idx, float *outdata);
290 void decompress(uint32 src_idx, float *srcdata, uint32 frame_idx, float *outdata);
291
293};
294
295
296
297/******************************************************************************
298
299 TimeCodedBitChannelClass is used to store a boolean "on/off" value for each frame
300 in an animation.
301
302******************************************************************************/
303
305{
307
308public:
309
312
313 bool Load_W3D(ChunkLoadClass & cload);
314 int Get_Type(void) { return Type; }
315 int Get_Pivot(void) { return PivotIdx; }
316 int Get_Bit(int frame);
317
318private:
319
320 uint32 PivotIdx;
321 uint32 Type;
322 int DefaultVal;
323
324 uint32 NumTimeCodes;
325 uint32 CachedIdx;
326
327 uint32 *Bits;
328
329 void Free(void);
330
332};
333
334
335#endif
@ ANIM_CHANNEL_Q
Definition w3d_file.h:1419
#define W3DMPO_GLUE(ARGCLASS)
Definition always.h:120
#define WWINLINE
Definition always.h:172
unsigned long uint32
Definition bittype.h:46
float float32
Definition bittype.h:54
unsigned char uint8
Definition bittype.h:44
void Get_Vector(float32 frame, float *setvec)
Definition motchan.cpp:1226
bool Load_W3D(ChunkLoadClass &cload)
Definition motchan.cpp:940
friend class HCompressedAnimClass
Definition motchan.h:292
Quaternion Get_QuatVector(float32 frame)
Definition motchan.cpp:1245
bool Load_W3D(ChunkLoadClass &cload)
Definition motchan.cpp:273
BitChannelClass(void)
Definition motchan.cpp:211
WWINLINE int Get_Type(void) const
Definition motchan.h:171
WWINLINE int Get_Pivot(void) const
Definition motchan.h:172
friend class HRawAnimClass
Definition motchan.h:187
~BitChannelClass(void)
Definition motchan.cpp:234
WWINLINE int Get_Bit(int frame) const
Definition motchan.h:191
WWINLINE int Get_Type(void) const
Definition motchan.h:76
bool Load_W3D(ChunkLoadClass &cload)
Definition motchan.cpp:161
~MotionChannelClass(void)
Definition motchan.cpp:119
WWINLINE void Get_Vector_As_Quat(int frame, Quaternion &quat) const
Definition motchan.h:138
WWINLINE int Get_Pivot(void) const
Definition motchan.h:77
void Get_Vector(int frame, float *setvec) const
Definition motchan.h:121
WWINLINE void Set_Pivot(int idx)
Definition motchan.h:78
void Do_Data_Compression(int datasize)
Definition motchan.cpp:1276
MotionChannelClass(void)
Definition motchan.cpp:94
WWINLINE void Set(float a=0.0, float b=0.0, float c=0.0, float d=1.0)
Definition quat.h:73
bool Load_W3D(ChunkLoadClass &cload)
Definition motchan.cpp:754
friend class HCompressedAnimClass
Definition motchan.h:331
int Get_Bit(int frame)
Definition motchan.cpp:803
Quaternion Get_QuatVector(float32 frame)
Definition motchan.cpp:482
void Get_Vector(float32 frame, float *setvec)
Definition motchan.cpp:428
friend class HCompressedAnimClass
Definition motchan.h:252
bool Load_W3D(ChunkLoadClass &cload)
Definition motchan.cpp:386