3D GMS2 Virtual Reality (Mobile device) camera look

Discussion in 'Programming' started by jtmx, Jul 13, 2019 at 5:01 PM.

  1. jtmx

    jtmx Member

    Joined:
    Oct 1, 2016
    Posts:
    19
    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);
     
  2. jtmx

    jtmx Member

    Joined:
    Oct 1, 2016
    Posts:
    19
    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
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice