Sniper rifle work...

already working pretty well!
This commit is contained in:
Simon 2020-07-09 23:53:06 +01:00
parent 79f9d36d70
commit 7902c68107
8 changed files with 85 additions and 22 deletions

View file

@ -1294,6 +1294,7 @@ void RTCWVR_Init()
positional_movementSideways = 0.0f;
positional_movementForward = 0.0f;
snapTurn = 0.0f;
scopeEngaged = qfalse;
ducked = DUCK_NOTDUCKED;
RTCWVR_ResyncClientYawWithGameYaw();

View file

@ -7,6 +7,8 @@
//New control scheme definitions to be defined L1VR_SurfaceView.c enumeration
enum control_scheme;
#define SCOPE_ENGAGE_DISTANCE 0.28
ovrInputStateTrackedRemote leftTrackedRemoteState_old;
ovrInputStateTrackedRemote leftTrackedRemoteState_new;
ovrTracking leftRemoteTracking_new;
@ -23,6 +25,7 @@ float remote_movementUp;
float positional_movementSideways;
float positional_movementForward;
float snapTurn;
qboolean scopeEngaged;
void sendButtonAction(const char* action, long buttonDown);
void sendButtonActionSimple(const char* action);
@ -33,5 +36,6 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
ovrInputStateTrackedRemote *pOffTrackedRemoteNew, ovrInputStateTrackedRemote *pOffTrackedRemoteOld, ovrTracking* pOffTracking,
int domButton1, int domButton2, int offButton1, int offButton2 );
void updateScopeAngles(float forwardYaw);
#endif //vrinput_h

View file

@ -122,6 +122,39 @@ void acquireTrackedRemotesData(const ovrMobile *Ovr, double displayTime) {//The
}
}
//YAW: Left increase, Right decrease
void updateScopeAngles(float forwardYaw)
{
//Bit of a hack, but use weapon orientation / position for view when scope is engaged
static vec3_t currentScopeAngles;
static vec3_t lastScopeAngles;
if (scopeEngaged)
{
//Set Position
VectorSet(vr.hmdposition, vr.hmdposition[0] + vr.weaponoffset[0], vr.hmdposition[1] + vr.weaponoffset[1], vr.hmdposition[2] + vr.weaponoffset[2]);
VectorSet(vr.weaponoffset, 0, 0, 0);
//Lerp the weapon angles to smooth out shaky hands a bit
vec3_t angles;
VectorSet(angles, vr.weaponangles[PITCH], vr.weaponangles[YAW] - forwardYaw, vr.hmdorientation[ROLL]);
VectorLerp(currentScopeAngles, 0.125, angles, currentScopeAngles);
//Set "view" Angles
VectorCopy(currentScopeAngles, vr.hmdorientation);
//Orientation
VectorSubtract(lastScopeAngles, currentScopeAngles, vr.hmdorientation_delta);
//Keep this for our records
VectorCopy(currentScopeAngles, lastScopeAngles);
} else {
VectorSet(currentScopeAngles, vr.weaponangles[PITCH], vr.weaponangles[YAW], vr.hmdorientation[ROLL]);
VectorCopy(currentScopeAngles, lastScopeAngles);
}
}
void PortableMouseAbs(float x,float y);
inline float clamp(float _min, float _val, float _max)
{

View file

@ -61,6 +61,11 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
}
static float forwardYaw = 0;
if (scopeEngaged)
{
//forwardYaw = (cl.viewangles[YAW] - vr.hmdorientation[YAW]);
}
//Menu button
handleTrackedControllerButton(&leftTrackedRemoteState_new, &leftTrackedRemoteState_old, ovrButton_Enter, K_ESCAPE);
@ -110,6 +115,10 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
powf(pOffTracking->HeadPose.Pose.Position.y - pDominantTracking->HeadPose.Pose.Position.y, 2) +
powf(pOffTracking->HeadPose.Pose.Position.z - pDominantTracking->HeadPose.Pose.Position.z, 2));
float distanceToHMD = sqrtf(powf(vr.hmdposition[0] - pDominantTracking->HeadPose.Pose.Position.x, 2) +
powf(vr.hmdposition[1] - pDominantTracking->HeadPose.Pose.Position.y, 2) +
powf(vr.hmdposition[2] - pDominantTracking->HeadPose.Pose.Position.z, 2));
//Turn on weapon stabilisation?
if ((pOffTrackedRemoteNew->Buttons & ovrButton_GripTrigger) !=
(pOffTrackedRemoteOld->Buttons & ovrButton_GripTrigger)) {
@ -127,6 +136,19 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
}
}
//Engage scope if conditions are right
if (vr.weapon_stabilised && !scopeEngaged && distanceToHMD < SCOPE_ENGAGE_DISTANCE)
{
scopeEngaged = qtrue;
sendButtonActionSimple("weapalt");
}
else if (scopeEngaged && (distanceToHMD > SCOPE_ENGAGE_DISTANCE || !vr.weapon_stabilised))
{
scopeEngaged = qfalse;
sendButtonActionSimple("weapalt");
RTCWVR_ResyncClientYawWithGameYaw();
}
//dominant hand stuff first
{
///Weapon location relative to view
@ -185,7 +207,7 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
} else{
if (dominantGripPushed) {
//Initiate crowbar from backpack mode
sendButtonActionSimple("weapon0");
sendButtonActionSimple("weapon 0");
int channel = (vr_control_scheme->integer >= 10) ? 0 : 1;
RTCWVR_Vibrate(80, channel, 0.8); // vibrate to let user know they switched
grabMeleeWeapon = 1;
@ -216,7 +238,7 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
}
else
{
controllerYawHeading = 0.0f;//-cl.viewangles[YAW];
controllerYawHeading = 0.0f;
}
}
@ -251,10 +273,11 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
if (!firingPrimary && dominantGripPushed && (GetTimeInMilliSeconds() - dominantGripPushTime) > vr_reloadtimeoutms->integer)
{
//Fire Secondary
if ((pDominantTrackedRemoteNew->Buttons & ovrButton_Trigger) !=
(pDominantTrackedRemoteOld->Buttons & ovrButton_Trigger)) {
sendButtonAction("+attack2", (pDominantTrackedRemoteNew->Buttons & ovrButton_Trigger));
if (((pDominantTrackedRemoteNew->Buttons & ovrButton_Trigger) !=
(pDominantTrackedRemoteOld->Buttons & ovrButton_Trigger))
&& (pDominantTrackedRemoteNew->Buttons & ovrButton_Trigger))
{
//sendButtonActionSimple("weapalt");
}
}
else
@ -269,9 +292,9 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
// we need to release secondary fire if dominantGripPushed has been released before releasing trigger -> should fix the gun jamming and non stop firing secondary attack bug
if ((pDominantTrackedRemoteNew->Buttons & ovrButton_Trigger) !=
(pDominantTrackedRemoteOld->Buttons & ovrButton_Trigger) &&
(pDominantTrackedRemoteNew->Buttons& ovrButton_Trigger) == false)
(pDominantTrackedRemoteNew->Buttons & ovrButton_Trigger) == false)
{
sendButtonAction("+attack2", false);
//sendButtonActionSimple("weapalt");
}
}
@ -292,11 +315,11 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
if (!itemSwitched) {
if (between(0.8f, pDominantTrackedRemoteNew->Joystick.y, 1.0f))
{
sendButtonActionSimple("weapprev");
sendButtonActionSimple("weapnext");
}
else
{
sendButtonActionSimple("weapnext");
sendButtonActionSimple("weapprev");
}
itemSwitched = true;
}
@ -435,6 +458,8 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
decreaseSnap = true;
}
}
updateScopeAngles(forwardYaw);
}
//Save state

View file

@ -3390,7 +3390,9 @@ static void CG_Draw2D( void ) {
// don't draw any status if dead
if ( cg.snap->ps.stats[STAT_HEALTH] > 0 ) {
// CG_DrawCrosshair();
if (cg.zoomedScope) {
CG_DrawCrosshair();
}
if ( cg_drawStatus.integer ) {
Menu_PaintAll();

View file

@ -2677,7 +2677,7 @@ static void FS_AddGameDirectory( const char *path, const char *dir ) {
}
qsort( sorted, numfiles, 4, paksort );
qsort( sorted, numfiles, sizeof(char*), paksort );
for ( i = 0 ; i < numfiles ; i++ ) {

View file

@ -30,6 +30,7 @@ If you have questions concerning this license or the applicable additional terms
#include <src/client/client.h>
#include "tr_local.h"
#include "../../../RTCWVR/VrClientInfo.h"
#include "../../../RTCWVR/VrInput.h"
int r_firstSceneDrawSurf;
@ -536,7 +537,7 @@ void RE_RenderScene( const refdef_t *fd ) {
static float yaw = 0;
static long long lastFrameIndex = 0;
long long frameIndex = RTCWVR_getFrameIndex();
if ((RTCWVR_useScreenLayer() || resyncClientYawWithGameYaw > 0))
if ((RTCWVR_useScreenLayer() || resyncClientYawWithGameYaw > 0 || scopeEngaged))
{
//Resyncing with known game yaw
yaw = fd->viewangles[YAW];

View file

@ -163,25 +163,22 @@ import static android.system.Os.setenv;
checkPermissionsAndInitialize();
}
public void create()
{
public void create() {
//Configuration files
copy_asset("/sdcard/RTCWQuest", "config.cfg");
copy_asset("/sdcard/RTCWQuest", "autoexec.cfg");
copy_asset("/sdcard/RTCWQuest", "commandline.txt");
//Read these from a file and pass through
commandLineParams = new String("rtcw");
//See if user is trying to use command line params
if(new File("/sdcard/RTCWQuest/commandline.txt").exists()) // should exist!
if (new File("/sdcard/RTCWQuest/commandline.txt").exists()) // should exist!
{
BufferedReader br;
try {
br = new BufferedReader(new FileReader("/sdcard/RTCWQuest/commandline.txt"));
String s;
StringBuilder sb=new StringBuilder(0);
while ((s=br.readLine())!=null)
StringBuilder sb = new StringBuilder(0);
while ((s = br.readLine()) != null)
sb.append(s + " ");
br.close();
@ -196,7 +193,7 @@ import static android.system.Os.setenv;
}
try {
setenv("RTCW_GAMELIBDIR", getFilesDir().getParentFile().getPath() + "/lib", true);
setenv("RTCW_GAMELIBDIR", getApplicationInfo().nativeLibraryDir, true);
}
catch (Exception e)
{
@ -205,7 +202,7 @@ import static android.system.Os.setenv;
mNativeHandle = GLES3JNILib.onCreate( this, commandLineParams );
}
public void copy_asset(String path, String name) {
File f = new File(path + "/" + name);
if (!f.exists()) {