Screen rotation (No Android)

Discussion in 'Programming' started by josyanf1, Oct 30, 2018.

  1. josyanf1

    josyanf1 Member

    Joined:
    Jan 12, 2018
    Posts:
    17
    Hello everyone!
    I'm doing a vertical shump and I would like to know how to rotate the screen vertically (TATE Mode) so that it is like the Ikaruga of Nintendo Switch.
    I tried with image_angle, but the GUI does not rotate and also the black bands on the sides cover what is missing from the screen. Thanks in advance!
     

    Attached Files:

  2. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,405
    Do you mean view_angle? If your GUI is drawn in Draw GUI event, it should behave fine. You could also draw application_surface yourself while rotating it via draw_surface_ext
     
  3. josyanf1

    josyanf1 Member

    Joined:
    Jan 12, 2018
    Posts:
    17
    Yes, view_angle sry. But I still have the same problem. When I go from horizontal to vertical, only the sprites rotate, the screen and the GUI do not change.
     

    Attached Files:

  4. icuurd12b42

    icuurd12b42 TMC Founder GMC Elder

    Joined:
    Apr 22, 2016
    Posts:
    1,839
    you can try to apply the view transform matrix to the gui draw.

    I'm sure a few lines of code would do... build projection matrix from view matrix, apply projection matrix to the drawing, draw gui...
     
  5. josyanf1

    josyanf1 Member

    Joined:
    Jan 12, 2018
    Posts:
    17
    I do not understand very well what you mean.
     
  6. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,405
    You should be able to rotate the GUI layer by doing
    Code:
    d3d_set_projection_ortho(0, 0, <gui width>, <gui height>, <angle>)
    prior to drawing. In GMS2, the function is replaced by a script of kind
    Code:
    /// @description d3d - set orthographic
    /// @param x       x of tl corner
    /// @param y       y of tl corner
    /// @param w       w of view
    /// @param h       h of view
    /// @param angle   rotation angle of the projection
    
    var xx = argument0;
    var yy = argument1;
    var ww = argument2;
    var hh = argument3;
    var angle = argument4;
    
    var mV = matrix_build_lookat( xx+ww/2, yy+hh/2, -16000,
                                 xx+ww/2, yy+hh/2, 0,
                                dsin(-angle), dcos(-angle), 0 );
    var mP = matrix_build_projection_ortho( ww, hh, 1, 32000 );
    
    //camera_set_view_mat( global.__d3dCamera, mV );
    //camera_set_proj_mat( global.__d3dCamera, mP );
    //camera_apply( global.__d3dCamera );
    camera_set_view_mat( camera_get_active(), mV );
    camera_set_proj_mat( camera_get_active(), mP );
    camera_apply( camera_get_active() );
     
  7. icuurd12b42

    icuurd12b42 TMC Founder GMC Elder

    Joined:
    Apr 22, 2016
    Posts:
    1,839
    ^there, I was too lazy to code that :)

    perfect example of why
    d3d_set_projection_ortho
    should never have been taken out

    all it needs is your draw gui... the drawing will be rotated on the draw without needing to change anything (hopefully)
     
  8. josyanf1

    josyanf1 Member

    Joined:
    Jan 12, 2018
    Posts:
    17
    It seems that that is the solution. The problem is that I think my options are interfering. (Excuse me, I'm new to the subject of the surfaces :p)

    This way I have my control object configured:

    Step Event:
    Code:
    ///Shader
    if shader_option = true
    {
    application_surface_draw_enable(false)
    
    shader_to_use = sh_CRT_Windows
    
    crt_surface_scale = 1;
    
    crt_surface_width  = view_wview[0] * crt_surface_scale;
    crt_surface_height = view_hview[0] * crt_surface_scale;
    
    uni_crt_sizes = shader_get_uniform(shader_to_use, "u_crt_sizes");
    distort = shader_get_uniform(shader_to_use, "distort");
    distortion = shader_get_uniform(shader_to_use, "distortion");
    border = shader_get_uniform(shader_to_use, "border");
    
    var_distort = true;
    var_distortion_ammount = 0.12;
    var_border = true;
    
    surface_width  = view_wview[0];
    surface_height = view_hview[0];
    
    surface_resize(application_surface, surface_width, surface_height);
    }
    else
    {
    application_surface_draw_enable(true)
    surface_resize(application_surface, 704, 896)
    }
    Draw GUI Begin:
    Code:
    display_set_gui_size(176,224)
    
    //Shader
    if shader_option = true
    {surface_set_target(application_surface)}
    
    Draw GUI End:
    Code:
    ///Shader
    if shader_option = true
    {
    surface_reset_target();
    shader_set(shader_to_use);
      shader_set_uniform_f(uni_crt_sizes, surface_width, surface_height,crt_surface_width, crt_surface_height);
      shader_set_uniform_f(distort, var_distort);
      shader_set_uniform_f(distortion, var_distortion_ammount);
      shader_set_uniform_f(border, var_border);
      draw_surface_part_ext(application_surface, 0, 0, view_wview[0], view_hview[0], 0, 0, crt_surface_scale, crt_surface_scale, c_white, 1);
    shader_reset()
    }
    Sorry for being so heavy and thanks for the patience ":p
     
  9. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,405
    With shader_option on, you'd be calling the function after surface_set_target and before drawing anything, and that should be fine.
     
  10. icuurd12b42

    icuurd12b42 TMC Founder GMC Elder

    Joined:
    Apr 22, 2016
    Posts:
    1,839
    quick note on you resizing the application surface each step

    else
    {
    application_surface_draw_enable(true)
    surface_resize(application_surface, 704, 896)
    }

    this is very costly... even sizing to the same size. check if the surface is not the right size first.
     
  11. josyanf1

    josyanf1 Member

    Joined:
    Jan 12, 2018
    Posts:
    17
    I resize the surface because the shader leaves it very small. I would like the shader to use the resolution I have in port on screen (x3 of the base resolution) to be able to rotate sprite without going bad etc
     
  12. josyanf1

    josyanf1 Member

    Joined:
    Jan 12, 2018
    Posts:
    17
    Now rotate the GUI without problems, what happens now is that for some reason I do not draw outside the margin of the screen. I have to give more resolution to the sides with some function?

    *If the 90º drawing is not visible because it is off the screen. I've drawn it to 200º so you can see what I mean.
     

    Attached Files:

  13. icuurd12b42

    icuurd12b42 TMC Founder GMC Elder

    Joined:
    Apr 22, 2016
    Posts:
    1,839
    yeah but you are resizing every frame even if it's the right size... don't

    if(surface_get_width (application_surface) != 704 || surface_get_height (application_surface) != 896)
    {
    surface_resize(application_surface, 704, 896)
    }
     
  14. josyanf1

    josyanf1 Member

    Joined:
    Jan 12, 2018
    Posts:
    17
    Damn is true. Anyway, when I activate the shader it keeps changing the resolution :/
     
  15. josyanf1

    josyanf1 Member

    Joined:
    Jan 12, 2018
    Posts:
    17
    Hello! Sorry for the delay in responding. I have been doing tests and all the functions and the optimization that you told me work.
    The only thing I need is to expand the margins of the screen and stretch it to the window for the fullscreen option. Any idea / form?
    Thanks for all your help :)
     

    Attached Files:

    • 1.PNG
      1.PNG
      File size:
      443.1 KB
      Views:
      4
  16. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,405
    If you can assemble a tiny project with just your screen setup, I could take a look at what else could be wrong. But I think you'll need to resize your application_surface to be not just that fixed size, but rather calculate the sizing while keeping aspect ratio, like so (live demo):
    Code:
    surf = -1;
    // ...
    var gameWidth = 180;
    var gameHeight = 320;
    if (!surface_exists(surf)) {
        surf = surface_create(gameWidth, gameHeight);
        surface_set_target(surf);
        draw_clear(c_blue);
        surface_reset_target();
    }
    var screenWidth = mouse_x;
    var screenHeight = mouse_y;
    var scale = min(screenWidth / gameWidth, screenHeight / gameHeight);
    var outWidth = gameWidth * scale;
    var outHeight = gameHeight * scale;
    var outX = (screenWidth - outWidth) div 2;
    var outY = (screenHeight - outHeight) div 2;
    draw_surface_stretched(surf, outX, outY, outWidth, outHeight);
    //
    draw_rectangle(0, 0, screenWidth, screenHeight, 1);
     
  17. josyanf1

    josyanf1 Member

    Joined:
    Jan 12, 2018
    Posts:
    17
    Surely that's it, thank you very much!
     

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