PlayerSlavedHUD

From DigitalBlacksmith

Jump to: navigation, search

Contents

[edit] Player Slaved 3D HUD

[edit] Background

I am trying to make a 3D copy of the HUD

One that exists as a 3D entity, and therefore can be resized to account for shortcomings in the NVIDIA Stereo driver.

My initial effort was to create a dll entity that updates its position based on the player..ala artag_model.cpp or player_slaved_entity.cpp.

The class consists of client and server code:


Client
------
cl_hud_vguiscreen.h
cl_hud_vguiscreen.cpp 

Server
-------
hud_vguiscreen.h
hud_vguiscreen.cpp 

BUT it LAGS..when the player walks the HUD isn't smooth.

[edit] Practice/Research

I decided to check out this tutorial, and set up a vgui::panel on the RPG. The idea being that perhaps I could replicate with the player instead of the rpg.

This creates a nice panel on the RPG..and it doesn't LAG...cool

Here's the trail:


It looks like the method:

 
// Returns information about the various control panels
virtual void             GetControlPanelInfo( int nPanelIndex, const char *&pPanelName );
virtual void            GetControlPanelClassName( int nPanelIndex, const char *&pPanelName );
 

Are defined in CBadeCombatWeapon and overload by RPG

[edit] SpawnControlPanels()

This is the cue to build the control panels

It's only called in baseviewmodel_shared.cpp

This is somehow called by the CBaseCombatWeapon base class when the RPG spawns..like this:


[edit] VGUI on Player Entity

Now I want to do the same thing for the player.

I discovered that the player model for the MOD is player.mdl

[edit] Attachments on player.mdl

We need to see if player.mdl has any attachments...IT DOES NOT

We will create our own.

I first had to get the modelsource for player.mdl

1. Used GCFScape to extract the following files from source models.gcf:

Player.dx80.vtx
Player.dx90.vtx
PLAYER.jpg
Player.sw.vtx
Player.vvd

I placed these in a new directory at

<MOD Content>/modelsrc/player

I then used Cannon Fodder's model decompiler to reverse engineer the source. Just open up the model decompiler and point it at the file in modelsrc/player..

I then renamed the mdldecompile.qc to player.qc and made it look like this:

$cd "C:\Steam\steamapps\SourceMods\ARMARSP\modelsrc\player"
$modelname "player.mdl"
$model "player" "playertemp.smd"
$cdmaterials "models\player\"


$hboxset "default"
$hbox 0 "Bip01 Spine" -6.313  -4.778  -6.764  5.310  4.961  6.453
$hbox 0 "Bip01 Spine1" -0.932  -5.634  -5.613  5.241  5.472  5.446
$hbox 0 "Bip01 Spine2" 0.000  -4.425  -8.311  5.793  6.156  8.063
$hbox 0 "Bip01 Neck" -6.931  -4.763  -6.012  2.047  6.425  5.795
$hbox 0 "Bip01 L Clavicle" 0.000  -2.828  -0.513  5.440  5.612  3.524
$hbox 0 "Bip01 L UpperArm" -2.169  -2.358  -2.573  11.586  3.420  2.381
$hbox 0 "Bip01 R Clavicle" 0.000  -2.790  -3.590  5.690  5.650  0.708
$hbox 0 "Bip01 R UpperArm" -1.905  -2.472  -2.185  11.838  3.305  2.816
$hbox 0 "Bip01 L Forearm" 0.000  -1.842  -2.199  10.759  2.868  2.412
$hbox 0 "Bip01 R Thigh" 0.000  -3.716  -3.162  18.872  5.256  3.402
$hbox 0 "Bip01 L Thigh" 0.000  -3.699  -3.103  18.923  5.262  3.334
$hbox 0 "Bip01 R Calf" 0.000  -3.983  -2.848  17.598  3.022  2.978
$hbox 0 "Bip01 R Foot" 0.000  -2.333  -2.185  3.800  6.407  2.259
$hbox 0 "Bip01 R Toe0" -0.213  -0.030  -2.199  2.711  2.298  2.665
$hbox 0 "Bip01 L Hand" 0.000  -0.805  -2.219  4.089  1.089  1.770
$hbox 0 "Bip01 R Forearm" 0.000  -1.989  -2.352  10.599  2.721  2.250
$hbox 0 "Bip01 R Hand" 0.000  -0.825  -1.624  4.131  1.061  2.363
$hbox 0 "Bip01 L Calf" 0.000  -3.959  -2.871  17.598  3.062  2.954
$hbox 0 "Bip01 L Foot" 0.000  -2.333  -2.287  3.793  6.407  2.202
$hbox 0 "Bip01 L Toe0" -0.213  -0.012  -2.648  2.711  2.316  2.216
$hbox 0 "Bip01 Head" -0.570  -3.687  -3.019  8.418  5.107  2.632

$attachment "controlpanel0_ur" "Bip01 Head" -0.00 18.00 0.00 rotate -90 0 0
$attachment "controlpanel0_ll" "Bip01 Head" -0.00 18.00 -8.00 rotate -90 0 0


// Model uses material "PLAYER_Chrome1.vmt"
$surfaceprop "flesh"
$illumposition 3.612 0.822 36.772
$sequence Idle01 "Idle01" loop ACT_IDLE 1 fps 22.00
$sequence run "run" loop ACT_RUN 1 fps 22.00
$sequence walk "walk" loop ACT_WALK 1 fps 22.00
$sequence diesimple "diesimple" loop ACT_DIESIMPLE 1 fps 22.00
$sequence shoot "shoot" loop ACT_RANGE_ATTACK1 1 fps 22.00

Note the two attachments placed on Bip01 Head...you can look for other bones to root your attachments by browsing playertemp.smd..

Made a batch file called player.bat that looks like this:

"C:\Steam\steamapps\steven_j_henderson\sourcesdk\bin\ep1\bin\studiomdl.exe" "C:\Steam\steamapps\SourceMods\ARMARSP\modelsrc\player\player.qc"
pause

It compiles and lloks like this:

Image:Player_attach.png

[edit] Modifying the SDK

I then confirmed that the player looks for VGUI Panels..

Added this to player.cpp:

Lines: 431


Msg("--------Spawinging player control panels....\n"); vm->SpawnControlPanels();

This indicated that it was trying to find a model....

Now I need to get it to load..

I added the following to line 221 of player.h right after UnlockPlayer:


 
void                    UnlockPlayer( void );
 
// DB: Get the name of our attached vguiscreen
void    GetControlPanelInfo( int nPanelIndex, const char *&pPanelName);
void    GetControlPanelClassName( int nPanelIndex, const char *&pPanelName );
 
virtual void            DrawDebugGeometryOverlays(void);    
 


And in player.cpp (around Line 6701 after UnlockPlayer):

 
//-----------------------------------------------------------------------------
// Purpose: DB: Get the name of our attached vguiscreen
//-----------------------------------------------------------------------------
void CBasePlayer::GetControlPanelInfo( int nPanelIndex, const char *&pPanelName )
{
    pPanelName = "rpg_screen";
}
 
 
//-----------------------------------------------------------------------------
// Returns information about the various control panels
//-----------------------------------------------------------------------------
void CBasePlayer::GetControlPanelClassName( int nPanelIndex, const char *&pPanelName )
{
    pPanelName = "vgui_screen";
}
 
 

Not sure if that second one is right


Now we may (probably) will have to modify the following method in baseviewmodel_shared.cpp (it looks weapon specific):

 
void CBaseViewModel::SpawnControlPanels()
 

For now I am going to watch it (Changin line 113-116):

 
if ( weapon == NULL ) {
  Warning("---------------- No Weapon in Spawn Control Panels!!!-------------------------");
  return;
}
 

As expected this didn't work...I'm getting the error message..going to try to tweak the code some more.

Found this here

 
// I bound this to a key for testing(i.e. bind [ ironsight_toggle)
CON_COMMAND(ironsight_toggle, "toggles ironsight mode for the current weapon")
{
if (gpGlobals->curtime - gIronsightedTime < 0.5f)
return;
 
CBasePlayer *pPlayer = UTIL_PlayerByIndex(engine->GetLocalPlayer());
if (pPlayer)
{
C_BaseViewModel  *pVm = pPlayer->GetViewModel();
if (pVm)
{
		//pPlayer->m_Local.m_iHideHUD |= HIDEHUD_CROSSHAIR;)
pVm->m_bExpSighted  ^= true;
gIronsightedTime     = gpGlobals->curtime;
}
}
}
 


Found a nice description of viewmodels.

Personal tools