Disable velocity triggered punch when weapon two handed

also reintroduced roll when two handed weapon
This commit is contained in:
Simon 2021-04-19 21:42:51 +01:00
parent b1cd3ac905
commit 1711b1286c
5 changed files with 61 additions and 103 deletions

View file

@ -226,7 +226,7 @@ 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;
@ -234,53 +234,26 @@ void HandleInput_Default( int controlscheme, int switchsticks, ovrInputStateGame
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));
//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);
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;
if (fired != velocityTriggeredAttack) {
ALOGV("**WEAPON EVENT** velocity triggered %s",
velocityTriggeredAttack ? "+attack" : "-attack");
Android_ButtonChange(UB_ATTACK, velocityTriggeredAttack ? 1 : 0);
fired = velocityTriggeredAttack;
}
}
}
else if (velocityTriggeredAttack)
@ -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));
//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);
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;
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)
@ -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);
dominantGripPushed = (pDominantTrackedRemoteNew->Buttons &
ovrButton_GripTrigger) != 0;
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;
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;

View file

@ -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, "" );
@ -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++)
{
@ -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).
@ -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);

Binary file not shown.

View file

@ -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"

View file

@ -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"