1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "C_PortalGhostRenderable.h"
#include "PortalRender.h"
#include "c_portal_player.h"
#include "model_types.h"
C_PortalGhostRenderable::C_PortalGhostRenderable( C_Prop_Portal *pOwningPortal, C_BaseEntity *pGhostSource, RenderGroup_t sourceRenderGroup, const VMatrix &matGhostTransform, float *pSharedRenderClipPlane, bool bLocalPlayer )
: m_pGhostedRenderable( pGhostSource ),
m_matGhostTransform( matGhostTransform ),
m_pSharedRenderClipPlane( pSharedRenderClipPlane ),
m_bLocalPlayer( bLocalPlayer ),
m_pOwningPortal( pOwningPortal )
{
m_bSourceIsBaseAnimating = (dynamic_cast<C_BaseAnimating *>(pGhostSource) != NULL);
cl_entitylist->AddNonNetworkableEntity( GetIClientUnknown() );
g_pClientLeafSystem->AddRenderable( this, sourceRenderGroup );
}
C_PortalGhostRenderable::~C_PortalGhostRenderable( void )
{
m_pGhostedRenderable = NULL;
g_pClientLeafSystem->RemoveRenderable( RenderHandle() );
cl_entitylist->RemoveEntity( GetIClientUnknown()->GetRefEHandle() );
DestroyModelInstance();
}
void C_PortalGhostRenderable::PerFrameUpdate( void )
{
if( m_pGhostedRenderable )
{
SetModelName( m_pGhostedRenderable->GetModelName() );
SetModelIndex( m_pGhostedRenderable->GetModelIndex() );
SetEffects( m_pGhostedRenderable->GetEffects() | EF_NOINTERP );
m_flAnimTime = m_pGhostedRenderable->m_flAnimTime;
if( m_bSourceIsBaseAnimating )
{
C_BaseAnimating *pSource = (C_BaseAnimating *)m_pGhostedRenderable;
SetCycle( pSource->GetCycle() );
SetSequence( pSource->GetSequence() );
m_nBody = pSource->m_nBody;
m_nSkin = pSource->m_nSkin;
}
}
// Set position and angles relative to the object it's ghosting
Vector ptNewOrigin = m_matGhostTransform * m_pGhostedRenderable->GetAbsOrigin();
QAngle qNewAngles = TransformAnglesToWorldSpace( m_pGhostedRenderable->GetAbsAngles(), m_matGhostTransform.As3x4() );
SetAbsOrigin( ptNewOrigin );
SetAbsAngles( qNewAngles );
AddEffects( EF_NOINTERP );
RemoveFromInterpolationList();
g_pClientLeafSystem->RenderableChanged( RenderHandle() );
}
Vector const& C_PortalGhostRenderable::GetRenderOrigin( void )
{
if( m_pGhostedRenderable == NULL )
return m_ReferencedReturns.vRenderOrigin;
m_ReferencedReturns.vRenderOrigin = m_matGhostTransform * m_pGhostedRenderable->GetRenderOrigin();
return m_ReferencedReturns.vRenderOrigin;
}
QAngle const& C_PortalGhostRenderable::GetRenderAngles( void )
{
if( m_pGhostedRenderable == NULL )
return m_ReferencedReturns.qRenderAngle;
m_ReferencedReturns.qRenderAngle = TransformAnglesToWorldSpace( m_pGhostedRenderable->GetRenderAngles(), m_matGhostTransform.As3x4() );
return m_ReferencedReturns.qRenderAngle;
}
bool C_PortalGhostRenderable::SetupBones( matrix3x4_t *pBoneToWorldOut, int nMaxBones, int boneMask, float currentTime )
{
if( m_pGhostedRenderable == NULL )
return false;
int nModelIndex = 0;
CBaseCombatWeapon *pParent = dynamic_cast<CBaseCombatWeapon*>( m_pGhostedRenderable );
if ( pParent )
{
nModelIndex = pParent->GetModelIndex();
pParent->SetModelIndex( pParent->GetWorldModelIndex() );
}
if( m_pGhostedRenderable->SetupBones( pBoneToWorldOut, nMaxBones, boneMask, currentTime ) )
{
if( pBoneToWorldOut )
{
for( int i = 0; i != nMaxBones; ++i ) //FIXME: nMaxBones is most definitely greater than the actual number of bone transforms actually used, find the subset somehow
{
pBoneToWorldOut[i] = (m_matGhostTransform * pBoneToWorldOut[i]).As3x4();
}
}
return true;
}
if ( pParent )
{
pParent->SetModelIndex( nModelIndex );
}
return false;
}
void C_PortalGhostRenderable::GetRenderBounds( Vector& mins, Vector& maxs )
{
if( m_pGhostedRenderable == NULL )
{
mins = maxs = vec3_origin;
return;
}
m_pGhostedRenderable->GetRenderBounds( mins, maxs );
}
void C_PortalGhostRenderable::GetRenderBoundsWorldspace( Vector& mins, Vector& maxs )
{
if( m_pGhostedRenderable == NULL )
{
mins = maxs = vec3_origin;
return;
}
m_pGhostedRenderable->GetRenderBoundsWorldspace( mins, maxs );
TransformAABB( m_matGhostTransform.As3x4(), mins, maxs, mins, maxs );
}
void C_PortalGhostRenderable::GetShadowRenderBounds( Vector &mins, Vector &maxs, ShadowType_t shadowType )
{
m_pGhostedRenderable->GetShadowRenderBounds( mins, maxs, shadowType );
TransformAABB( m_matGhostTransform.As3x4(), mins, maxs, mins, maxs );
}
/*bool C_PortalGhostRenderable::GetShadowCastDistance( float *pDist, ShadowType_t shadowType ) const
{
if( m_pGhostedRenderable == NULL )
return false;
return m_pGhostedRenderable->GetShadowCastDistance( pDist, shadowType );
}
bool C_PortalGhostRenderable::GetShadowCastDirection( Vector *pDirection, ShadowType_t shadowType ) const
{
if( m_pGhostedRenderable == NULL )
return false;
if( m_pGhostedRenderable->GetShadowCastDirection( pDirection, shadowType ) )
{
if( pDirection )
*pDirection = m_matGhostTransform.ApplyRotation( *pDirection );
return true;
}
return false;
}*/
const matrix3x4_t & C_PortalGhostRenderable::RenderableToWorldTransform()
{
if( m_pGhostedRenderable == NULL )
return m_ReferencedReturns.matRenderableToWorldTransform;
ConcatTransforms( m_matGhostTransform.As3x4(), m_pGhostedRenderable->RenderableToWorldTransform(), m_ReferencedReturns.matRenderableToWorldTransform );
return m_ReferencedReturns.matRenderableToWorldTransform;
}
bool C_PortalGhostRenderable::GetAttachment( int number, Vector &origin, QAngle &angles )
{
if( m_pGhostedRenderable == NULL )
return false;
if( m_pGhostedRenderable->GetAttachment( number, origin, angles ) )
{
origin = m_matGhostTransform * origin;
angles = TransformAnglesToWorldSpace( angles, m_matGhostTransform.As3x4() );
return true;
}
return false;
}
bool C_PortalGhostRenderable::GetAttachment( int number, matrix3x4_t &matrix )
{
if( m_pGhostedRenderable == NULL )
return false;
if( m_pGhostedRenderable->GetAttachment( number, matrix ) )
{
ConcatTransforms( m_matGhostTransform.As3x4(), matrix, matrix );
return true;
}
return false;
}
bool C_PortalGhostRenderable::GetAttachment( int number, Vector &origin )
{
if( m_pGhostedRenderable == NULL )
return false;
if( m_pGhostedRenderable->GetAttachment( number, origin ) )
{
origin = m_matGhostTransform * origin;
return true;
}
return false;
}
bool C_PortalGhostRenderable::GetAttachmentVelocity( int number, Vector &originVel, Quaternion &angleVel )
{
if( m_pGhostedRenderable == NULL )
return false;
Vector ghostVel;
if( m_pGhostedRenderable->GetAttachmentVelocity( number, ghostVel, angleVel ) )
{
Vector3DMultiply( m_matGhostTransform, ghostVel, originVel );
Vector3DMultiply( m_matGhostTransform, *(Vector*)( &angleVel ), *(Vector*)( &angleVel ) );
return true;
}
return false;
}
int C_PortalGhostRenderable::DrawModel( int flags )
{
if( m_bSourceIsBaseAnimating )
{
if( m_bLocalPlayer )
{
C_Portal_Player *pPlayer = C_Portal_Player::GetLocalPlayer();
if ( !pPlayer->IsAlive() )
{
// Dead player uses a ragdoll to draw, so don't ghost the dead entity
return 0;
}
else if( g_pPortalRender->GetViewRecursionLevel() == 0 )
{
if( pPlayer->m_bEyePositionIsTransformedByPortal )
return 0;
}
else if( g_pPortalRender->GetViewRecursionLevel() == 1 )
{
if( !pPlayer->m_bEyePositionIsTransformedByPortal )
return 0;
}
}
return C_BaseAnimating::DrawModel( flags );
}
else
{
DrawBrushModelMode_t mode = DBM_DRAW_ALL;
if ( flags & STUDIO_TWOPASS )
{
mode = ( flags & STUDIO_TRANSPARENCY ) ? DBM_DRAW_TRANSLUCENT_ONLY : DBM_DRAW_OPAQUE_ONLY;
}
render->DrawBrushModelEx( m_pGhostedRenderable,
(model_t *)m_pGhostedRenderable->GetModel(),
GetRenderOrigin(),
GetRenderAngles(),
mode );
return 1;
}
return 0;
}
ModelInstanceHandle_t C_PortalGhostRenderable::GetModelInstance()
{
if ( m_pGhostedRenderable )
return m_pGhostedRenderable->GetModelInstance();
return BaseClass::GetModelInstance();
}
bool C_PortalGhostRenderable::IsTransparent( void )
{
if( m_pGhostedRenderable == NULL )
return false;
return m_pGhostedRenderable->IsTransparent();
}
bool C_PortalGhostRenderable::UsesPowerOfTwoFrameBufferTexture()
{
if( m_pGhostedRenderable == NULL )
return false;
return m_pGhostedRenderable->UsesPowerOfTwoFrameBufferTexture();
}
/*const model_t* C_PortalGhostRenderable::GetModel( ) const
{
if( m_pGhostedRenderable == NULL )
return NULL;
return m_pGhostedRenderable->GetModel();
}
int C_PortalGhostRenderable::GetBody()
{
if( m_pGhostedRenderable == NULL )
return 0;
return m_pGhostedRenderable->GetBody();
}*/
void C_PortalGhostRenderable::GetColorModulation( float* color )
{
if( m_pGhostedRenderable == NULL )
return;
return m_pGhostedRenderable->GetColorModulation( color );
}
/*ShadowType_t C_PortalGhostRenderable::ShadowCastType()
{
if( m_pGhostedRenderable == NULL )
return SHADOWS_NONE;
return m_pGhostedRenderable->ShadowCastType();
}*/
int C_PortalGhostRenderable::LookupAttachment( const char *pAttachmentName )
{
if( m_pGhostedRenderable == NULL )
return -1;
return m_pGhostedRenderable->LookupAttachment( pAttachmentName );
}
/*int C_PortalGhostRenderable::GetSkin()
{
if( m_pGhostedRenderable == NULL )
return -1;
return m_pGhostedRenderable->GetSkin();
}
bool C_PortalGhostRenderable::IsTwoPass( void )
{
if( m_pGhostedRenderable == NULL )
return false;
return m_pGhostedRenderable->IsTwoPass();
}*/
|