Visible flashlight in holster

This commit is contained in:
Simon 2020-09-18 23:34:27 +01:00
parent 6cfe71c10b
commit c6d666aba0
8 changed files with 166 additions and 44 deletions

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.drbeef.doom3quest" package="com.drbeef.doom3quest"
android:versionCode="3" android:versionCode="4"
android:versionName="0.0.9" android:installLocation="auto" > android:versionName="0.0.10" android:installLocation="auto" >
<!-- Tell the system this app requires OpenGL ES 3.1. --> <!-- Tell the system this app requires OpenGL ES 3.1. -->
<uses-feature android:glEsVersion="0x00030001" android:required="true"/> <uses-feature android:glEsVersion="0x00030001" android:required="true"/>

View file

@ -36,7 +36,7 @@ typedef struct {
vec3_t weaponangles_last; // Don't use this, it is just for calculating delta! vec3_t weaponangles_last; // Don't use this, it is just for calculating delta!
vec3_t weaponangles_delta; vec3_t weaponangles_delta;
vec3_t flashlightHolsterOrigin; // Where the flashlight can be picked up from vec3_t flashlightHolsterOffset; // Where the flashlight can be picked up from
vec3_t current_weaponoffset; vec3_t current_weaponoffset;

View file

@ -274,18 +274,20 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
} }
} }
if (pVRClientInfo->weaponid != -1 &&
pVRClientInfo->weaponid != 11)
{ {
vec2_t v; vec2_t v;
rotateAboutOrigin(pVRClientInfo->right_handed ? 0.25f : -0.25f, 0.0f, rotateAboutOrigin(pVRClientInfo->right_handed ? -0.2f : 0.2f, 0.0f,
-pVRClientInfo->hmdorientation[YAW], v); -pVRClientInfo->hmdorientation[YAW], v);
pVRClientInfo->flashlightHolsterOrigin[0] = pVRClientInfo->hmdposition[0] + v[0]; pVRClientInfo->flashlightHolsterOffset[0] = -v[0];
pVRClientInfo->flashlightHolsterOrigin[1] = pVRClientInfo->hmdposition[1] / 2.0f; // half way down body "waist" pVRClientInfo->flashlightHolsterOffset[1] = -pVRClientInfo->hmdposition[1] * 0.45f; // almost half way down body "waist"
pVRClientInfo->flashlightHolsterOrigin[2] = (pVRClientInfo->hmdposition[2] + v[1]); pVRClientInfo->flashlightHolsterOffset[2] = -v[1];
float distance = sqrtf( float distance = sqrtf(
powf(pVRClientInfo->flashlightHolsterOrigin[0] - pWeapon->HeadPose.Pose.Position.x, 2) + powf((pVRClientInfo->hmdposition[0] + pVRClientInfo->flashlightHolsterOffset[0]) - pWeapon->HeadPose.Pose.Position.x, 2) +
powf(pVRClientInfo->flashlightHolsterOrigin[1] - pWeapon->HeadPose.Pose.Position.y, 2) + powf((pVRClientInfo->hmdposition[1] + pVRClientInfo->flashlightHolsterOffset[1]) - pWeapon->HeadPose.Pose.Position.y, 2) +
powf(pVRClientInfo->flashlightHolsterOrigin[2] - pWeapon->HeadPose.Pose.Position.z, 2)); powf((pVRClientInfo->hmdposition[2] + pVRClientInfo->flashlightHolsterOffset[2]) - pWeapon->HeadPose.Pose.Position.z, 2));
if (distance > FLASHLIGHT_HOLSTER_DISTANCE) { if (distance > FLASHLIGHT_HOLSTER_DISTANCE) {
canGrabFlashlight = false; canGrabFlashlight = false;

View file

@ -31,6 +31,7 @@ If you have questions concerning this license or the applicable additional terms
#include "framework/async/NetworkSystem.h" #include "framework/async/NetworkSystem.h"
#include "framework/DeclEntityDef.h" #include "framework/DeclEntityDef.h"
#include "renderer/RenderSystem.h" #include "renderer/RenderSystem.h"
#include "renderer/ModelManager.h"
#include "gamesys/SysCvar.h" #include "gamesys/SysCvar.h"
#include "script/Script_Thread.h" #include "script/Script_Thread.h"
@ -44,6 +45,16 @@ If you have questions concerning this license or the applicable additional terms
const int ASYNC_PLAYER_INV_AMMO_BITS = idMath::BitsForInteger( 999 ); // 9 bits to cover the range [0, 999] const int ASYNC_PLAYER_INV_AMMO_BITS = idMath::BitsForInteger( 999 ); // 9 bits to cover the range [0, 999]
const int ASYNC_PLAYER_INV_CLIP_BITS = -7; // -7 bits to cover the range [-1, 60] const int ASYNC_PLAYER_INV_CLIP_BITS = -7; // -7 bits to cover the range [-1, 60]
void rotateAboutOrigin(float x, float y, float rotation, float out[2])
{
out[0] = cosf(DEG2RAD(-rotation)) * x + sinf(DEG2RAD(-rotation)) * y;
out[1] = cosf(DEG2RAD(-rotation)) * y - sinf(DEG2RAD(-rotation)) * x;
}
/* /*
=============================================================================== ===============================================================================
@ -1037,9 +1048,12 @@ idPlayer::idPlayer() {
weapon_soulcube = -1; weapon_soulcube = -1;
weapon_pda = -1; weapon_pda = -1;
weapon_fists = -1; weapon_fists = -1;
weapon_flashlight = -1;
showWeaponViewModel = true; showWeaponViewModel = true;
skin = NULL; flashlightModelDefHandle = -1;
skin = NULL;
powerUpSkin = NULL; powerUpSkin = NULL;
baseSkinName = ""; baseSkinName = "";
@ -1214,6 +1228,7 @@ void idPlayer::Init( void ) {
weapon_soulcube = SlotForWeapon( "weapon_soulcube" ); weapon_soulcube = SlotForWeapon( "weapon_soulcube" );
weapon_pda = SlotForWeapon( "weapon_pda" ); weapon_pda = SlotForWeapon( "weapon_pda" );
weapon_fists = SlotForWeapon( "weapon_fists" ); weapon_fists = SlotForWeapon( "weapon_fists" );
weapon_flashlight = SlotForWeapon( "weapon_flashlight" );
showWeaponViewModel = GetUserInfo()->GetBool( "ui_showGun" ); showWeaponViewModel = GetUserInfo()->GetBool( "ui_showGun" );
@ -1411,6 +1426,8 @@ void idPlayer::Init( void ) {
} }
cvarSystem->SetCVarBool( "ui_chat", false ); cvarSystem->SetCVarBool( "ui_chat", false );
SetupFlashlightHolster();
} }
/* /*
@ -2086,6 +2103,10 @@ void idPlayer::Restore( idRestoreGame *savefile ) {
if ( hud ) { if ( hud ) {
hud->SetStateString( "message", "" ); hud->SetStateString( "message", "" );
} }
//Have to do this for loaded games
weapon_flashlight = SlotForWeapon( "weapon_flashlight" );
SetupFlashlightHolster();
} }
/* /*
@ -6211,6 +6232,81 @@ void idPlayer::StartFxOnBone( const char *fx, const char *bone ) {
idEntityFx::StartFx( fx, &offset, &axis, this, true ); idEntityFx::StartFx( fx, &offset, &axis, this, true );
} }
/*
==============
idPlayer::SetupFlashlightSlot
==============
*/
void idPlayer::SetupFlashlightHolster()
{
memset( &flashlightRenderEntity, 0, sizeof( flashlightRenderEntity ) );
flashlightRenderEntity.hModel = renderModelManager->FindModel( "models/items/flashlight/flashlight2_world.lwo" );
if( flashlightRenderEntity.hModel )
{
flashlightRenderEntity.hModel->Reset();
flashlightRenderEntity.bounds = flashlightRenderEntity.hModel->Bounds( &flashlightRenderEntity );
}
flashlightRenderEntity.shaderParms[ SHADERPARM_RED ] = 1.0f;
flashlightRenderEntity.shaderParms[ SHADERPARM_GREEN ] = 1.0f;
flashlightRenderEntity.shaderParms[ SHADERPARM_BLUE ] = 1.0f;
flashlightRenderEntity.shaderParms[ SHADERPARM_ALPHA ] = 0.75f;
flashlightRenderEntity.shaderParms[ SHADERPARM_TIMEOFFSET ] = 0.0f;
flashlightRenderEntity.shaderParms[5] = 0.0f;
flashlightRenderEntity.shaderParms[6] = 0.0f;
flashlightRenderEntity.shaderParms[7] = 0.0f;
}
/*
==============
idPlayer::UpdateFlashlightHolster
==============
*/
void idPlayer::UpdateFlashlightHolster()
{
bool hasFlashlight = !( ( weapon_flashlight < 0 ) || ( inventory.weapons & ( 1 << weapon_flashlight ) ) == 0 );
if( hasFlashlight &&
currentWeapon != weapon_flashlight &&
flashlightRenderEntity.hModel &&
pVRClientInfo != nullptr)
{
idVec3 holsterOffset( pVRClientInfo->flashlightHolsterOffset[2],
pVRClientInfo->flashlightHolsterOffset[0],
pVRClientInfo->flashlightHolsterOffset[1]);
float r[2];
rotateAboutOrigin(holsterOffset.x, holsterOffset.y, viewAngles.yaw - pVRClientInfo->hmdorientation[YAW], r);
holsterOffset.x = -r[0];
holsterOffset.y = -r[1];
holsterOffset *= cvarSystem->GetCVarFloat( "vr_worldscale" );
flashlightRenderEntity.origin = firstPersonViewOrigin + holsterOffset;
flashlightRenderEntity.entityNum = ENTITYNUM_NONE;
flashlightRenderEntity.axis = idAngles(-60, 90, 0).ToMat3() * firstPersonViewAxis;
flashlightRenderEntity.allowSurfaceInViewID = entityNumber + 1;
flashlightRenderEntity.weaponDepthHack = true;
if( flashlightModelDefHandle == -1 )
{
flashlightModelDefHandle = gameRenderWorld->AddEntityDef( &flashlightRenderEntity );
}
else
{
gameRenderWorld->UpdateEntityDef( flashlightModelDefHandle, &flashlightRenderEntity );
}
}
else if (!hasFlashlight || // User hasn't got flashlight yet
currentWeapon == weapon_flashlight)
{
if( flashlightModelDefHandle != -1 )
{
gameRenderWorld->FreeEntityDef( flashlightModelDefHandle );
flashlightModelDefHandle = -1;
}
}
}
/* /*
============== ==============
idPlayer::Think idPlayer::Think
@ -6238,7 +6334,12 @@ void idPlayer::Think( void ) {
if (pVRClientInfo != nullptr) if (pVRClientInfo != nullptr)
{ {
pVRClientInfo->weaponid = currentWeapon; if (inventory.weapons > 1) {
pVRClientInfo->weaponid = currentWeapon;
}
else {
pVRClientInfo->weaponid = -1;
}
cvarSystem->SetCVarBool("vr_weapon_stabilised", pVRClientInfo->weapon_stabilised); cvarSystem->SetCVarBool("vr_weapon_stabilised", pVRClientInfo->weapon_stabilised);
pVRClientInfo->velocitytriggered = (currentWeapon == 11 || // 11 is flashlight pVRClientInfo->velocitytriggered = (currentWeapon == 11 || // 11 is flashlight
currentWeapon == 10); // 10 is chainsaw currentWeapon == 10); // 10 is chainsaw
@ -6377,6 +6478,8 @@ void idPlayer::Think( void ) {
UpdatePowerUps(); UpdatePowerUps();
UpdateFlashlightHolster();
UpdateDeathSkin( false ); UpdateDeathSkin( false );
if ( gameLocal.isMultiplayer ) { if ( gameLocal.isMultiplayer ) {
@ -6794,24 +6897,28 @@ void idPlayer::Damage( idEntity *inflictor, idEntity *attacker, const idVec3 &di
CalcDamagePoints( inflictor, attacker, &damageDef->dict, damageScale, location, &damage, &armorSave ); CalcDamagePoints( inflictor, attacker, &damageDef->dict, damageScale, location, &damage, &armorSave );
// determine knockback // determine knockback
damageDef->dict.GetInt( "knockback", "20", knockback ); if ( vr_knockBack.GetBool() )
{
// determine knockback
damageDef->dict.GetInt("knockback", "20", knockback);
if ( knockback != 0 && !fl.noknockback ) { if (knockback != 0 && !fl.noknockback) {
if ( attacker == this ) { if (attacker == this) {
damageDef->dict.GetFloat( "attackerPushScale", "0", attackerPushScale ); damageDef->dict.GetFloat("attackerPushScale", "0", attackerPushScale);
} else { } else {
attackerPushScale = 1.0f; attackerPushScale = 1.0f;
} }
kick = dir; kick = dir;
kick.Normalize(); kick.Normalize();
kick *= g_knockback.GetFloat() * knockback * attackerPushScale / 200.0f; kick *= g_knockback.GetFloat() * knockback * attackerPushScale / 200.0f;
physicsObj.SetLinearVelocity( physicsObj.GetLinearVelocity() + kick ); physicsObj.SetLinearVelocity(physicsObj.GetLinearVelocity() + kick);
// set the timer so that the player can't cancel out the movement immediately // set the timer so that the player can't cancel out the movement immediately
physicsObj.SetKnockBack( idMath::ClampInt( 50, 200, knockback * 2 ) ); physicsObj.SetKnockBack(idMath::ClampInt(50, 200, knockback * 2));
} }
}
// give feedback on the player view and audibly when armor is helping // give feedback on the player view and audibly when armor is helping
if ( armorSave ) { if ( armorSave ) {
@ -7130,12 +7237,6 @@ Calculate the bobbing position of the view weapon
============== ==============
*/ */
void rotateAboutOrigin(float x, float y, float rotation, float out[2])
{
out[0] = cosf(DEG2RAD(-rotation)) * x + sinf(DEG2RAD(-rotation)) * y;
out[1] = cosf(DEG2RAD(-rotation)) * y - sinf(DEG2RAD(-rotation)) * x;
}
void idPlayer::CalculateViewWeaponPos( bool adjusted, idVec3 &origin, idMat3 &axis, idAngles &angles ) { void idPlayer::CalculateViewWeaponPos( bool adjusted, idVec3 &origin, idMat3 &axis, idAngles &angles ) {
float scale; float scale;
float fracsin; float fracsin;
@ -7173,8 +7274,16 @@ void idPlayer::CalculateViewWeaponPos( bool adjusted, idVec3 &origin, idMat3 &ax
gunpos *= cvarSystem->GetCVarFloat( "vr_worldscale" ); gunpos *= cvarSystem->GetCVarFloat( "vr_worldscale" );
idVec3 gunOfs( g_gun_x.GetFloat(), g_gun_y.GetFloat(), g_gun_z.GetFloat() ); if (currentWeapon == 11) // Flashlight adjustment
origin = viewOrigin + gunpos + (gunOfs * axis); {
idVec3 gunOfs( -14, 9, 20 );
origin = viewOrigin + gunpos + (gunOfs * axis);
}
else
{
idVec3 gunOfs( g_gun_x.GetFloat(), g_gun_y.GetFloat(), g_gun_z.GetFloat() );
origin = viewOrigin + gunpos + (gunOfs * axis);
}
return; return;
} }

View file

@ -221,6 +221,9 @@ public:
class idPlayerView playerView; // handles damage kicks and effects class idPlayerView playerView; // handles damage kicks and effects
renderEntity_t flashlightRenderEntity; // used to present a model to the renderer
qhandle_t flashlightModelDefHandle; // handle to static renderer model
bool noclip; bool noclip;
bool godmode; bool godmode;
@ -270,6 +273,7 @@ public:
int weapon_soulcube; int weapon_soulcube;
int weapon_pda; int weapon_pda;
int weapon_fists; int weapon_fists;
int weapon_flashlight;
int heartRate; int heartRate;
idInterpolate<float> heartInfo; idInterpolate<float> heartInfo;
@ -391,7 +395,11 @@ public:
// use exitEntityNum to specify a teleport with private camera view and delayed exit // use exitEntityNum to specify a teleport with private camera view and delayed exit
virtual void Teleport( const idVec3 &origin, const idAngles &angles, idEntity *destination ); virtual void Teleport( const idVec3 &origin, const idAngles &angles, idEntity *destination );
void Kill( bool delayRespawn, bool nodamage ); virtual void SetupFlashlightHolster();
virtual void UpdateFlashlightHolster();
void Kill( bool delayRespawn, bool nodamage );
virtual void Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location ); virtual void Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
void StartFxOnBone(const char *fx, const char *bone); void StartFxOnBone(const char *fx, const char *bone);

View file

@ -395,20 +395,21 @@ void idPlayerView::CalculateShake() {
idVec3 origin, matrix; idVec3 origin, matrix;
float shakeVolume = gameSoundWorld->CurrentShakeAmplitudeForPosition( gameLocal.time, player->firstPersonViewOrigin ); float shakeVolume = gameSoundWorld->CurrentShakeAmplitudeForPosition( gameLocal.time, player->firstPersonViewOrigin );
// //
// shakeVolume should somehow be molded into an angle here // shakeVolume should somehow be molded into an angle here
// it should be thought of as being in the range 0.0 -> 1.0, although // it should be thought of as being in the range 0.0 -> 1.0, although
// since CurrentShakeAmplitudeForPosition() returns all the shake sounds // since CurrentShakeAmplitudeForPosition() returns all the shake sounds
// the player can hear, it can go over 1.0 too. // the player can hear, it can go over 1.0 too.
// //
shakeAng[0] = gameLocal.random.CRandomFloat() * shakeVolume; shakeAng[0] = gameLocal.random.CRandomFloat() * shakeVolume * vr_shakeAmplitude.GetFloat();
shakeAng[1] = gameLocal.random.CRandomFloat() * shakeVolume; shakeAng[1] = gameLocal.random.CRandomFloat() * shakeVolume * vr_shakeAmplitude.GetFloat();
shakeAng[2] = gameLocal.random.CRandomFloat() * shakeVolume; shakeAng[2] = gameLocal.random.CRandomFloat() * shakeVolume * vr_shakeAmplitude.GetFloat();
if (shakeVolume > 0.05) { if (shakeVolume > 0.1) {
//Shake controllers! //Shake controllers!
common->Vibrate(50, 0, idMath::ClampFloat(0.3, 1.0, (shakeVolume*2.0f + 0.1f))); common->Vibrate(50, 0, idMath::ClampFloat(0.1, 1.0, shakeVolume*2.0f + 0.1f));
common->Vibrate(50, 1, idMath::ClampFloat(0.3, 1.0, (shakeVolume*2.0f + 0.1f))); common->Vibrate(50, 1, idMath::ClampFloat(0.1, 1.0, shakeVolume*2.0f + 0.1f));
} }
} }

View file

@ -343,5 +343,5 @@ idCVar vr_worldscale( "vr_worldscale", "45.0", CVAR_GAME | CVAR_FLOAT | C
idCVar vr_heightoffset( "vr_heightoffset", "0.0", CVAR_GAME | CVAR_FLOAT | CVAR_ARCHIVE, "VR Height Offset" ); idCVar vr_heightoffset( "vr_heightoffset", "0.0", CVAR_GAME | CVAR_FLOAT | CVAR_ARCHIVE, "VR Height Offset" );
idCVar vr_eye( "vr_eye", "0", CVAR_GAME | CVAR_INTEGER, "VR Eye currently being drawn" ); idCVar vr_eye( "vr_eye", "0", CVAR_GAME | CVAR_INTEGER, "VR Eye currently being drawn" );
idCVar vr_control_scheme( "vr_control_scheme", "0", CVAR_GAME | CVAR_INTEGER, "VR Control Scheme: 0 = right handed, 10 = left handed" ); idCVar vr_control_scheme( "vr_control_scheme", "0", CVAR_GAME | CVAR_INTEGER, "VR Control Scheme: 0 = right handed, 10 = left handed" );
idCVar vr_shakeAmplitude( "vr_shakeAmplitude", "0.8", CVAR_FLOAT | CVAR_ARCHIVE, "Screen shake amplitude 0.0 = disabled to 1.0 = full\n", 0.0f, 1.0f );
idCVar vr_knockBack( "vr_knockBack", "0", CVAR_BOOL | CVAR_ARCHIVE | CVAR_GAME, "Enable damage knockback in VR. 0 = Disabled, 1 = Enabled" );

View file

@ -257,6 +257,8 @@ extern idCVar vr_worldscale;
extern idCVar vr_eye; extern idCVar vr_eye;
extern idCVar vr_heightoffset; extern idCVar vr_heightoffset;
extern idCVar vr_control_scheme; extern idCVar vr_control_scheme;
extern idCVar vr_shakeAmplitude;
extern idCVar vr_knockBack;
extern const char *si_gameTypeArgs[]; extern const char *si_gameTypeArgs[];