• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

3D GMS2 Virtual Reality (Mobile device) camera look

J

jtmx

Guest
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);
 
J

jtmx

Guest
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