Skip to content

Commit

Permalink
Added gyroscope support for aiming (#59)
Browse files Browse the repository at this point in the history
* Added some build stuff to git ignore, change "\" to "/" in the paths in
the Makefile. added basic support for motion camera and added some menu
options to turn it on  and off

* removed gyro from the todo list

* changed from quaternions to angularvelocity, since quats made no sense

* Reverted the Makefile to its previous windows-friendly state, rename the
state variable to the more descriptive "motionstate"
  • Loading branch information
jakebriggs authored and Rinnegatamante committed Mar 1, 2018
1 parent 38cd8ca commit 8f4f64e
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 67 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,15 @@ $RECYCLE.BIN/
Network Trash Folder
Temporary Items
.apdisk

# c object files and other build files
*.o
*.elf
build/eboot.bin
build/sce_sys/param.sfo
buildeboot.bin
param.sfo
*.velf
*.vpk


3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GIT_VERSION := $(shell git describe --abbrev=6 --dirty --always --tags)
LIBS = -lvitaGL -lvorbisfile -lvorbis -logg -lspeexdsp -lmpg123 \
-lc -lSceCommonDialog_stub -lSceAudio_stub -lSceLibKernel_stub \
-lSceNet_stub -lSceNetCtl_stub -lpng -lz -lSceDisplay_stub -lSceGxm_stub \
-lSceSysmodule_stub -lSceCtrl_stub -lSceTouch_stub -lm -lSceAppMgr_stub \
-lSceSysmodule_stub -lSceCtrl_stub -lSceTouch_stub -lSceMotion_stub -lm -lSceAppMgr_stub \
-lSceAppUtil_stub -lScePgf_stub -ljpeg -lSceRtc_stub -lScePower_stub

COMMON_OBJS = source/chase.o \
Expand Down Expand Up @@ -103,4 +103,3 @@ $(TARGET).elf: $(OBJS)

clean:
@rm -rf $(TARGET).velf $(TARGET).elf $(OBJS) $(TARGET).elf.unstripped.elf ../$(TARGET).vpk ../build/eboot.bin ../build/sce_sys/param.sfo ./param.sfo

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Priority: HIGH:
- Increase engine limits (FitzQuake's protocol)

Priority: LOW
- Add support to gyroscope.
- Enable multiplayer menu only if the user has WiFi on.
- Add "Performances" submenu.
- Customize joystick's X/Y sensitivity
Expand Down
46 changes: 39 additions & 7 deletions source/in_psp2.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ CVAR (psvita_front_sensitivity_x, 1, CVAR_ARCHIVE | CVAR_PSVITA)
CVAR (psvita_front_sensitivity_y, 0.5, CVAR_ARCHIVE | CVAR_PSVITA)
CVAR (psvita_back_sensitivity_x, 1, CVAR_ARCHIVE | CVAR_PSVITA)
CVAR (psvita_back_sensitivity_y, 0.5, CVAR_ARCHIVE | CVAR_PSVITA)
CVAR (motioncam, 0, CVAR_ARCHIVE | CVAR_PSVITA)
CVAR (motion_sensitivity, 0, CVAR_ARCHIVE | CVAR_PSVITA)

extern cvar_t always_run, inverted;
extern void Log (const char *format, ...);

#define lerp(value, from_max, to_max) ((((value*10) * (to_max*10))/(from_max*10))/10)

uint64_t rumble_tick = 0;
SceCtrlData oldanalogs, analogs;
SceMotionState motionstate;

void IN_Init (void)
{
Expand All @@ -47,12 +51,17 @@ void IN_Init (void)
Cvar_RegisterVariable (&pstv_rumble);
Cvar_RegisterVariable(&psvita_touchmode);

Cvar_RegisterVariable (&motioncam);
Cvar_RegisterVariable (&motion_sensitivity);

//Touchscreen sensitivity
Cvar_RegisterVariable(&psvita_front_sensitivity_x);
Cvar_RegisterVariable(&psvita_front_sensitivity_y);
Cvar_RegisterVariable(&psvita_back_sensitivity_x);
Cvar_RegisterVariable(&psvita_back_sensitivity_y);

sceMotionReset();
sceMotionStartSampling();
}

void IN_ResetInputs(void)
Expand Down Expand Up @@ -112,7 +121,7 @@ void IN_RescaleAnalog(int *x, int *y, int dead) {
float magnitude = sqrt(analogX * analogX + analogY * analogY);
if (magnitude >= deadZone)
{
float scalingFactor = maximum / magnitude * (magnitude - deadZone) / (maximum - deadZone);
float scalingFactor = maximum / magnitude * (magnitude - deadZone) / (maximum - deadZone);
*x = (int) (analogX * scalingFactor);
*y = (int) (analogY * scalingFactor);
} else {
Expand All @@ -133,20 +142,20 @@ void IN_Move (usercmd_t *cmd)
cl_backspeed.value = 200;
cl_sidespeed.value = 300;
}

sceCtrlPeekBufferPositive(0, &analogs, 1);
int left_x = analogs.lx - 127;
int left_y = analogs.ly - 127;
int right_x = analogs.rx - 127;
int right_y = analogs.ry - 127;

// Left analog support for player movement
float x_mov = abs(left_x) < 30 ? 0 : (left_x * cl_sidespeed.value) * 0.01;
float y_mov = abs(left_y) < 30 ? 0 : (left_y * (left_y > 0 ? cl_backspeed.value : cl_forwardspeed.value)) * 0.01;
cmd->forwardmove -= y_mov;
if (gl_xflip.value) cmd->sidemove -= x_mov;
else cmd->sidemove += x_mov;

// Right analog support for camera movement
IN_RescaleAnalog(&right_x, &right_y, 30);
float x_cam = (right_x * sensitivity.value) * 0.008;
Expand All @@ -156,9 +165,9 @@ void IN_Move (usercmd_t *cmd)
V_StopPitchDrift();
if (inverted.value) cl.viewangles[PITCH] -= y_cam;
else cl.viewangles[PITCH] += y_cam;

// TOUCH SUPPORT

// Retrotouch support for camera movement
SceTouchData touch;
if (retrotouch.value){
Expand All @@ -176,7 +185,7 @@ void IN_Move (usercmd_t *cmd)
else cl.viewangles[PITCH] += y_cam;
}
}

if (psvita_touchmode.value == 1)
{
sceTouchPeek(SCE_TOUCH_PORT_FRONT, &touch, 1);
Expand All @@ -194,6 +203,29 @@ void IN_Move (usercmd_t *cmd)
}
}

// gyro analog support for camera movement

if (motioncam.value){
sceMotionGetState(&motionstate);

// not sure why YAW or the horizontal x axis is the controlled by angularVelocity.y
// and the PITCH or the vertical y axis is controlled by angularVelocity.x but its what seems to work
float x_gyro_cam = motionstate.angularVelocity.y * motion_sensitivity.value;
float y_gyro_cam = motionstate.angularVelocity.x * motion_sensitivity.value;

if (gl_xflip.value)
cl.viewangles[YAW] -= x_gyro_cam;
else
cl.viewangles[YAW] += x_gyro_cam;

V_StopPitchDrift();

if (inverted.value)
cl.viewangles[PITCH] += y_gyro_cam;
else
cl.viewangles[PITCH] -= y_gyro_cam;
}

if (pq_fullpitch.value)
cl.viewangles[PITCH] = COM_Clamp(cl.viewangles[PITCH], -90, 90);
else
Expand Down
Loading

0 comments on commit 8f4f64e

Please sign in to comment.