Skip to content

Commit

Permalink
Disable velocity triggered punch when weapon two handed
Browse files Browse the repository at this point in the history
also reintroduced roll when two handed weapon
  • Loading branch information
DrBeef committed Apr 19, 2021
1 parent b1cd3ac commit 1711b12
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 107 deletions.
140 changes: 50 additions & 90 deletions Projects/Android/jni/Doom3Quest/VrInputDefault.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,61 +226,34 @@ void HandleInput_Default( int controlscheme, int switchsticks, ovrInputStateGame

//Turn on weapon stabilisation?
bool stabilised = false;
if (!pVRClientInfo->oneHandOnly && // Don't stabilise pistols
if (!pVRClientInfo->oneHandOnly &&
(pOffTrackedRemoteNew->Buttons & ovrButton_GripTrigger) && (distance < STABILISATION_DISTANCE))
{
stabilised = true;
}

pVRClientInfo->weapon_stabilised = stabilised;

//dominant hand stuff first
{
//Record recent weapon position for trajectory based stuff
/*
for (int i = (NUM_WEAPON_SAMPLES-1); i != 0; --i)
{
VectorCopy(pVRClientInfo->weaponoffset_history[i-1], pVRClientInfo->weaponoffset_history[i]);
pVRClientInfo->weaponoffset_history_timestamp[i] = pVRClientInfo->weaponoffset_history_timestamp[i-1];
}
VectorCopy(pVRClientInfo->current_weaponoffset, pVRClientInfo->weaponoffset_history[0]);
pVRClientInfo->weaponoffset_history_timestamp[0] = pVRClientInfo->current_weaponoffset_timestamp;
///Weapon location relative to view
pVRClientInfo->current_weaponoffset[0] = pWeapon->HeadPose.Pose.Position.x - pVRClientInfo->hmdposition[0];
pVRClientInfo->current_weaponoffset[1] = pWeapon->HeadPose.Pose.Position.y - pVRClientInfo->hmdposition[1];
pVRClientInfo->current_weaponoffset[2] = pWeapon->HeadPose.Pose.Position.z - pVRClientInfo->hmdposition[2];
pVRClientInfo->current_weaponoffset_timestamp = Sys_Milliseconds( );
{
//Caclulate speed between two historic controller position readings
float distance = VectorDistance(pVRClientInfo->weaponoffset_history[NEWER_READING], pVRClientInfo->weaponoffset_history[OLDER_READING]);
float t = pVRClientInfo->weaponoffset_history_timestamp[NEWER_READING] - pVRClientInfo->weaponoffset_history_timestamp[OLDER_READING];
pVRClientInfo->throw_power = distance / (t/(float)1000.0);
//Calculate trajectory
VectorSubtract(pVRClientInfo->weaponoffset_history[NEWER_READING], pVRClientInfo->weaponoffset_history[OLDER_READING], pVRClientInfo->throw_trajectory);
VectorNormalize( pVRClientInfo->throw_trajectory );
//Set origin to the newer reading offset
VectorCopy(pVRClientInfo->weaponoffset_history[NEWER_READING], pVRClientInfo->throw_origin);
}*/

//Does weapon velocity trigger attack (knife) and is it fast enough
//Does weapon velocity trigger attack and is it fast enough
static bool velocityTriggeredAttack = false;
if (pVRClientInfo->velocitytriggered)
{
static bool fired = false;
float velocity = sqrtf(powf(pWeapon->HeadPose.LinearVelocity.x, 2) +
powf(pWeapon->HeadPose.LinearVelocity.y, 2) +
powf(pWeapon->HeadPose.LinearVelocity.z, 2));

velocityTriggeredAttack = (velocity > VELOCITY_TRIGGER);

if (fired != velocityTriggeredAttack) {
ALOGV("**WEAPON EVENT** velocity triggered %s", velocityTriggeredAttack ? "+attack" : "-attack");
Android_ButtonChange(UB_ATTACK, velocityTriggeredAttack ? 1 : 0);
fired = velocityTriggeredAttack;
//velocity trigger only available if weapon is not stabilised with off-hand
if (!pVRClientInfo->weapon_stabilised) {
static bool fired = false;
float velocity = sqrtf(powf(pWeapon->HeadPose.LinearVelocity.x, 2) +
powf(pWeapon->HeadPose.LinearVelocity.y, 2) +
powf(pWeapon->HeadPose.LinearVelocity.z, 2));

velocityTriggeredAttack = (velocity > VELOCITY_TRIGGER);

if (fired != velocityTriggeredAttack) {
ALOGV("**WEAPON EVENT** velocity triggered %s",
velocityTriggeredAttack ? "+attack" : "-attack");
Android_ButtonChange(UB_ATTACK, velocityTriggeredAttack ? 1 : 0);
fired = velocityTriggeredAttack;
}
}
}
else if (velocityTriggeredAttack)
Expand All @@ -291,24 +264,30 @@ void HandleInput_Default( int controlscheme, int switchsticks, ovrInputStateGame
Android_ButtonChange(UB_ATTACK, velocityTriggeredAttack ? 1 : 0);
}

//Does weapon velocity trigger attack (knife) and is it fast enough
static bool velocityTriggeredAttackOffHand = false;
pVRClientInfo->velocitytriggeredoffhandstate = false;
if (pVRClientInfo->velocitytriggeredoffhand)
{
static bool firedOffHand = false;
float velocity = sqrtf(powf(pOff->HeadPose.LinearVelocity.x, 2) +
powf(pOff->HeadPose.LinearVelocity.y, 2) +
powf(pOff->HeadPose.LinearVelocity.z, 2));

velocityTriggeredAttackOffHand = (velocity > VELOCITY_TRIGGER);

if (firedOffHand != velocityTriggeredAttackOffHand) {
ALOGV("**WEAPON EVENT** velocity triggered (offhand) %s", velocityTriggeredAttackOffHand ? "+attack" : "-attack");
//Android_ButtonChange(UB_IMPULSE37, velocityTriggeredAttackOffHand ? 1 : 0);
//Android_SetImpulse(UB_IMPULSE37);
pVRClientInfo->velocitytriggeredoffhandstate = true;
firedOffHand = velocityTriggeredAttackOffHand;
//velocity trigger only available if weapon is not stabilised with off-hand
if (!pVRClientInfo->weapon_stabilised) {
float velocity = sqrtf(powf(pOff->HeadPose.LinearVelocity.x, 2) +
powf(pOff->HeadPose.LinearVelocity.y, 2) +
powf(pOff->HeadPose.LinearVelocity.z, 2));

velocityTriggeredAttackOffHand = (velocity > VELOCITY_TRIGGER);

if (firedOffHand != velocityTriggeredAttackOffHand) {
ALOGV("**WEAPON EVENT** velocity triggered (offhand) %s",
velocityTriggeredAttackOffHand ? "+attack" : "-attack");
//Android_ButtonChange(UB_IMPULSE37, velocityTriggeredAttackOffHand ? 1 : 0);
//Android_SetImpulse(UB_IMPULSE37);
pVRClientInfo->velocitytriggeredoffhandstate = firedOffHand;
firedOffHand = velocityTriggeredAttackOffHand;
}
}
else {
firedOffHand = false;
}
}
else //GB This actually nevers gets run currently as we are always returning true for pVRClientInfo->velocitytriggeredoffhand (but we might not in the future when weapons are sorted)
Expand All @@ -319,43 +298,24 @@ void HandleInput_Default( int controlscheme, int switchsticks, ovrInputStateGame
//Android_ButtonChange(UB_IMPULSE37, velocityTriggeredAttackOffHand ? 1 : 0);
pVRClientInfo->velocitytriggeredoffhandstate = false;
}
}

/*if (pVRClientInfo->weapon_stabilised)
{
{
float x = pOff->HeadPose.Pose.Position.x - pWeapon->HeadPose.Pose.Position.x;
float y = pOff->HeadPose.Pose.Position.y - pWeapon->HeadPose.Pose.Position.y;
float z = pOff->HeadPose.Pose.Position.z - pWeapon->HeadPose.Pose.Position.z;
float zxDist = length(x, z);
if (zxDist != 0.0f && z != 0.0f) {
{
VectorSet(pVRClientInfo->weaponangles, -degrees(atanf(y / zxDist)),
-degrees(atan2f(x, -z)), pVRClientInfo->weaponangles[ROLL] / 2.0f); //Dampen roll on stabilised weapon
}
}
}
}*/



dominantGripPushed = (pDominantTrackedRemoteNew->Buttons &
ovrButton_GripTrigger) != 0;
dominantGripPushed = (pDominantTrackedRemoteNew->Buttons &
ovrButton_GripTrigger) != 0;

if (dominantGripPushed) {
if (dominantGripPushTime == 0) {
dominantGripPushTime = GetTimeInMilliSeconds();
}
if (dominantGripPushed) {
if (dominantGripPushTime == 0) {
dominantGripPushTime = GetTimeInMilliSeconds();
}
else
{
if ((GetTimeInMilliSeconds() - dominantGripPushTime) < vr_reloadtimeoutms) {
//Reload
Android_SetImpulse(UB_IMPULSE13);
}

dominantGripPushTime = 0;
}
else
{
if ((GetTimeInMilliSeconds() - dominantGripPushTime) < vr_reloadtimeoutms) {
//Reload
Android_SetImpulse(UB_IMPULSE13);
}

dominantGripPushTime = 0;
}

float controllerYawHeading = 0.0f;
Expand Down
28 changes: 13 additions & 15 deletions Projects/Android/jni/d3es-multithread-master/neo/game/Vr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ idCVar vr_jumpBounce( "vr_jumpBounce", "0", CVAR_FLOAT | CVAR_ARCHIVE | CVAR_GAM
idCVar vr_stepSmooth( "vr_stepSmooth", "1", CVAR_FLOAT | CVAR_ARCHIVE | CVAR_GAME, "Enable smoothing when climbing stairs. 0 = Disabled, 1 = Full", 0.0f, 1.0f ); // Carl

//Added to menu - needs testing
idCVar vr_walkSpeedAdjust( "vr_walkSpeedAdjust", "0", CVAR_FLOAT | CVAR_ARCHIVE, "Player walk speed adjustment in VR. (slow down default movement)" );
idCVar vr_walkSpeedAdjust( "vr_walkSpeedAdjust", "20", CVAR_FLOAT | CVAR_ARCHIVE, "Player walk speed adjustment for VR" );

//What is this??
idCVar vr_headbbox( "vr_headbbox", "10.0", CVAR_FLOAT | CVAR_ARCHIVE, "" );
Expand Down Expand Up @@ -633,10 +633,10 @@ void iVr::HMDGetOrientation( idAngles &hmdAngles, idVec3 &headPositionDelta, idV
pVRClientInfo->rhand_orientation_quat[3]);


commonVr->handPose[1].Orientation = _lhandOrientation;
commonVr->handPose[1].Position = _lhandPosition;
commonVr->handPose[0].Orientation = _rhandOrientation;
commonVr->handPose[0].Position = _rhandPosition;
handPose[1].Orientation = _lhandOrientation;
handPose[1].Position = _lhandPosition;
handPose[0].Orientation = _rhandOrientation;
handPose[0].Position = _rhandPosition;

for (int i = 0; i < 2; i++)
{
Expand Down Expand Up @@ -898,15 +898,19 @@ void iVr::MotionControlGetTouchController( int hand, idVec3 &motionPosition, idQ
static idAngles poseAngles = ang_zero;
static idAngles angTemp = ang_zero;

motionPosition.x = -handPose[hand].Position.z * (100.0f / 2.54f) / vr_scale.GetFloat();// Koz convert position (in meters) to inch (1 id unit = 1 inch).
poseRot.x = handPose[hand].Orientation.z; // x;
poseRot.y = handPose[hand].Orientation.x; // y;
poseRot.z = -handPose[hand].Orientation.y; // z;
poseRot.w = handPose[hand].Orientation.w;

motionPosition.x = -handPose[hand].Position.z * (100.0f / 2.54f) / vr_scale.GetFloat();// Koz convert position (in meters) to inch (1 id unit = 1 inch).
motionPosition.y = -handPose[hand].Position.x * (100.0f / 2.54f) / vr_scale.GetFloat();
motionPosition.z = handPose[hand].Position.y * (100.0f / 2.54f) / vr_scale.GetFloat();
motionPosition -= trackingOriginOffset;
motionPosition *= idAngles( 0.0f, (-trackingOriginYawOffset), 0.0f ).ToMat3();
motionPosition -= commonVr->hmdBodyTranslation;

if (pVRClientInfo != NULL &&
pVRClientInfo->weapon_stabilised &&
if (GetWeaponStabilised() &&
hand == vr_weaponHand.GetInteger()) {
idVec3 offHandPosition;
offHandPosition.x = -handPose[1 - hand].Position.z * (100.0f / 2.54f) / vr_scale.GetFloat();// Koz convert position (in meters) to inch (1 id unit = 1 inch).
Expand All @@ -918,14 +922,8 @@ void iVr::MotionControlGetTouchController( int hand, idVec3 &motionPosition, idQ

poseAngles = (offHandPosition - motionPosition).ToAngles();

angTemp.Set(poseAngles.pitch, poseAngles.yaw, poseAngles.roll);
angTemp.Set(poseAngles.pitch, poseAngles.yaw, poseRot.ToAngles().roll);
} else {

poseRot.x = handPose[hand].Orientation.z; // x;
poseRot.y = handPose[hand].Orientation.x; // y;
poseRot.z = -handPose[hand].Orientation.y; // z;
poseRot.w = handPose[hand].Orientation.w;

poseAngles = poseRot.ToAngles();

angTemp.Set(poseAngles.pitch, poseAngles.yaw, poseAngles.roll);
Expand Down
Binary file modified assets/pak399.pk4
Binary file not shown.
2 changes: 1 addition & 1 deletion assets/quest1_default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ seta vr_pdaPosZ "5.0"
seta vr_pdaPosY "4.0"
seta vr_pdaPosX "6.0"
seta vr_headbbox "10.0"
seta vr_walkSpeedAdjust "0.0"
seta vr_walkSpeedAdjust "20.0"
seta vr_stepSmooth "1"
seta vr_jumpBounce "0"
seta vr_3dgui "1"
Expand Down
2 changes: 1 addition & 1 deletion assets/quest2_default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ seta vr_pdaPosZ "5.0"
seta vr_pdaPosY "4.0"
seta vr_pdaPosX "6.0"
seta vr_headbbox "10.0"
seta vr_walkSpeedAdjust "0.0"
seta vr_walkSpeedAdjust "20.0"
seta vr_stepSmooth "1"
seta vr_jumpBounce "0"
seta vr_3dgui "1"
Expand Down

0 comments on commit 1711b12

Please sign in to comment.