mirror of
https://github.com/DrBeef/JKXR.git
synced 2024-11-22 04:01:33 +00:00
Make weapon adjustment mode independent for each weapon; Optimize loading of weapon adjustments
This commit is contained in:
parent
baec8832ab
commit
21483d0d5a
5 changed files with 117 additions and 128 deletions
|
@ -272,8 +272,6 @@ void VR_Init()
|
|||
vr.snapTurn = 0.0f;
|
||||
vr.immersive_cinematics = true;
|
||||
|
||||
vr.test_scale = 1.0f;
|
||||
|
||||
//init randomiser
|
||||
srand(time(NULL));
|
||||
|
||||
|
|
|
@ -11,6 +11,13 @@
|
|||
#define USE_GESTURE_OFF_HAND 1
|
||||
#define USE_GESTURE_WEAPON_HAND 2
|
||||
|
||||
typedef struct {
|
||||
bool loaded;
|
||||
float scale;
|
||||
vec3_t angles;
|
||||
vec3_t offset;
|
||||
} vr_weapon_adjustment_t;
|
||||
|
||||
typedef struct {
|
||||
bool cin_camera; // cinematic camera taken over
|
||||
|
||||
|
@ -71,6 +78,9 @@ typedef struct {
|
|||
vec3_t weaponoffset_history[NUM_WEAPON_SAMPLES];
|
||||
float weaponoffset_history_timestamp[NUM_WEAPON_SAMPLES];
|
||||
|
||||
vr_weapon_adjustment_t weaponadjustment[32];
|
||||
char weaponadjustment_info[256]; // debug message for weapon alignment
|
||||
|
||||
int item_selector; // 1 - weapons/gadgets/saber stance, 2 - Force powers
|
||||
|
||||
bool velocitytriggered;
|
||||
|
@ -92,15 +102,6 @@ typedef struct {
|
|||
float curHeight;
|
||||
int useGestureState;
|
||||
|
||||
//////////////////////////////////////
|
||||
// Test stuff for weapon alignment
|
||||
//////////////////////////////////////
|
||||
|
||||
char test_name[256];
|
||||
float test_scale;
|
||||
vec3_t test_angles;
|
||||
vec3_t test_offset;
|
||||
|
||||
} vr_client_info_t;
|
||||
|
||||
#ifndef JKXR_CLIENT
|
||||
|
|
|
@ -186,9 +186,14 @@ void HandleInput_WeaponAlign( ovrInputStateTrackedRemote *pDominantTrackedRemote
|
|||
sendButtonActionSimple("weapprev");
|
||||
}
|
||||
|
||||
vr_weapon_adjustment_t *adjustment = &vr.weaponadjustment[cl.frame.ps.weapon];
|
||||
if (!adjustment->loaded) {
|
||||
return; // will be loaded "next frame"
|
||||
}
|
||||
|
||||
static int item_index = 0;
|
||||
float* items[7] = {&vr.test_scale, &(vr.test_offset[0]), &(vr.test_offset[1]), &(vr.test_offset[2]),
|
||||
&(vr.test_angles[PITCH]), &(vr.test_angles[YAW]), &(vr.test_angles[ROLL])};
|
||||
float* items[7] = {&adjustment->scale, &(adjustment->offset[0]), &(adjustment->offset[1]), &(adjustment->offset[2]),
|
||||
&(adjustment->angles[PITCH]), &(adjustment->angles[YAW]), &(adjustment->angles[ROLL])};
|
||||
char* item_names[7] = {"scale", "right", "up", "forward", "pitch", "yaw", "roll"};
|
||||
float item_inc[7] = {0.005, 0.02, 0.02, 0.02, 0.1, 0.1, 0.1};
|
||||
|
||||
|
@ -249,14 +254,15 @@ void HandleInput_WeaponAlign( ovrInputStateTrackedRemote *pDominantTrackedRemote
|
|||
}
|
||||
}
|
||||
|
||||
Com_sprintf(vr.test_name, sizeof(vr.test_name), "%s: %.3f", item_names[item_index], *(items[item_index]));
|
||||
Com_sprintf(vr.weaponadjustment_info, sizeof(vr.weaponadjustment_info), "%s: %.3f", item_names[item_index], *(items[item_index]));
|
||||
|
||||
char cvar_name[64];
|
||||
Com_sprintf(cvar_name, sizeof(cvar_name), "vr_weapon_adjustment_%i", cl.frame.ps.weapon);
|
||||
|
||||
char buffer[256];
|
||||
Com_sprintf(buffer, sizeof(buffer), "%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f", vr.test_scale, (vr.test_offset[0] / vr.test_scale), (vr.test_offset[1] / vr.test_scale), (vr.test_offset[2] / vr.test_scale),
|
||||
(vr.test_angles[PITCH]), (vr.test_angles[YAW]), (vr.test_angles[ROLL]));
|
||||
Com_sprintf(buffer, sizeof(buffer), "%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f", adjustment->scale,
|
||||
adjustment->offset[0], adjustment->offset[1], adjustment->offset[2],
|
||||
adjustment->angles[PITCH], adjustment->angles[YAW], adjustment->angles[ROLL]);
|
||||
Cvar_Set(cvar_name, buffer );
|
||||
}
|
||||
|
||||
|
|
|
@ -864,6 +864,35 @@ void CG_CalculateWeaponPosition( vec3_t origin, vec3_t angles )
|
|||
angles[PITCH] += (scale * 0.5f ) * fracsin * 0.01;
|
||||
}
|
||||
|
||||
static vr_weapon_adjustment_t* LoadWeaponAdjustment( int weapon ) {
|
||||
char cvar_name[64];
|
||||
vr_weapon_adjustment_t *adjustment = &vr->weaponadjustment[weapon];
|
||||
if (!adjustment->loaded) {
|
||||
Com_sprintf(cvar_name, sizeof(cvar_name), "vr_weapon_adjustment_%i", weapon);
|
||||
char* weapon_adjustment = cgi_Cvar_Get(cvar_name);
|
||||
if (strlen(weapon_adjustment) > 0) {
|
||||
sscanf(weapon_adjustment, "%f,%f,%f,%f,%f,%f,%f",
|
||||
&adjustment->scale,
|
||||
&adjustment->offset[0],
|
||||
&adjustment->offset[1],
|
||||
&adjustment->offset[2],
|
||||
&adjustment->angles[PITCH],
|
||||
&adjustment->angles[YAW],
|
||||
&adjustment->angles[ROLL]);
|
||||
} else {
|
||||
adjustment->scale = 1.0f;
|
||||
adjustment->offset[0] = 0.0f;
|
||||
adjustment->offset[1] = 0.0f;
|
||||
adjustment->offset[2] = 0.0f;
|
||||
adjustment->angles[PITCH] = 0.0f;
|
||||
adjustment->angles[YAW] = 0.0f;
|
||||
adjustment->angles[ROLL] = 0.0f;
|
||||
}
|
||||
adjustment->loaded = true;
|
||||
}
|
||||
return adjustment;
|
||||
}
|
||||
|
||||
static float CG_CalculateWeaponPositionAndScale( playerState_t *ps, vec3_t origin, vec3_t angles ) {
|
||||
|
||||
if (cg.renderingThirdPerson)
|
||||
|
@ -874,64 +903,27 @@ static float CG_CalculateWeaponPositionAndScale( playerState_t *ps, vec3_t origi
|
|||
|
||||
BG_CalculateVRWeaponPosition(origin, angles);
|
||||
|
||||
vr_weapon_adjustment_t *adjustment = LoadWeaponAdjustment(ps->weapon);
|
||||
|
||||
vec3_t offset;
|
||||
VectorScale(adjustment->offset, adjustment->scale, offset);
|
||||
|
||||
//Weapon offset debugging
|
||||
float scale=1.0f;
|
||||
if (strcmp(cgi_Cvar_Get("vr_control_scheme"), "99") == 0) {
|
||||
scale = vr->test_scale;
|
||||
|
||||
//Adjust angles for weapon models that aren't aligned very well
|
||||
matrix4x4 m1, m2, m3;
|
||||
vec3_t zero;
|
||||
VectorClear(zero);
|
||||
Matrix4x4_CreateFromEntity(m1, angles, zero, 1.0);
|
||||
Matrix4x4_CreateFromEntity(m2, vr->test_angles, zero, 1.0);
|
||||
Matrix4x4_Concat(m3, m1, m2);
|
||||
Matrix4x4_ConvertToEntity(m3, angles, zero);
|
||||
|
||||
VectorCopy(vr->test_offset, offset);
|
||||
|
||||
int w = cgi_R_Font_StrLenPixels(vr->test_name, cgs.media.qhFontSmall, 1.0f);
|
||||
int x = ( SCREEN_WIDTH - w ) / 2;
|
||||
cgi_R_Font_DrawString(x, (SCREEN_HEIGHT / 2), vr->test_name, colorTable[CT_ICON_BLUE], cgs.media.qhFontSmall, -1, 1.0f);
|
||||
} else {
|
||||
if (ps->weapon != 0)
|
||||
{
|
||||
char cvar_name[64];
|
||||
Com_sprintf(cvar_name, sizeof(cvar_name), "vr_weapon_adjustment_%i", ps->weapon);
|
||||
|
||||
char* weapon_adjustment = cgi_Cvar_Get(cvar_name);
|
||||
|
||||
if (strlen(weapon_adjustment) > 0) {
|
||||
vec3_t adjust;
|
||||
vec3_t temp_offset;
|
||||
VectorClear(temp_offset);
|
||||
VectorClear(adjust);
|
||||
|
||||
sscanf(weapon_adjustment, "%f,%f,%f,%f,%f,%f,%f", &scale,
|
||||
&(temp_offset[0]), &(temp_offset[1]), &(temp_offset[2]),
|
||||
&(adjust[PITCH]), &(adjust[YAW]), &(adjust[ROLL]));
|
||||
VectorScale(temp_offset, scale, offset);
|
||||
|
||||
if (!vr->right_handed)
|
||||
{
|
||||
//yaw needs to go in the other direction as left handed model is reversed
|
||||
adjust[YAW] *= -1.0f;
|
||||
}
|
||||
|
||||
//Adjust angles for weapon models that aren't aligned very well
|
||||
matrix4x4 m1, m2, m3;
|
||||
vec3_t zero;
|
||||
VectorClear(zero);
|
||||
Matrix4x4_CreateFromEntity(m1, angles, zero, 1.0);
|
||||
Matrix4x4_CreateFromEntity(m2, adjust, zero, 1.0);
|
||||
Matrix4x4_Concat(m3, m1, m2);
|
||||
Matrix4x4_ConvertToEntity(m3, angles, zero);
|
||||
}
|
||||
}
|
||||
vec3_t adjust;
|
||||
VectorCopy(adjustment->angles, adjust);
|
||||
if (!vr->right_handed)
|
||||
{
|
||||
//yaw needs to go in the other direction as left handed model is reversed
|
||||
adjust[YAW] *= -1.0f;
|
||||
}
|
||||
|
||||
//Adjust angles for weapon models that aren't aligned very well
|
||||
matrix4x4 m1, m2, m3;
|
||||
vec3_t zero;
|
||||
VectorClear(zero);
|
||||
Matrix4x4_CreateFromEntity(m1, angles, zero, 1.0);
|
||||
Matrix4x4_CreateFromEntity(m2, adjust, zero, 1.0);
|
||||
Matrix4x4_Concat(m3, m1, m2);
|
||||
Matrix4x4_ConvertToEntity(m3, angles, zero);
|
||||
|
||||
//Now move weapon closer to proper origin
|
||||
vec3_t forward, right, up;
|
||||
|
@ -944,7 +936,7 @@ static float CG_CalculateWeaponPositionAndScale( playerState_t *ps, vec3_t origi
|
|||
VectorMA(origin, -offset[0], right, origin);
|
||||
}
|
||||
|
||||
return scale;
|
||||
return adjustment->scale;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1224,7 +1216,7 @@ void CG_AddViewWeapon( playerState_t *ps )
|
|||
120, cgi_R_RegisterShader( "gfx/misc/whiteline2" ),
|
||||
0, FX_SIZE_LINEAR | FX_ALPHA_LINEAR );
|
||||
|
||||
CG_CenterPrint(vr->test_name, 240);
|
||||
CG_CenterPrint(vr->weaponadjustment_info, 240);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -781,6 +781,35 @@ void CG_CalculateWeaponPosition( vec3_t origin, vec3_t angles )
|
|||
angles[PITCH] += (scale * 0.5f ) * fracsin * 0.01;
|
||||
}
|
||||
|
||||
static vr_weapon_adjustment_t* LoadWeaponAdjustment( int weapon ) {
|
||||
char cvar_name[64];
|
||||
vr_weapon_adjustment_t *adjustment = &vr->weaponadjustment[weapon];
|
||||
if (!adjustment->loaded) {
|
||||
Com_sprintf(cvar_name, sizeof(cvar_name), "vr_weapon_adjustment_%i", weapon);
|
||||
char* weapon_adjustment = cgi_Cvar_Get(cvar_name);
|
||||
if (strlen(weapon_adjustment) > 0) {
|
||||
sscanf(weapon_adjustment, "%f,%f,%f,%f,%f,%f,%f",
|
||||
&adjustment->scale,
|
||||
&adjustment->offset[0],
|
||||
&adjustment->offset[1],
|
||||
&adjustment->offset[2],
|
||||
&adjustment->angles[PITCH],
|
||||
&adjustment->angles[YAW],
|
||||
&adjustment->angles[ROLL]);
|
||||
} else {
|
||||
adjustment->scale = 1.0f;
|
||||
adjustment->offset[0] = 0.0f;
|
||||
adjustment->offset[1] = 0.0f;
|
||||
adjustment->offset[2] = 0.0f;
|
||||
adjustment->angles[PITCH] = 0.0f;
|
||||
adjustment->angles[YAW] = 0.0f;
|
||||
adjustment->angles[ROLL] = 0.0f;
|
||||
}
|
||||
adjustment->loaded = true;
|
||||
}
|
||||
return adjustment;
|
||||
}
|
||||
|
||||
static float CG_CalculateWeaponPositionAndScale( playerState_t *ps, vec3_t origin, vec3_t angles ) {
|
||||
|
||||
if (cg.renderingThirdPerson)
|
||||
|
@ -791,64 +820,27 @@ static float CG_CalculateWeaponPositionAndScale( playerState_t *ps, vec3_t origi
|
|||
|
||||
BG_CalculateVRWeaponPosition(origin, angles);
|
||||
|
||||
vr_weapon_adjustment_t *adjustment = LoadWeaponAdjustment(ps->weapon);
|
||||
|
||||
vec3_t offset;
|
||||
VectorScale(adjustment->offset, adjustment->scale, offset);
|
||||
|
||||
//Weapon offset debugging
|
||||
float scale=1.0f;
|
||||
if (strcmp(cgi_Cvar_Get("vr_control_scheme"), "99") == 0) {
|
||||
scale = vr->test_scale;
|
||||
|
||||
//Adjust angles for weapon models that aren't aligned very well
|
||||
matrix4x4 m1, m2, m3;
|
||||
vec3_t zero;
|
||||
VectorClear(zero);
|
||||
Matrix4x4_CreateFromEntity(m1, angles, zero, 1.0);
|
||||
Matrix4x4_CreateFromEntity(m2, vr->test_angles, zero, 1.0);
|
||||
Matrix4x4_Concat(m3, m1, m2);
|
||||
Matrix4x4_ConvertToEntity(m3, angles, zero);
|
||||
|
||||
VectorCopy(vr->test_offset, offset);
|
||||
|
||||
int w = cgi_R_Font_StrLenPixels(vr->test_name, cgs.media.qhFontSmall, 1.0f);
|
||||
int x = ( SCREEN_WIDTH - w ) / 2;
|
||||
cgi_R_Font_DrawString(x, (SCREEN_HEIGHT / 2), vr->test_name, colorTable[CT_ICON_BLUE], cgs.media.qhFontSmall, -1, FONT_SCALE);
|
||||
} else {
|
||||
if (ps->weapon != 0)
|
||||
{
|
||||
char cvar_name[64];
|
||||
Com_sprintf(cvar_name, sizeof(cvar_name), "vr_weapon_adjustment_%i", ps->weapon);
|
||||
|
||||
char* weapon_adjustment = cgi_Cvar_Get(cvar_name);
|
||||
|
||||
if (strlen(weapon_adjustment) > 0) {
|
||||
vec3_t adjust;
|
||||
vec3_t temp_offset;
|
||||
VectorClear(temp_offset);
|
||||
VectorClear(adjust);
|
||||
|
||||
sscanf(weapon_adjustment, "%f,%f,%f,%f,%f,%f,%f", &scale,
|
||||
&(temp_offset[0]), &(temp_offset[1]), &(temp_offset[2]),
|
||||
&(adjust[PITCH]), &(adjust[YAW]), &(adjust[ROLL]));
|
||||
VectorScale(temp_offset, scale, offset);
|
||||
|
||||
if (!vr->right_handed)
|
||||
{
|
||||
//yaw needs to go in the other direction as left handed model is reversed
|
||||
adjust[YAW] *= -1.0f;
|
||||
}
|
||||
|
||||
//Adjust angles for weapon models that aren't aligned very well
|
||||
matrix4x4 m1, m2, m3;
|
||||
vec3_t zero;
|
||||
VectorClear(zero);
|
||||
Matrix4x4_CreateFromEntity(m1, angles, zero, 1.0);
|
||||
Matrix4x4_CreateFromEntity(m2, adjust, zero, 1.0);
|
||||
Matrix4x4_Concat(m3, m1, m2);
|
||||
Matrix4x4_ConvertToEntity(m3, angles, zero);
|
||||
}
|
||||
}
|
||||
vec3_t adjust;
|
||||
VectorCopy(adjustment->angles, adjust);
|
||||
if (!vr->right_handed)
|
||||
{
|
||||
//yaw needs to go in the other direction as left handed model is reversed
|
||||
adjust[YAW] *= -1.0f;
|
||||
}
|
||||
|
||||
//Adjust angles for weapon models that aren't aligned very well
|
||||
matrix4x4 m1, m2, m3;
|
||||
vec3_t zero;
|
||||
VectorClear(zero);
|
||||
Matrix4x4_CreateFromEntity(m1, angles, zero, 1.0);
|
||||
Matrix4x4_CreateFromEntity(m2, adjust, zero, 1.0);
|
||||
Matrix4x4_Concat(m3, m1, m2);
|
||||
Matrix4x4_ConvertToEntity(m3, angles, zero);
|
||||
|
||||
//Now move weapon closer to proper origin
|
||||
vec3_t forward, right, up;
|
||||
|
@ -861,7 +853,7 @@ static float CG_CalculateWeaponPositionAndScale( playerState_t *ps, vec3_t origi
|
|||
VectorMA(origin, -offset[0], right, origin);
|
||||
}
|
||||
|
||||
return scale;
|
||||
return adjustment->scale;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1150,7 +1142,7 @@ void CG_AddViewWeapon( playerState_t *ps )
|
|||
120, cgi_R_RegisterShader( "gfx/misc/whiteline2" ),
|
||||
FX_SIZE_LINEAR | FX_ALPHA_LINEAR );
|
||||
|
||||
CG_CenterPrint(vr->test_name, 240);
|
||||
CG_CenterPrint(vr->weaponadjustment_info, 240);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue