2018-01-19 18:00:32 +01:00
|
|
|
//========= Copyright (c) 1996-2002, Valve LLC, All rights reserved. ============
|
2016-06-04 15:24:23 +02:00
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
//
|
|
|
|
// $NoKeywords: $
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
// studio_model.cpp
|
|
|
|
// routines for setting up to draw 3DStudio models
|
|
|
|
|
|
|
|
#include "hud.h"
|
|
|
|
#include "cl_util.h"
|
|
|
|
#include "const.h"
|
|
|
|
#include "com_model.h"
|
|
|
|
#include "studio.h"
|
|
|
|
#include "entity_state.h"
|
|
|
|
#include "cl_entity.h"
|
|
|
|
#include "dlight.h"
|
|
|
|
#include "triangleapi.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "studio_util.h"
|
|
|
|
#include "r_studioint.h"
|
|
|
|
|
|
|
|
#include "StudioModelRenderer.h"
|
|
|
|
#include "GameStudioModelRenderer.h"
|
|
|
|
|
|
|
|
// Global engine <-> studio model rendering code interface
|
|
|
|
engine_studio_api_t IEngineStudio;
|
|
|
|
|
|
|
|
/////////////////////
|
|
|
|
// Implementation of CStudioModelRenderer.h
|
|
|
|
#define LEGS_BONES_COUNT 8
|
|
|
|
|
|
|
|
// enumerate all the bones that used for gait animation
|
|
|
|
const char *legs_bones[] =
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
"Bip01",
|
|
|
|
"Bip01 Pelvis",
|
|
|
|
"Bip01 L Leg",
|
|
|
|
"Bip01 L Leg1",
|
|
|
|
"Bip01 L Foot",
|
|
|
|
"Bip01 R Leg",
|
|
|
|
"Bip01 R Leg1",
|
|
|
|
"Bip01 R Foot"
|
2016-06-04 15:24:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
Init
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
void CStudioModelRenderer::Init( void )
|
|
|
|
{
|
|
|
|
// Set up some variables shared with engine
|
|
|
|
m_pCvarHiModels = IEngineStudio.GetCvar( "cl_himodels" );
|
|
|
|
m_pCvarDeveloper = IEngineStudio.GetCvar( "developer" );
|
|
|
|
m_pCvarDrawEntities = IEngineStudio.GetCvar( "r_drawentities" );
|
|
|
|
|
|
|
|
m_pChromeSprite = IEngineStudio.GetChromeSprite();
|
|
|
|
|
|
|
|
IEngineStudio.GetModelCounters( &m_pStudioModelCount, &m_pModelsDrawn );
|
|
|
|
|
|
|
|
// Get pointers to engine data structures
|
|
|
|
m_pbonetransform = (float (*)[MAXSTUDIOBONES][3][4])IEngineStudio.StudioGetBoneTransform();
|
|
|
|
m_plighttransform = (float (*)[MAXSTUDIOBONES][3][4])IEngineStudio.StudioGetLightTransform();
|
|
|
|
m_paliastransform = (float (*)[3][4])IEngineStudio.StudioGetAliasTransform();
|
|
|
|
m_protationmatrix = (float (*)[3][4])IEngineStudio.StudioGetRotationMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
CStudioModelRenderer
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
CStudioModelRenderer::CStudioModelRenderer( void )
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
m_fDoInterp = 1;
|
2016-06-04 15:24:23 +02:00
|
|
|
m_fGaitEstimation = 1;
|
|
|
|
m_pCurrentEntity = NULL;
|
|
|
|
m_pCvarHiModels = NULL;
|
|
|
|
m_pCvarDeveloper = NULL;
|
|
|
|
m_pCvarDrawEntities = NULL;
|
|
|
|
m_pChromeSprite = NULL;
|
|
|
|
m_pStudioModelCount = NULL;
|
|
|
|
m_pModelsDrawn = NULL;
|
|
|
|
m_protationmatrix = NULL;
|
|
|
|
m_paliastransform = NULL;
|
|
|
|
m_pbonetransform = NULL;
|
|
|
|
m_plighttransform = NULL;
|
|
|
|
m_pStudioHeader = NULL;
|
2016-08-01 13:13:13 +02:00
|
|
|
m_pBodyPart = NULL;
|
|
|
|
m_pSubModel = NULL;
|
2016-06-04 15:24:23 +02:00
|
|
|
m_pPlayerInfo = NULL;
|
|
|
|
m_pRenderModel = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
~CStudioModelRenderer
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
CStudioModelRenderer::~CStudioModelRenderer( void )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioCalcBoneAdj
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
void CStudioModelRenderer::StudioCalcBoneAdj( float dadt, float *adj, const byte *pcontroller1, const byte *pcontroller2, byte mouthopen )
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
int i, j;
|
|
|
|
float value;
|
2016-06-04 15:24:23 +02:00
|
|
|
mstudiobonecontroller_t *pbonecontroller;
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
pbonecontroller = (mstudiobonecontroller_t *)( (byte *)m_pStudioHeader + m_pStudioHeader->bonecontrollerindex );
|
|
|
|
|
|
|
|
for( j = 0; j < m_pStudioHeader->numbonecontrollers; j++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
i = pbonecontroller[j].index;
|
2016-08-01 13:13:13 +02:00
|
|
|
if( i <= 3 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// check for 360% wrapping
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pbonecontroller[j].type & STUDIO_RLOOP )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
if( abs( pcontroller1[i] - pcontroller2[i] ) > 128)
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
int a, b;
|
2016-08-01 13:13:13 +02:00
|
|
|
a = ( pcontroller1[j] + 128 ) % 256;
|
|
|
|
b = ( pcontroller2[j] + 128 ) % 256;
|
2019-10-13 13:49:25 +02:00
|
|
|
value = ( ( a * dadt ) + ( b * ( 1.0f - dadt ) ) - 128.0f ) * ( 360.0f / 256.0f ) + pbonecontroller[j].start;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
else
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
value = ( ( pcontroller1[i] * dadt + ( pcontroller2[i] ) * ( 1.0f - dadt ) ) ) * ( 360.0f / 256.0f ) + pbonecontroller[j].start;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
else
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
value = ( pcontroller1[i] * dadt + pcontroller2[i] * ( 1.0f - dadt ) ) / 255.0f;
|
|
|
|
if( value < 0.0f ) value = 0.0f;
|
|
|
|
if( value > 1.0f ) value = 1.0f;
|
|
|
|
value = ( 1.0f - value ) * pbonecontroller[j].start + value * pbonecontroller[j].end;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
// Con_DPrintf( "%d %d %f : %f\n", m_pCurrentEntity->curstate.controller[j], m_pCurrentEntity->latched.prevcontroller[j], value, dadt );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
value = mouthopen / 64.0f;
|
|
|
|
if( value > 1.0f ) value = 1.0f;
|
|
|
|
value = ( 1.0f - value ) * pbonecontroller[j].start + value * pbonecontroller[j].end;
|
2016-08-01 13:13:13 +02:00
|
|
|
// Con_DPrintf( "%d %f\n", mouthopen, value );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
switch( pbonecontroller[j].type & STUDIO_TYPES )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
case STUDIO_XR:
|
|
|
|
case STUDIO_YR:
|
|
|
|
case STUDIO_ZR:
|
2019-10-13 13:49:25 +02:00
|
|
|
adj[j] = value * ( M_PI_F / 180.0f );
|
2016-06-04 15:24:23 +02:00
|
|
|
break;
|
|
|
|
case STUDIO_X:
|
|
|
|
case STUDIO_Y:
|
|
|
|
case STUDIO_Z:
|
|
|
|
adj[j] = value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioCalcBoneQuaterion
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
void CStudioModelRenderer::StudioCalcBoneQuaterion( int frame, float s, mstudiobone_t *pbone, mstudioanim_t *panim, float *adj, float *q )
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
int j, k;
|
|
|
|
vec4_t q1, q2;
|
|
|
|
vec3_t angle1, angle2;
|
|
|
|
mstudioanimvalue_t *panimvalue;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
for( j = 0; j < 3; j++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
if( panim->offset[j + 3] == 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
angle2[j] = angle1[j] = pbone->value[ j + 3]; // default;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
panimvalue = (mstudioanimvalue_t *)( (byte *)panim + panim->offset[j + 3] );
|
2016-06-04 15:24:23 +02:00
|
|
|
k = frame;
|
|
|
|
// DEBUG
|
2016-08-01 13:13:13 +02:00
|
|
|
if( panimvalue->num.total < panimvalue->num.valid )
|
2016-06-04 15:24:23 +02:00
|
|
|
k = 0;
|
2016-08-01 13:13:13 +02:00
|
|
|
while( panimvalue->num.total <= k )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
k -= panimvalue->num.total;
|
|
|
|
panimvalue += panimvalue->num.valid + 1;
|
|
|
|
// DEBUG
|
2016-08-01 13:13:13 +02:00
|
|
|
if( panimvalue->num.total < panimvalue->num.valid )
|
2016-06-04 15:24:23 +02:00
|
|
|
k = 0;
|
|
|
|
}
|
|
|
|
// Bah, missing blend!
|
2016-08-01 13:13:13 +02:00
|
|
|
if( panimvalue->num.valid > k )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
angle1[j] = panimvalue[k + 1].value;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( panimvalue->num.valid > k + 1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
angle2[j] = panimvalue[k + 2].value;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
if( panimvalue->num.total > k + 1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
angle2[j] = angle1[j];
|
|
|
|
else
|
2016-08-01 13:13:13 +02:00
|
|
|
angle2[j] = panimvalue[panimvalue->num.valid + 2].value;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
angle1[j] = panimvalue[panimvalue->num.valid].value;
|
2016-08-01 13:13:13 +02:00
|
|
|
if( panimvalue->num.total > k + 1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
angle2[j] = angle1[j];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
angle2[j] = panimvalue[panimvalue->num.valid + 2].value;
|
|
|
|
}
|
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
angle1[j] = pbone->value[j+3] + angle1[j] * pbone->scale[j + 3];
|
|
|
|
angle2[j] = pbone->value[j+3] + angle2[j] * pbone->scale[j + 3];
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pbone->bonecontroller[j + 3] != -1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
angle1[j] += adj[pbone->bonecontroller[j + 3]];
|
|
|
|
angle2[j] += adj[pbone->bonecontroller[j + 3]];
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( !VectorCompare( angle1, angle2 ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
AngleQuaternion( angle1, q1 );
|
|
|
|
AngleQuaternion( angle2, q2 );
|
|
|
|
QuaternionSlerp( q1, q2, s, q );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AngleQuaternion( angle1, q );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioCalcBonePosition
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
void CStudioModelRenderer::StudioCalcBonePosition( int frame, float s, mstudiobone_t *pbone, mstudioanim_t *panim, float *adj, float *pos )
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
int j, k;
|
|
|
|
mstudioanimvalue_t *panimvalue;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
for( j = 0; j < 3; j++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pos[j] = pbone->value[j]; // default;
|
2016-08-01 13:13:13 +02:00
|
|
|
if( panim->offset[j] != 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
panimvalue = (mstudioanimvalue_t *)( (byte *)panim + panim->offset[j] );
|
2016-06-04 15:24:23 +02:00
|
|
|
/*
|
2016-08-01 13:13:13 +02:00
|
|
|
if( i == 0 && j == 0 )
|
|
|
|
Con_DPrintf( "%d %d:%d %f\n", frame, panimvalue->num.valid, panimvalue->num.total, s );
|
2016-06-04 15:24:23 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
k = frame;
|
|
|
|
// DEBUG
|
2016-08-01 13:13:13 +02:00
|
|
|
if( panimvalue->num.total < panimvalue->num.valid )
|
2016-06-04 15:24:23 +02:00
|
|
|
k = 0;
|
|
|
|
// find span of values that includes the frame we want
|
2016-08-01 13:13:13 +02:00
|
|
|
while( panimvalue->num.total <= k )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
k -= panimvalue->num.total;
|
|
|
|
panimvalue += panimvalue->num.valid + 1;
|
|
|
|
// DEBUG
|
2016-08-01 13:13:13 +02:00
|
|
|
if( panimvalue->num.total < panimvalue->num.valid )
|
2016-06-04 15:24:23 +02:00
|
|
|
k = 0;
|
|
|
|
}
|
|
|
|
// if we're inside the span
|
2016-08-01 13:13:13 +02:00
|
|
|
if( panimvalue->num.valid > k )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// and there's more data in the span
|
2016-08-01 13:13:13 +02:00
|
|
|
if( panimvalue->num.valid > k + 1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
pos[j] += ( panimvalue[k + 1].value * ( 1.0f - s ) + s * panimvalue[k + 2].value ) * pbone->scale[j];
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
pos[j] += panimvalue[k + 1].value * pbone->scale[j];
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// are we at the end of the repeating values section and there's another section with data?
|
2016-08-01 13:13:13 +02:00
|
|
|
if( panimvalue->num.total <= k + 1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
pos[j] += ( panimvalue[panimvalue->num.valid].value * ( 1.0f - s ) + s * panimvalue[panimvalue->num.valid + 2].value ) * pbone->scale[j];
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos[j] += panimvalue[panimvalue->num.valid].value * pbone->scale[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pbone->bonecontroller[j] != -1 && adj )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pos[j] += adj[pbone->bonecontroller[j]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioSlerpBones
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
void CStudioModelRenderer::StudioSlerpBones( vec4_t q1[], float pos1[][3], vec4_t q2[], float pos2[][3], float s )
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
int i;
|
|
|
|
vec4_t q3;
|
|
|
|
float s1;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
if( s < 0.0f )
|
|
|
|
s = 0.0f;
|
|
|
|
else if( s > 1.0f )
|
|
|
|
s = 1.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
s1 = 1.0f - s;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
for( i = 0; i < m_pStudioHeader->numbones; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
QuaternionSlerp( q1[i], q2[i], s, q3 );
|
|
|
|
q1[i][0] = q3[0];
|
|
|
|
q1[i][1] = q3[1];
|
|
|
|
q1[i][2] = q3[2];
|
|
|
|
q1[i][3] = q3[3];
|
|
|
|
pos1[i][0] = pos1[i][0] * s1 + pos2[i][0] * s;
|
|
|
|
pos1[i][1] = pos1[i][1] * s1 + pos2[i][1] * s;
|
|
|
|
pos1[i][2] = pos1[i][2] * s1 + pos2[i][2] * s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioGetAnim
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
mstudioanim_t *CStudioModelRenderer::StudioGetAnim( model_t *m_pSubModel, mstudioseqdesc_t *pseqdesc )
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
mstudioseqgroup_t *pseqgroup;
|
2016-06-04 15:24:23 +02:00
|
|
|
cache_user_t *paSequences;
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
pseqgroup = (mstudioseqgroup_t *)( (byte *)m_pStudioHeader + m_pStudioHeader->seqgroupindex ) + pseqdesc->seqgroup;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pseqdesc->seqgroup == 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
return (mstudioanim_t *)( (byte *)m_pStudioHeader + pseqdesc->animindex );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
paSequences = (cache_user_t *)m_pSubModel->submodels;
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( paSequences == NULL )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
paSequences = (cache_user_t *)IEngineStudio.Mem_Calloc( 16, sizeof(cache_user_t) ); // UNDONE: leak!
|
2016-06-04 15:24:23 +02:00
|
|
|
m_pSubModel->submodels = (dmodel_t *)paSequences;
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( !IEngineStudio.Cache_Check( (struct cache_user_s *)&( paSequences[pseqdesc->seqgroup] ) ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
gEngfuncs.Con_DPrintf("loading %s\n", pseqgroup->name );
|
|
|
|
IEngineStudio.LoadCacheFile( pseqgroup->name, (struct cache_user_s *)&paSequences[pseqdesc->seqgroup] );
|
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
return (mstudioanim_t *)( (byte *)paSequences[pseqdesc->seqgroup].data + pseqdesc->animindex );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioPlayerBlend
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
void CStudioModelRenderer::StudioPlayerBlend( mstudioseqdesc_t *pseqdesc, int *pBlend, float *pPitch )
|
|
|
|
{
|
|
|
|
// calc up/down pointing
|
2016-08-01 13:13:13 +02:00
|
|
|
*pBlend = ( *pPitch * 3 );
|
|
|
|
if( *pBlend < pseqdesc->blendstart[0] )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
*pPitch -= pseqdesc->blendstart[0] / 3.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
*pBlend = 0;
|
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
else if( *pBlend > pseqdesc->blendend[0] )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
*pPitch -= pseqdesc->blendend[0] / 3.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
*pBlend = 255;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
if( pseqdesc->blendend[0] - pseqdesc->blendstart[0] < 0.1f ) // catch qc error
|
2016-06-04 15:24:23 +02:00
|
|
|
*pBlend = 127;
|
|
|
|
else
|
2016-08-01 13:13:13 +02:00
|
|
|
*pBlend = 255 * ( *pBlend - pseqdesc->blendstart[0] ) / ( pseqdesc->blendend[0] - pseqdesc->blendstart[0] );
|
2016-06-04 15:24:23 +02:00
|
|
|
*pPitch = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioSetUpTransform
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
2016-08-01 13:13:13 +02:00
|
|
|
void CStudioModelRenderer::StudioSetUpTransform( int trivial_accept )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
int i;
|
|
|
|
vec3_t angles;
|
|
|
|
vec3_t modelpos;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
// tweek model origin
|
|
|
|
//for( i = 0; i < 3; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
// modelpos[i] = m_pCurrentEntity->origin[i];
|
|
|
|
|
|
|
|
VectorCopy( m_pCurrentEntity->origin, modelpos );
|
|
|
|
|
|
|
|
// TODO: should really be stored with the entity instead of being reconstructed
|
|
|
|
// TODO: should use a look-up table
|
|
|
|
// TODO: could cache lazily, stored in the entity
|
|
|
|
angles[ROLL] = m_pCurrentEntity->curstate.angles[ROLL];
|
|
|
|
angles[PITCH] = m_pCurrentEntity->curstate.angles[PITCH];
|
|
|
|
angles[YAW] = m_pCurrentEntity->curstate.angles[YAW];
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
//Con_DPrintf( "Angles %4.2f prev %4.2f for %i\n", angles[PITCH], m_pCurrentEntity->index );
|
|
|
|
//Con_DPrintf( "movetype %d %d\n", m_pCurrentEntity->movetype, m_pCurrentEntity->aiment );
|
|
|
|
if( m_pCurrentEntity->curstate.movetype == MOVETYPE_STEP )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
float f = 0;
|
|
|
|
float d;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// don't do it if the goalstarttime hasn't updated in a while.
|
|
|
|
|
|
|
|
// NOTE: Because we need to interpolate multiplayer characters, the interpolation time limit
|
|
|
|
// was increased to 1.0 s., which is 2x the max lag we are accounting for.
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( ( m_clTime < m_pCurrentEntity->curstate.animtime + 1.0f ) &&
|
|
|
|
( m_pCurrentEntity->curstate.animtime != m_pCurrentEntity->latched.prevanimtime ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
f = ( m_clTime - m_pCurrentEntity->curstate.animtime ) / ( m_pCurrentEntity->curstate.animtime - m_pCurrentEntity->latched.prevanimtime );
|
|
|
|
//Con_DPrintf( "%4.2f %.2f %.2f\n", f, m_pCurrentEntity->curstate.animtime, m_clTime );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_fDoInterp )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// ugly hack to interpolate angle, position. current is reached 0.1 seconds after being set
|
2019-10-13 13:49:25 +02:00
|
|
|
f = f - 1.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
f = 0.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
for( i = 0; i < 3; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
modelpos[i] += ( m_pCurrentEntity->origin[i] - m_pCurrentEntity->latched.prevorigin[i] ) * f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: Because multiplayer lag can be relatively large, we don't want to cap
|
|
|
|
// f at 1.5 anymore.
|
2019-10-13 13:49:25 +02:00
|
|
|
//if( f > -1.0f && f < 1.5f ) {}
|
2016-08-01 13:13:13 +02:00
|
|
|
//Con_DPrintf( "%.0f %.0f\n",m_pCurrentEntity->msg_angles[0][YAW], m_pCurrentEntity->msg_angles[1][YAW] );
|
|
|
|
for( i = 0; i < 3; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
float ang1, ang2;
|
|
|
|
|
|
|
|
ang1 = m_pCurrentEntity->angles[i];
|
|
|
|
ang2 = m_pCurrentEntity->latched.prevangles[i];
|
|
|
|
|
|
|
|
d = ang1 - ang2;
|
2019-10-13 13:49:25 +02:00
|
|
|
if( d > 180.0f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
d -= 360.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
2019-10-13 13:49:25 +02:00
|
|
|
else if( d < -180.0f )
|
2016-08-01 13:13:13 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
d += 360.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
angles[i] += d * f;
|
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
//Con_DPrintf( "%.3f \n", f );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
else if( m_pCurrentEntity->curstate.movetype != MOVETYPE_NONE )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
VectorCopy( m_pCurrentEntity->angles, angles );
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
//Con_DPrintf( "%.0f %0.f %0.f\n", modelpos[0], modelpos[1], modelpos[2] );
|
|
|
|
//Con_DPrintf( "%.0f %0.f %0.f\n", angles[0], angles[1], angles[2] );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
angles[PITCH] = -angles[PITCH];
|
2016-08-01 13:13:13 +02:00
|
|
|
AngleMatrix( angles, ( *m_protationmatrix ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( !IEngineStudio.IsHardware() )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
static float viewmatrix[3][4];
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
VectorCopy( m_vRight, viewmatrix[0] );
|
|
|
|
VectorCopy( m_vUp, viewmatrix[1] );
|
|
|
|
VectorInverse( viewmatrix[1] );
|
|
|
|
VectorCopy( m_vNormal, viewmatrix[2] );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
(*m_protationmatrix)[0][3] = modelpos[0] - m_vRenderOrigin[0];
|
|
|
|
(*m_protationmatrix)[1][3] = modelpos[1] - m_vRenderOrigin[1];
|
|
|
|
(*m_protationmatrix)[2][3] = modelpos[2] - m_vRenderOrigin[2];
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
ConcatTransforms( viewmatrix, (*m_protationmatrix), (*m_paliastransform) );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// do the scaling up of x and y to screen coordinates as part of the transform
|
|
|
|
// for the unclipped case (it would mess up clipping in the clipped case).
|
|
|
|
// Also scale down z, so 1/z is scaled 31 bits for free, and scale down x and y
|
|
|
|
// correspondingly so the projected x and y come out right
|
|
|
|
// FIXME: make this work for clipped case too?
|
2016-08-01 13:13:13 +02:00
|
|
|
if( trivial_accept )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
for( i = 0; i < 4; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
(*m_paliastransform)[0][i] *= m_fSoftwareXScale * ( 1.0f / ( ZISCALE * 0x10000 ) );
|
|
|
|
(*m_paliastransform)[1][i] *= m_fSoftwareYScale * ( 1.0f / ( ZISCALE * 0x10000 ) );
|
|
|
|
(*m_paliastransform)[2][i] *= 1.0f / ( ZISCALE * 0x10000 );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(*m_protationmatrix)[0][3] = modelpos[0];
|
|
|
|
(*m_protationmatrix)[1][3] = modelpos[1];
|
|
|
|
(*m_protationmatrix)[2][3] = modelpos[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioEstimateInterpolant
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
float CStudioModelRenderer::StudioEstimateInterpolant( void )
|
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
float dadt = 1.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
if( m_fDoInterp && ( m_pCurrentEntity->curstate.animtime >= m_pCurrentEntity->latched.prevanimtime + 0.01f ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
dadt = ( m_clTime - m_pCurrentEntity->curstate.animtime ) / 0.1f;
|
|
|
|
if( dadt > 2.0f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
dadt = 2.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return dadt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioCalcRotations
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
2016-08-01 13:13:13 +02:00
|
|
|
void CStudioModelRenderer::StudioCalcRotations( float pos[][3], vec4_t *q, mstudioseqdesc_t *pseqdesc, mstudioanim_t *panim, float f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
int i;
|
|
|
|
int frame;
|
|
|
|
mstudiobone_t *pbone;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
float s;
|
|
|
|
float adj[MAXSTUDIOCONTROLLERS];
|
|
|
|
float dadt;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( f > pseqdesc->numframes - 1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
f = 0.0f; // bah, fix this bug with changing sequences too fast
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
// BUG ( somewhere else ) but this code should validate this data.
|
|
|
|
// This could cause a crash if the frame # is negative, so we'll go ahead
|
|
|
|
// and clamp it here
|
2019-10-13 13:49:25 +02:00
|
|
|
else if( f < -0.01f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
f = -0.01f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
frame = (int)f;
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
// Con_DPrintf( "%d %.4f %.4f %.4f %.4f %d\n", m_pCurrentEntity->curstate.sequence, m_clTime, m_pCurrentEntity->animtime, m_pCurrentEntity->frame, f, frame );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Con_DPrintf( "%f %f %f\n", m_pCurrentEntity->angles[ROLL], m_pCurrentEntity->angles[PITCH], m_pCurrentEntity->angles[YAW] );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
// Con_DPrintf( "frame %d %d\n", frame1, frame2 );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
dadt = StudioEstimateInterpolant();
|
|
|
|
s = ( f - frame );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// add in programtic controllers
|
2016-08-01 13:13:13 +02:00
|
|
|
pbone = (mstudiobone_t *)( (byte *)m_pStudioHeader + m_pStudioHeader->boneindex );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
StudioCalcBoneAdj( dadt, adj, m_pCurrentEntity->curstate.controller, m_pCurrentEntity->latched.prevcontroller, m_pCurrentEntity->mouth.mouthopen );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
for( i = 0; i < m_pStudioHeader->numbones; i++, pbone++, panim++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
StudioCalcBoneQuaterion( frame, s, pbone, panim, adj, q[i] );
|
|
|
|
|
|
|
|
StudioCalcBonePosition( frame, s, pbone, panim, adj, pos[i] );
|
2016-08-01 13:13:13 +02:00
|
|
|
// if( 0 && i == 0 )
|
|
|
|
// Con_DPrintf( "%d %d %d %d\n", m_pCurrentEntity->curstate.sequence, frame, j, k );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pseqdesc->motiontype & STUDIO_X )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
pos[pseqdesc->motionbone][0] = 0.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pseqdesc->motiontype & STUDIO_Y )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
pos[pseqdesc->motionbone][1] = 0.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pseqdesc->motiontype & STUDIO_Z )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
pos[pseqdesc->motionbone][2] = 0.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
s = 0 * ( ( 1.0f - ( f - (int)( f ) ) ) / ( pseqdesc->numframes ) ) * m_pCurrentEntity->curstate.framerate;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pseqdesc->motiontype & STUDIO_LX )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pos[pseqdesc->motionbone][0] += s * pseqdesc->linearmovement[0];
|
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pseqdesc->motiontype & STUDIO_LY )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pos[pseqdesc->motionbone][1] += s * pseqdesc->linearmovement[1];
|
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pseqdesc->motiontype & STUDIO_LZ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pos[pseqdesc->motionbone][2] += s * pseqdesc->linearmovement[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
Studio_FxTransform
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
void CStudioModelRenderer::StudioFxTransform( cl_entity_t *ent, float transform[3][4] )
|
|
|
|
{
|
|
|
|
switch( ent->curstate.renderfx )
|
|
|
|
{
|
|
|
|
case kRenderFxDistort:
|
|
|
|
case kRenderFxHologram:
|
2016-08-01 13:13:13 +02:00
|
|
|
if( gEngfuncs.pfnRandomLong( 0, 49 ) == 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
int axis = gEngfuncs.pfnRandomLong( 0, 1 );
|
|
|
|
if( axis == 1 ) // Choose between x & z
|
2016-06-04 15:24:23 +02:00
|
|
|
axis = 2;
|
2019-10-13 13:49:25 +02:00
|
|
|
VectorScale( transform[axis], gEngfuncs.pfnRandomFloat( 1.0f, 1.484f ), transform[axis] );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
else if( gEngfuncs.pfnRandomLong( 0, 49 ) == 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
float offset;
|
2019-11-16 09:54:30 +01:00
|
|
|
/*int axis = gEngfuncs.pfnRandomLong(0,1);
|
2016-08-01 13:13:13 +02:00
|
|
|
if( axis == 1 ) // Choose between x & z
|
2019-11-16 09:54:30 +01:00
|
|
|
axis = 2;*/
|
2019-10-13 13:49:25 +02:00
|
|
|
offset = gEngfuncs.pfnRandomFloat( -10.0f, 10.0f );
|
2016-08-01 13:13:13 +02:00
|
|
|
transform[gEngfuncs.pfnRandomLong( 0, 2 )][3] += offset;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kRenderFxExplode:
|
|
|
|
{
|
|
|
|
float scale;
|
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
scale = 1.0f + ( m_clTime - ent->curstate.animtime ) * 10.0f;
|
2016-08-01 13:13:13 +02:00
|
|
|
if( scale > 2 ) // Don't blow up more than 200%
|
2016-06-04 15:24:23 +02:00
|
|
|
scale = 2;
|
|
|
|
transform[0][1] *= scale;
|
|
|
|
transform[1][1] *= scale;
|
|
|
|
transform[2][1] *= scale;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioEstimateFrame
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
float CStudioModelRenderer::StudioEstimateFrame( mstudioseqdesc_t *pseqdesc )
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
double dfdt, f;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_fDoInterp )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_clTime < m_pCurrentEntity->curstate.animtime )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
dfdt = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
dfdt = ( m_clTime - m_pCurrentEntity->curstate.animtime ) * m_pCurrentEntity->curstate.framerate * pseqdesc->fps;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dfdt = 0;
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pseqdesc->numframes <= 1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
f = 0.0;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
f = ( m_pCurrentEntity->curstate.frame * ( pseqdesc->numframes - 1 ) ) / 256.0;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
f += dfdt;
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pseqdesc->flags & STUDIO_LOOPING )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pseqdesc->numframes > 1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
f -= (int)( f / ( pseqdesc->numframes - 1 ) ) * ( pseqdesc->numframes - 1 );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
if( f < 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
f += ( pseqdesc->numframes - 1 );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
if( f >= pseqdesc->numframes - 1.001 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
f = pseqdesc->numframes - 1.001;
|
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
if( f < 0.0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
f = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioSetupBones
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
2016-08-01 13:13:13 +02:00
|
|
|
void CStudioModelRenderer::StudioSetupBones( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
int i, j;
|
|
|
|
double f;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
mstudiobone_t *pbones;
|
|
|
|
mstudioseqdesc_t *pseqdesc;
|
|
|
|
mstudioanim_t *panim;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
static float pos[MAXSTUDIOBONES][3];
|
|
|
|
static vec4_t q[MAXSTUDIOBONES];
|
|
|
|
float bonematrix[3][4];
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
static float pos2[MAXSTUDIOBONES][3];
|
|
|
|
static vec4_t q2[MAXSTUDIOBONES];
|
|
|
|
static float pos3[MAXSTUDIOBONES][3];
|
|
|
|
static vec4_t q3[MAXSTUDIOBONES];
|
|
|
|
static float pos4[MAXSTUDIOBONES][3];
|
|
|
|
static vec4_t q4[MAXSTUDIOBONES];
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pCurrentEntity->curstate.sequence >= m_pStudioHeader->numseq )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_pCurrentEntity->curstate.sequence = 0;
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
pseqdesc = (mstudioseqdesc_t *)( (byte *)m_pStudioHeader + m_pStudioHeader->seqindex ) + m_pCurrentEntity->curstate.sequence;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
f = StudioEstimateFrame( pseqdesc );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pCurrentEntity->latched.prevframe > f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
//Con_DPrintf( "%f %f\n", m_pCurrentEntity->prevframe, f );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
panim = StudioGetAnim( m_pRenderModel, pseqdesc );
|
|
|
|
StudioCalcRotations( pos, q, pseqdesc, panim, f );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pseqdesc->numblends > 1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
float s;
|
|
|
|
float dadt;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
panim += m_pStudioHeader->numbones;
|
|
|
|
StudioCalcRotations( pos2, q2, pseqdesc, panim, f );
|
|
|
|
|
|
|
|
dadt = StudioEstimateInterpolant();
|
2016-08-01 13:13:13 +02:00
|
|
|
s = ( m_pCurrentEntity->curstate.blending[0] * dadt + m_pCurrentEntity->latched.prevblending[0] * ( 1.0 - dadt ) ) / 255.0;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
StudioSlerpBones( q, pos, q2, pos2, s );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pseqdesc->numblends == 4 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
panim += m_pStudioHeader->numbones;
|
|
|
|
StudioCalcRotations( pos3, q3, pseqdesc, panim, f );
|
|
|
|
|
|
|
|
panim += m_pStudioHeader->numbones;
|
|
|
|
StudioCalcRotations( pos4, q4, pseqdesc, panim, f );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
s = ( m_pCurrentEntity->curstate.blending[0] * dadt + m_pCurrentEntity->latched.prevblending[0] * ( 1.0 - dadt ) ) / 255.0;
|
2016-06-04 15:24:23 +02:00
|
|
|
StudioSlerpBones( q3, pos3, q4, pos4, s );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
s = ( m_pCurrentEntity->curstate.blending[1] * dadt + m_pCurrentEntity->latched.prevblending[1] * ( 1.0 - dadt ) ) / 255.0;
|
2016-06-04 15:24:23 +02:00
|
|
|
StudioSlerpBones( q, pos, q3, pos3, s );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_fDoInterp && m_pCurrentEntity->latched.sequencetime &&
|
2016-06-04 15:24:23 +02:00
|
|
|
( m_pCurrentEntity->latched.sequencetime + 0.2 > m_clTime ) &&
|
2016-08-01 13:13:13 +02:00
|
|
|
( m_pCurrentEntity->latched.prevsequence < m_pStudioHeader->numseq ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// blend from last sequence
|
2016-08-01 13:13:13 +02:00
|
|
|
static float pos1b[MAXSTUDIOBONES][3];
|
|
|
|
static vec4_t q1b[MAXSTUDIOBONES];
|
|
|
|
float s;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
pseqdesc = (mstudioseqdesc_t *)( (byte *)m_pStudioHeader + m_pStudioHeader->seqindex ) + m_pCurrentEntity->latched.prevsequence;
|
2016-06-04 15:24:23 +02:00
|
|
|
panim = StudioGetAnim( m_pRenderModel, pseqdesc );
|
|
|
|
// clip prevframe
|
|
|
|
StudioCalcRotations( pos1b, q1b, pseqdesc, panim, m_pCurrentEntity->latched.prevframe );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pseqdesc->numblends > 1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
panim += m_pStudioHeader->numbones;
|
|
|
|
StudioCalcRotations( pos2, q2, pseqdesc, panim, m_pCurrentEntity->latched.prevframe );
|
|
|
|
|
|
|
|
s = (m_pCurrentEntity->latched.prevseqblending[0]) / 255.0;
|
|
|
|
StudioSlerpBones( q1b, pos1b, q2, pos2, s );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pseqdesc->numblends == 4 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
panim += m_pStudioHeader->numbones;
|
|
|
|
StudioCalcRotations( pos3, q3, pseqdesc, panim, m_pCurrentEntity->latched.prevframe );
|
|
|
|
|
|
|
|
panim += m_pStudioHeader->numbones;
|
|
|
|
StudioCalcRotations( pos4, q4, pseqdesc, panim, m_pCurrentEntity->latched.prevframe );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
s = ( m_pCurrentEntity->latched.prevseqblending[0] ) / 255.0;
|
2016-06-04 15:24:23 +02:00
|
|
|
StudioSlerpBones( q3, pos3, q4, pos4, s );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
s = ( m_pCurrentEntity->latched.prevseqblending[1] ) / 255.0;
|
2016-06-04 15:24:23 +02:00
|
|
|
StudioSlerpBones( q1b, pos1b, q3, pos3, s );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
s = 1.0 - ( m_clTime - m_pCurrentEntity->latched.sequencetime ) / 0.2;
|
2016-06-04 15:24:23 +02:00
|
|
|
StudioSlerpBones( q, pos, q1b, pos1b, s );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Con_DPrintf("prevframe = %4.2f\n", f);
|
|
|
|
m_pCurrentEntity->latched.prevframe = f;
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
pbones = (mstudiobone_t *)( (byte *)m_pStudioHeader + m_pStudioHeader->boneindex );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// calc gait animation
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pPlayerInfo && m_pPlayerInfo->gaitsequence != 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pPlayerInfo->gaitsequence >= m_pStudioHeader->numseq )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_pPlayerInfo->gaitsequence = 0;
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
pseqdesc = (mstudioseqdesc_t *)( (byte *)m_pStudioHeader + m_pStudioHeader->seqindex ) + m_pPlayerInfo->gaitsequence;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
panim = StudioGetAnim( m_pRenderModel, pseqdesc );
|
|
|
|
StudioCalcRotations( pos2, q2, pseqdesc, panim, m_pPlayerInfo->gaitframe );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
for( i = 0; i < m_pStudioHeader->numbones; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
for( j = 0; j < LEGS_BONES_COUNT; j++ )
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
if( !strcmp( pbones[i].name, legs_bones[j] ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( j == LEGS_BONES_COUNT )
|
|
|
|
continue; // not used for legs
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
memcpy( pos[i], pos2[i], sizeof(pos[i]) );
|
|
|
|
memcpy( q[i], q2[i], sizeof(q[i]) );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
for( i = 0; i < m_pStudioHeader->numbones; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
QuaternionMatrix( q[i], bonematrix );
|
|
|
|
|
|
|
|
bonematrix[0][3] = pos[i][0];
|
|
|
|
bonematrix[1][3] = pos[i][1];
|
|
|
|
bonematrix[2][3] = pos[i][2];
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pbones[i].parent == -1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
if( IEngineStudio.IsHardware() )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
ConcatTransforms( (*m_protationmatrix), bonematrix, (*m_pbonetransform)[i] );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// MatrixCopy should be faster...
|
2016-08-01 13:13:13 +02:00
|
|
|
//ConcatTransforms( (*m_protationmatrix), bonematrix, (*m_plighttransform)[i] );
|
2016-06-04 15:24:23 +02:00
|
|
|
MatrixCopy( (*m_pbonetransform)[i], (*m_plighttransform)[i] );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
ConcatTransforms( (*m_paliastransform), bonematrix, (*m_pbonetransform)[i] );
|
|
|
|
ConcatTransforms( (*m_protationmatrix), bonematrix, (*m_plighttransform)[i] );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Apply client-side effects to the transformation matrix
|
|
|
|
StudioFxTransform( m_pCurrentEntity, (*m_pbonetransform)[i] );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
ConcatTransforms( (*m_pbonetransform)[pbones[i].parent], bonematrix, (*m_pbonetransform)[i] );
|
|
|
|
ConcatTransforms( (*m_plighttransform)[pbones[i].parent], bonematrix, (*m_plighttransform)[i] );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioSaveBones
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
void CStudioModelRenderer::StudioSaveBones( void )
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
int i;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
mstudiobone_t *pbones;
|
|
|
|
pbones = (mstudiobone_t *)( (byte *)m_pStudioHeader + m_pStudioHeader->boneindex );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
m_nCachedBones = m_pStudioHeader->numbones;
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
for( i = 0; i < m_pStudioHeader->numbones; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
strcpy( m_nCachedBoneNames[i], pbones[i].name );
|
|
|
|
MatrixCopy( (*m_pbonetransform)[i], m_rgCachedBoneTransform[i] );
|
|
|
|
MatrixCopy( (*m_plighttransform)[i], m_rgCachedLightTransform[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioMergeBones
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
2016-08-01 13:13:13 +02:00
|
|
|
void CStudioModelRenderer::StudioMergeBones( model_t *m_pSubModel )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
int i, j;
|
|
|
|
double f;
|
|
|
|
int do_hunt = true;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
mstudiobone_t *pbones;
|
|
|
|
mstudioseqdesc_t *pseqdesc;
|
|
|
|
mstudioanim_t *panim;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
static float pos[MAXSTUDIOBONES][3];
|
|
|
|
float bonematrix[3][4];
|
|
|
|
static vec4_t q[MAXSTUDIOBONES];
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pCurrentEntity->curstate.sequence >= m_pStudioHeader->numseq )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_pCurrentEntity->curstate.sequence = 0;
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
pseqdesc = (mstudioseqdesc_t *)( (byte *)m_pStudioHeader + m_pStudioHeader->seqindex ) + m_pCurrentEntity->curstate.sequence;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
f = StudioEstimateFrame( pseqdesc );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pCurrentEntity->latched.prevframe > f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
//Con_DPrintf( "%f %f\n", m_pCurrentEntity->prevframe, f );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
panim = StudioGetAnim( m_pSubModel, pseqdesc );
|
|
|
|
StudioCalcRotations( pos, q, pseqdesc, panim, f );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
pbones = (mstudiobone_t *)( (byte *)m_pStudioHeader + m_pStudioHeader->boneindex );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
for( i = 0; i < m_pStudioHeader->numbones; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
for( j = 0; j < m_nCachedBones; j++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
if( stricmp( pbones[i].name, m_nCachedBoneNames[j] ) == 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
MatrixCopy( m_rgCachedBoneTransform[j], (*m_pbonetransform)[i] );
|
|
|
|
MatrixCopy( m_rgCachedLightTransform[j], (*m_plighttransform)[i] );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
if( j >= m_nCachedBones )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
QuaternionMatrix( q[i], bonematrix );
|
|
|
|
|
|
|
|
bonematrix[0][3] = pos[i][0];
|
|
|
|
bonematrix[1][3] = pos[i][1];
|
|
|
|
bonematrix[2][3] = pos[i][2];
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pbones[i].parent == -1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
if( IEngineStudio.IsHardware() )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
ConcatTransforms( (*m_protationmatrix), bonematrix, (*m_pbonetransform)[i] );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// MatrixCopy should be faster...
|
2016-08-01 13:13:13 +02:00
|
|
|
//ConcatTransforms( (*m_protationmatrix), bonematrix, (*m_plighttransform)[i] );
|
2016-06-04 15:24:23 +02:00
|
|
|
MatrixCopy( (*m_pbonetransform)[i], (*m_plighttransform)[i] );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
ConcatTransforms( (*m_paliastransform), bonematrix, (*m_pbonetransform)[i] );
|
|
|
|
ConcatTransforms( (*m_protationmatrix), bonematrix, (*m_plighttransform)[i] );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Apply client-side effects to the transformation matrix
|
|
|
|
StudioFxTransform( m_pCurrentEntity, (*m_pbonetransform)[i] );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
ConcatTransforms( (*m_pbonetransform)[pbones[i].parent], bonematrix, (*m_pbonetransform)[i] );
|
|
|
|
ConcatTransforms( (*m_plighttransform)[pbones[i].parent], bonematrix, (*m_plighttransform)[i] );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioDrawModel
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
int CStudioModelRenderer::StudioDrawModel( int flags )
|
|
|
|
{
|
|
|
|
alight_t lighting;
|
|
|
|
vec3_t dir;
|
|
|
|
|
|
|
|
m_pCurrentEntity = IEngineStudio.GetCurrentEntity();
|
|
|
|
IEngineStudio.GetTimes( &m_nFrameCount, &m_clTime, &m_clOldTime );
|
|
|
|
IEngineStudio.GetViewInfo( m_vRenderOrigin, m_vUp, m_vRight, m_vNormal );
|
|
|
|
IEngineStudio.GetAliasScale( &m_fSoftwareXScale, &m_fSoftwareYScale );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pCurrentEntity->curstate.renderfx == kRenderFxDeadPlayer )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
entity_state_t deadplayer;
|
|
|
|
|
|
|
|
int result;
|
|
|
|
int save_interp;
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pCurrentEntity->curstate.renderamt <= 0 || m_pCurrentEntity->curstate.renderamt > gEngfuncs.GetMaxClients() )
|
2016-06-04 15:24:23 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
// get copy of player
|
2016-08-01 13:13:13 +02:00
|
|
|
deadplayer = *( IEngineStudio.GetPlayerState( m_pCurrentEntity->curstate.renderamt - 1 ) ); //cl.frames[cl.parsecount & CL_UPDATE_MASK].playerstate[m_pCurrentEntity->curstate.renderamt - 1];
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// clear weapon, movement state
|
|
|
|
deadplayer.number = m_pCurrentEntity->curstate.renderamt;
|
|
|
|
deadplayer.weaponmodel = 0;
|
|
|
|
deadplayer.gaitsequence = 0;
|
|
|
|
|
|
|
|
deadplayer.movetype = MOVETYPE_NONE;
|
|
|
|
VectorCopy( m_pCurrentEntity->curstate.angles, deadplayer.angles );
|
|
|
|
VectorCopy( m_pCurrentEntity->curstate.origin, deadplayer.origin );
|
|
|
|
|
|
|
|
save_interp = m_fDoInterp;
|
|
|
|
m_fDoInterp = 0;
|
|
|
|
|
|
|
|
// draw as though it were a player
|
|
|
|
result = StudioDrawPlayer( flags, &deadplayer );
|
|
|
|
|
|
|
|
m_fDoInterp = save_interp;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pRenderModel = m_pCurrentEntity->model;
|
2016-08-01 13:13:13 +02:00
|
|
|
m_pStudioHeader = (studiohdr_t *)IEngineStudio.Mod_Extradata( m_pRenderModel );
|
2016-06-04 15:24:23 +02:00
|
|
|
IEngineStudio.StudioSetHeader( m_pStudioHeader );
|
|
|
|
IEngineStudio.SetRenderModel( m_pRenderModel );
|
|
|
|
|
|
|
|
StudioSetUpTransform( 0 );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( flags & STUDIO_RENDER )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// see if the bounding box lets us trivially reject, also sets
|
2016-08-01 13:13:13 +02:00
|
|
|
if( !IEngineStudio.StudioCheckBBox() )
|
2016-06-04 15:24:23 +02:00
|
|
|
return 0;
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
( *m_pModelsDrawn )++;
|
|
|
|
( *m_pStudioModelCount )++; // render data cache cookie
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pStudioHeader->numbodyparts == 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pCurrentEntity->curstate.movetype == MOVETYPE_FOLLOW )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
StudioMergeBones( m_pRenderModel );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
StudioSetupBones();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
StudioSaveBones();
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( flags & STUDIO_EVENTS )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
StudioCalcAttachments();
|
|
|
|
IEngineStudio.StudioClientEvents();
|
2016-06-04 15:24:23 +02:00
|
|
|
// copy attachments into global entity array
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pCurrentEntity->index > 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
cl_entity_t *ent = gEngfuncs.GetEntityByIndex( m_pCurrentEntity->index );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
memcpy( ent->attachment, m_pCurrentEntity->attachment, sizeof(vec3_t) * 4 );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( flags & STUDIO_RENDER )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
lighting.plightvec = dir;
|
2016-08-01 13:13:13 +02:00
|
|
|
IEngineStudio.StudioDynamicLight( m_pCurrentEntity, &lighting );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
IEngineStudio.StudioEntityLight( &lighting );
|
|
|
|
|
|
|
|
// model and frame independant
|
2016-08-01 13:13:13 +02:00
|
|
|
IEngineStudio.StudioSetupLighting( &lighting );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// get remap colors
|
|
|
|
m_nTopColor = m_pCurrentEntity->curstate.colormap & 0xFF;
|
2016-08-01 13:13:13 +02:00
|
|
|
m_nBottomColor = ( m_pCurrentEntity->curstate.colormap & 0xFF00 ) >> 8;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
IEngineStudio.StudioSetRemapColors( m_nTopColor, m_nBottomColor );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
StudioRenderModel();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioEstimateGait
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
void CStudioModelRenderer::StudioEstimateGait( entity_state_t *pplayer )
|
|
|
|
{
|
|
|
|
float dt;
|
|
|
|
vec3_t est_velocity;
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
dt = ( m_clTime - m_clOldTime );
|
2019-10-13 13:49:25 +02:00
|
|
|
if( dt < 0.0f )
|
|
|
|
dt = 0.0f;
|
|
|
|
else if( dt > 1.0f )
|
|
|
|
dt = 1.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( dt == 0 || m_pPlayerInfo->renderframe == m_nFrameCount )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_flGaitMovement = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// VectorAdd( pplayer->velocity, pplayer->prediction_error, est_velocity );
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_fGaitEstimation )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
VectorSubtract( m_pCurrentEntity->origin, m_pPlayerInfo->prevgaitorigin, est_velocity );
|
|
|
|
VectorCopy( m_pCurrentEntity->origin, m_pPlayerInfo->prevgaitorigin );
|
|
|
|
m_flGaitMovement = Length( est_velocity );
|
2016-08-01 13:13:13 +02:00
|
|
|
if( dt <= 0 || m_flGaitMovement / dt < 5 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_flGaitMovement = 0;
|
|
|
|
est_velocity[0] = 0;
|
|
|
|
est_velocity[1] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VectorCopy( pplayer->velocity, est_velocity );
|
|
|
|
m_flGaitMovement = Length( est_velocity ) * dt;
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( est_velocity[1] == 0 && est_velocity[0] == 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
float flYawDiff = m_pCurrentEntity->angles[YAW] - m_pPlayerInfo->gaityaw;
|
2019-10-13 13:49:25 +02:00
|
|
|
flYawDiff = flYawDiff - (int)( flYawDiff / 360.0f ) * 360.0f;
|
|
|
|
if( flYawDiff > 180.0f )
|
|
|
|
flYawDiff -= 360.0f;
|
|
|
|
if( flYawDiff < -180.0f )
|
|
|
|
flYawDiff += 360.0f;
|
|
|
|
|
|
|
|
if( dt < 0.25f )
|
|
|
|
flYawDiff *= dt * 4.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
else
|
|
|
|
flYawDiff *= dt;
|
|
|
|
|
|
|
|
m_pPlayerInfo->gaityaw += flYawDiff;
|
2019-10-13 13:49:25 +02:00
|
|
|
m_pPlayerInfo->gaityaw = m_pPlayerInfo->gaityaw - (int)( m_pPlayerInfo->gaityaw / 360.0f ) * 360.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
m_flGaitMovement = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
m_pPlayerInfo->gaityaw = ( atan2( est_velocity[1], est_velocity[0] ) * 180.0f / M_PI_F );
|
|
|
|
if( m_pPlayerInfo->gaityaw > 180.0f )
|
|
|
|
m_pPlayerInfo->gaityaw = 180.0f;
|
|
|
|
if( m_pPlayerInfo->gaityaw < -180.0f )
|
|
|
|
m_pPlayerInfo->gaityaw = -180.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioProcessGait
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
void CStudioModelRenderer::StudioProcessGait( entity_state_t *pplayer )
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
mstudioseqdesc_t *pseqdesc;
|
2016-06-04 15:24:23 +02:00
|
|
|
float dt;
|
|
|
|
int iBlend;
|
|
|
|
float flYaw; // view direction relative to movement
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pCurrentEntity->curstate.sequence >= m_pStudioHeader->numseq )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_pCurrentEntity->curstate.sequence = 0;
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
pseqdesc = (mstudioseqdesc_t *)( (byte *)m_pStudioHeader + m_pStudioHeader->seqindex ) + m_pCurrentEntity->curstate.sequence;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
StudioPlayerBlend( pseqdesc, &iBlend, &m_pCurrentEntity->angles[PITCH] );
|
|
|
|
|
|
|
|
m_pCurrentEntity->latched.prevangles[PITCH] = m_pCurrentEntity->angles[PITCH];
|
|
|
|
m_pCurrentEntity->curstate.blending[0] = iBlend;
|
|
|
|
m_pCurrentEntity->latched.prevblending[0] = m_pCurrentEntity->curstate.blending[0];
|
|
|
|
m_pCurrentEntity->latched.prevseqblending[0] = m_pCurrentEntity->curstate.blending[0];
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
// Con_DPrintf( "%f %d\n", m_pCurrentEntity->angles[PITCH], m_pCurrentEntity->blending[0] );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
dt = ( m_clTime - m_clOldTime );
|
2019-10-13 13:49:25 +02:00
|
|
|
if( dt < 0.0f )
|
|
|
|
dt = 0.0f;
|
|
|
|
else if( dt > 1.0f )
|
|
|
|
dt = 1.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
StudioEstimateGait( pplayer );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
// Con_DPrintf( "%f %f\n", m_pCurrentEntity->angles[YAW], m_pPlayerInfo->gaityaw );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// calc side to side turning
|
|
|
|
flYaw = m_pCurrentEntity->angles[YAW] - m_pPlayerInfo->gaityaw;
|
2019-10-13 13:49:25 +02:00
|
|
|
flYaw = flYaw - (int)( flYaw / 360.0f ) * 360.0f;
|
|
|
|
if( flYaw < -180.0f )
|
|
|
|
flYaw = flYaw + 360.0f;
|
|
|
|
if( flYaw > 180.0f )
|
|
|
|
flYaw = flYaw - 360.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
if( flYaw > 120.0f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
m_pPlayerInfo->gaityaw = m_pPlayerInfo->gaityaw - 180.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
m_flGaitMovement = -m_flGaitMovement;
|
2019-10-13 13:49:25 +02:00
|
|
|
flYaw = flYaw - 180.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
2019-10-13 13:49:25 +02:00
|
|
|
else if( flYaw < -120.0f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
m_pPlayerInfo->gaityaw = m_pPlayerInfo->gaityaw + 180.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
m_flGaitMovement = -m_flGaitMovement;
|
2019-10-13 13:49:25 +02:00
|
|
|
flYaw = flYaw + 180.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// adjust torso
|
2019-10-13 13:49:25 +02:00
|
|
|
m_pCurrentEntity->curstate.controller[0] = ( ( flYaw / 4.0f ) + 30.0f ) / ( 60.0f / 255.0f );
|
|
|
|
m_pCurrentEntity->curstate.controller[1] = ( ( flYaw / 4.0f ) + 30.0f ) / ( 60.0f / 255.0f );
|
|
|
|
m_pCurrentEntity->curstate.controller[2] = ( ( flYaw / 4.0f ) + 30.0f ) / ( 60.0f / 255.0f );
|
|
|
|
m_pCurrentEntity->curstate.controller[3] = ( ( flYaw / 4.0f ) + 30.0f ) / ( 60.0f / 255.0f );
|
2016-06-04 15:24:23 +02:00
|
|
|
m_pCurrentEntity->latched.prevcontroller[0] = m_pCurrentEntity->curstate.controller[0];
|
|
|
|
m_pCurrentEntity->latched.prevcontroller[1] = m_pCurrentEntity->curstate.controller[1];
|
|
|
|
m_pCurrentEntity->latched.prevcontroller[2] = m_pCurrentEntity->curstate.controller[2];
|
|
|
|
m_pCurrentEntity->latched.prevcontroller[3] = m_pCurrentEntity->curstate.controller[3];
|
|
|
|
|
|
|
|
m_pCurrentEntity->angles[YAW] = m_pPlayerInfo->gaityaw;
|
2019-10-13 13:49:25 +02:00
|
|
|
if( m_pCurrentEntity->angles[YAW] < -0.0f )
|
|
|
|
m_pCurrentEntity->angles[YAW] += 360.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
m_pCurrentEntity->latched.prevangles[YAW] = m_pCurrentEntity->angles[YAW];
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pplayer->gaitsequence >= m_pStudioHeader->numseq )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pplayer->gaitsequence = 0;
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
pseqdesc = (mstudioseqdesc_t *)( (byte *)m_pStudioHeader + m_pStudioHeader->seqindex ) + pplayer->gaitsequence;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// calc gait frame
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pseqdesc->linearmovement[0] > 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
m_pPlayerInfo->gaitframe += ( m_flGaitMovement / pseqdesc->linearmovement[0] ) * pseqdesc->numframes;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_pPlayerInfo->gaitframe += pseqdesc->fps * dt;
|
|
|
|
}
|
|
|
|
|
|
|
|
// do modulo
|
|
|
|
m_pPlayerInfo->gaitframe = m_pPlayerInfo->gaitframe - (int)(m_pPlayerInfo->gaitframe / pseqdesc->numframes) * pseqdesc->numframes;
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pPlayerInfo->gaitframe < 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
m_pPlayerInfo->gaitframe += pseqdesc->numframes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioDrawPlayer
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
int CStudioModelRenderer::StudioDrawPlayer( int flags, entity_state_t *pplayer )
|
|
|
|
{
|
|
|
|
alight_t lighting;
|
|
|
|
vec3_t dir;
|
|
|
|
|
|
|
|
m_pCurrentEntity = IEngineStudio.GetCurrentEntity();
|
|
|
|
IEngineStudio.GetTimes( &m_nFrameCount, &m_clTime, &m_clOldTime );
|
|
|
|
IEngineStudio.GetViewInfo( m_vRenderOrigin, m_vUp, m_vRight, m_vNormal );
|
|
|
|
IEngineStudio.GetAliasScale( &m_fSoftwareXScale, &m_fSoftwareYScale );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
// Con_DPrintf( "DrawPlayer %d\n", m_pCurrentEntity->blending[0] );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
// Con_DPrintf( "DrawPlayer %d %d (%d)\n", m_nFrameCount, pplayer->player_index, m_pCurrentEntity->curstate.sequence );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// Con_DPrintf("Player %.2f %.2f %.2f\n", pplayer->velocity[0], pplayer->velocity[1], pplayer->velocity[2] );
|
|
|
|
|
|
|
|
m_nPlayerIndex = pplayer->number - 1;
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_nPlayerIndex < 0 || m_nPlayerIndex >= gEngfuncs.GetMaxClients() )
|
2016-06-04 15:24:23 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
m_pRenderModel = IEngineStudio.SetupPlayerModel( m_nPlayerIndex );
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pRenderModel == NULL )
|
2016-06-04 15:24:23 +02:00
|
|
|
return 0;
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
m_pStudioHeader = (studiohdr_t *)IEngineStudio.Mod_Extradata( m_pRenderModel );
|
2016-06-04 15:24:23 +02:00
|
|
|
IEngineStudio.StudioSetHeader( m_pStudioHeader );
|
|
|
|
IEngineStudio.SetRenderModel( m_pRenderModel );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pplayer->gaitsequence )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
vec3_t orig_angles;
|
|
|
|
m_pPlayerInfo = IEngineStudio.PlayerInfo( m_nPlayerIndex );
|
|
|
|
|
|
|
|
VectorCopy( m_pCurrentEntity->angles, orig_angles );
|
2016-08-01 13:13:13 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
StudioProcessGait( pplayer );
|
|
|
|
|
|
|
|
m_pPlayerInfo->gaitsequence = pplayer->gaitsequence;
|
|
|
|
m_pPlayerInfo = NULL;
|
|
|
|
|
|
|
|
StudioSetUpTransform( 0 );
|
|
|
|
VectorCopy( orig_angles, m_pCurrentEntity->angles );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_pCurrentEntity->curstate.controller[0] = 127;
|
|
|
|
m_pCurrentEntity->curstate.controller[1] = 127;
|
|
|
|
m_pCurrentEntity->curstate.controller[2] = 127;
|
|
|
|
m_pCurrentEntity->curstate.controller[3] = 127;
|
|
|
|
m_pCurrentEntity->latched.prevcontroller[0] = m_pCurrentEntity->curstate.controller[0];
|
|
|
|
m_pCurrentEntity->latched.prevcontroller[1] = m_pCurrentEntity->curstate.controller[1];
|
|
|
|
m_pCurrentEntity->latched.prevcontroller[2] = m_pCurrentEntity->curstate.controller[2];
|
|
|
|
m_pCurrentEntity->latched.prevcontroller[3] = m_pCurrentEntity->curstate.controller[3];
|
2016-08-01 13:13:13 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
m_pPlayerInfo = IEngineStudio.PlayerInfo( m_nPlayerIndex );
|
|
|
|
m_pPlayerInfo->gaitsequence = 0;
|
|
|
|
|
|
|
|
StudioSetUpTransform( 0 );
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( flags & STUDIO_RENDER )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// see if the bounding box lets us trivially reject, also sets
|
2016-08-01 13:13:13 +02:00
|
|
|
if( !IEngineStudio.StudioCheckBBox () )
|
2016-06-04 15:24:23 +02:00
|
|
|
return 0;
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
( *m_pModelsDrawn )++;
|
|
|
|
( *m_pStudioModelCount )++; // render data cache cookie
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pStudioHeader->numbodyparts == 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pPlayerInfo = IEngineStudio.PlayerInfo( m_nPlayerIndex );
|
2016-08-01 13:13:13 +02:00
|
|
|
StudioSetupBones();
|
|
|
|
StudioSaveBones();
|
2016-06-04 15:24:23 +02:00
|
|
|
m_pPlayerInfo->renderframe = m_nFrameCount;
|
|
|
|
|
|
|
|
m_pPlayerInfo = NULL;
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( flags & STUDIO_EVENTS )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
StudioCalcAttachments();
|
|
|
|
IEngineStudio.StudioClientEvents();
|
2016-06-04 15:24:23 +02:00
|
|
|
// copy attachments into global entity array
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pCurrentEntity->index > 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
cl_entity_t *ent = gEngfuncs.GetEntityByIndex( m_pCurrentEntity->index );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
memcpy( ent->attachment, m_pCurrentEntity->attachment, sizeof(vec3_t) * 4 );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( flags & STUDIO_RENDER )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pCvarHiModels->value && m_pRenderModel != m_pCurrentEntity->model )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// show highest resolution multiplayer model
|
|
|
|
m_pCurrentEntity->curstate.body = 255;
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( !( m_pCvarDeveloper->value == 0 && gEngfuncs.GetMaxClients() == 1 ) && ( m_pRenderModel == m_pCurrentEntity->model ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_pCurrentEntity->curstate.body = 1; // force helmet
|
|
|
|
}
|
|
|
|
|
|
|
|
lighting.plightvec = dir;
|
2016-08-01 13:13:13 +02:00
|
|
|
IEngineStudio.StudioDynamicLight( m_pCurrentEntity, &lighting );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
IEngineStudio.StudioEntityLight( &lighting );
|
|
|
|
|
|
|
|
// model and frame independant
|
2016-08-01 13:13:13 +02:00
|
|
|
IEngineStudio.StudioSetupLighting( &lighting );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
m_pPlayerInfo = IEngineStudio.PlayerInfo( m_nPlayerIndex );
|
|
|
|
|
|
|
|
// get remap colors
|
|
|
|
m_nTopColor = m_pPlayerInfo->topcolor;
|
|
|
|
m_nBottomColor = m_pPlayerInfo->bottomcolor;
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_nTopColor < 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
m_nTopColor = 0;
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_nTopColor > 360 )
|
2016-06-04 15:24:23 +02:00
|
|
|
m_nTopColor = 360;
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_nBottomColor < 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
m_nBottomColor = 0;
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_nBottomColor > 360 )
|
2016-06-04 15:24:23 +02:00
|
|
|
m_nBottomColor = 360;
|
|
|
|
|
|
|
|
IEngineStudio.StudioSetRemapColors( m_nTopColor, m_nBottomColor );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
StudioRenderModel();
|
2016-06-04 15:24:23 +02:00
|
|
|
m_pPlayerInfo = NULL;
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( pplayer->weaponmodel )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
cl_entity_t saveent = *m_pCurrentEntity;
|
|
|
|
|
|
|
|
model_t *pweaponmodel = IEngineStudio.GetModelByIndex( pplayer->weaponmodel );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
m_pStudioHeader = (studiohdr_t *)IEngineStudio.Mod_Extradata( pweaponmodel );
|
2016-06-04 15:24:23 +02:00
|
|
|
IEngineStudio.StudioSetHeader( m_pStudioHeader );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
StudioMergeBones( pweaponmodel );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
IEngineStudio.StudioSetupLighting( &lighting );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
StudioRenderModel();
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
StudioCalcAttachments();
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
*m_pCurrentEntity = saveent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioCalcAttachments
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
void CStudioModelRenderer::StudioCalcAttachments( void )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
mstudioattachment_t *pattachment;
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pStudioHeader->numattachments > 4 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
gEngfuncs.Con_DPrintf( "Too many attachments on %s\n", m_pCurrentEntity->model->name );
|
|
|
|
exit( -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
// calculate attachment points
|
2016-08-01 13:13:13 +02:00
|
|
|
pattachment = (mstudioattachment_t *)( (byte *)m_pStudioHeader + m_pStudioHeader->attachmentindex );
|
|
|
|
for( i = 0; i < m_pStudioHeader->numattachments; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
VectorTransform( pattachment[i].org, (*m_plighttransform)[pattachment[i].bone], m_pCurrentEntity->attachment[i] );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioRenderModel
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
void CStudioModelRenderer::StudioRenderModel( void )
|
|
|
|
{
|
|
|
|
IEngineStudio.SetChromeOrigin();
|
|
|
|
IEngineStudio.SetForceFaceFlags( 0 );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pCurrentEntity->curstate.renderfx == kRenderFxGlowShell )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_pCurrentEntity->curstate.renderfx = kRenderFxNone;
|
2016-08-01 13:13:13 +02:00
|
|
|
StudioRenderFinal();
|
|
|
|
|
|
|
|
if( !IEngineStudio.IsHardware() )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
gEngfuncs.pTriAPI->RenderMode( kRenderTransAdd );
|
|
|
|
}
|
|
|
|
|
|
|
|
IEngineStudio.SetForceFaceFlags( STUDIO_NF_CHROME );
|
|
|
|
|
|
|
|
gEngfuncs.pTriAPI->SpriteTexture( m_pChromeSprite, 0 );
|
|
|
|
m_pCurrentEntity->curstate.renderfx = kRenderFxGlowShell;
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
StudioRenderFinal();
|
|
|
|
if( !IEngineStudio.IsHardware() )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
gEngfuncs.pTriAPI->RenderMode( kRenderNormal );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
StudioRenderFinal();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioRenderFinal_Software
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
void CStudioModelRenderer::StudioRenderFinal_Software( void )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// Note, rendermode set here has effect in SW
|
|
|
|
IEngineStudio.SetupRenderer( 0 );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pCvarDrawEntities->value == 2 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
IEngineStudio.StudioDrawBones();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
else if( m_pCvarDrawEntities->value == 3 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
IEngineStudio.StudioDrawHulls();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
for( i = 0; i < m_pStudioHeader->numbodyparts; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
IEngineStudio.StudioSetupModel( i, (void **)&m_pBodyPart, (void **)&m_pSubModel );
|
2016-08-01 13:13:13 +02:00
|
|
|
IEngineStudio.StudioDrawPoints();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pCvarDrawEntities->value == 4 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
gEngfuncs.pTriAPI->RenderMode( kRenderTransAdd );
|
2016-08-01 13:13:13 +02:00
|
|
|
IEngineStudio.StudioDrawHulls();
|
2016-06-04 15:24:23 +02:00
|
|
|
gEngfuncs.pTriAPI->RenderMode( kRenderNormal );
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pCvarDrawEntities->value == 5 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
IEngineStudio.StudioDrawAbsBBox();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
IEngineStudio.RestoreRenderer();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioRenderFinal_Hardware
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
void CStudioModelRenderer::StudioRenderFinal_Hardware( void )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int rendermode;
|
|
|
|
|
|
|
|
rendermode = IEngineStudio.GetForceFaceFlags() ? kRenderTransAdd : m_pCurrentEntity->curstate.rendermode;
|
|
|
|
IEngineStudio.SetupRenderer( rendermode );
|
2016-08-01 13:13:13 +02:00
|
|
|
|
|
|
|
if( m_pCvarDrawEntities->value == 2 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
IEngineStudio.StudioDrawBones();
|
|
|
|
}
|
2016-08-01 13:13:13 +02:00
|
|
|
else if( m_pCvarDrawEntities->value == 3 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
IEngineStudio.StudioDrawHulls();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
for( i = 0; i < m_pStudioHeader->numbodyparts; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
IEngineStudio.StudioSetupModel( i, (void **)&m_pBodyPart, (void **)&m_pSubModel );
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_fDoInterp )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// interpolation messes up bounding boxes.
|
|
|
|
m_pCurrentEntity->trivial_accept = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
IEngineStudio.GL_SetRenderMode( rendermode );
|
|
|
|
IEngineStudio.StudioDrawPoints();
|
|
|
|
IEngineStudio.GL_StudioDrawShadow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pCvarDrawEntities->value == 4 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
gEngfuncs.pTriAPI->RenderMode( kRenderTransAdd );
|
2016-08-01 13:13:13 +02:00
|
|
|
IEngineStudio.StudioDrawHulls();
|
2016-06-04 15:24:23 +02:00
|
|
|
gEngfuncs.pTriAPI->RenderMode( kRenderNormal );
|
|
|
|
}
|
|
|
|
|
2016-08-01 13:13:13 +02:00
|
|
|
if( m_pCvarDrawEntities->value == 5 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
IEngineStudio.StudioDrawAbsBBox();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
IEngineStudio.RestoreRenderer();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
StudioRenderFinal
|
|
|
|
|
|
|
|
====================
|
|
|
|
*/
|
2016-08-01 13:13:13 +02:00
|
|
|
void CStudioModelRenderer::StudioRenderFinal( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-08-01 13:13:13 +02:00
|
|
|
if( IEngineStudio.IsHardware() )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
StudioRenderFinal_Hardware();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StudioRenderFinal_Software();
|
|
|
|
}
|
|
|
|
}
|