3D GMS2 Virtual Reality (Mobile device) camera look

jtmx

Member
Hello all,

I'm working on a virtual reality game for mobile devices and I'm trying to get the game camera to pitch, yaw and roll with the device's gyroscope using device_get_tilt_* functions. I've come across an issue though, the game camera's pitch (device_get_tilt_z) moves up and down with the phone however the yaw (device_get_tilt_y) doesn't appear to work and I can't figure how to implement the camera roll/tilt. Any help on how to do this would be greatly appreciated.

obj_camera Create
Code:
// Setup
gpu_set_ztestenable(true);
gpu_set_zwriteenable(true);
// Camera
view_enabled = true;
view_visible[0] = true;
view_xport[0] = 0;
view_yport[0] = 0;
view_wport[0] = 640;
view_hport[0] = 360;
global.cam_main = camera_create();
projection_matrix = matrix_build_projection_perspective_fov(90,view_get_wport(0) / view_get_hport(0),1,32000);
camera_set_proj_mat(global.cam_main,projection_matrix);
view_set_camera(0,global.cam_main);
cam_pitch = 0;
cam_yaw = 0;
cam_roll = 0;
cam_z = - 56;
obj_camera Step
Code:
// Set camera vars
cam_pitch = - round(clamp(device_get_tilt_z() * 90,- 89,89));
cam_yaw = round(device_get_tilt_y() * 90);
// Update camera
var cam_matrix = matrix_build_lookat(x,y,cam_z,
x + dcos(cam_yaw),y - dsin(cam_yaw),cam_z - dtan(cam_pitch),0,0,1);
camera_set_view_mat(global.cam_main,cam_matrix);
 

jtmx

Member
just discovered an issue:
the device_get_tilt_y/cam_yaw is only changing properly when the device is on a flat surface making device_get_tilt_z = 0
 
Top