Camera Projection Matrizes..?

Discussion in 'Programming' started by SirDude, Oct 10, 2019.

  1. SirDude

    SirDude Member

    Joined:
    Mar 16, 2019
    Posts:
    5
    Hi, so I'm using the new Camera Projection Matrix added in GMS 2, but I don't really understand how to get the data once it's set up. For example, how do I get the x and y position of the camera like
    camera_get_view_x(view_camera[0]) used to do? I tried to calculate it myself with:
    var cw = camera_get_view_width(view_camera[0]);
    var ch = camera_get_view_height(view_camera[0]);
    var cleft = x - (cw / 2);
    var ctop = y - (ch / 2);

    ,but there has to be an easier way, right? (also I'm actually not even sure if that is correct...)

    Thank you for your help.
     
  2. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,742
    Isn't there functions named camera_get_view_x and camera_get_view_y to get their top left corner? Then you can just add the width/height to get the bottom right corner. The camera's center is the average of those points.
     
  3. SirDude

    SirDude Member

    Joined:
    Mar 16, 2019
    Posts:
    5
    Unfortunately, camera_get_view_x and camera_get_view_y are (for whatever reason) always 0 using Projection Matrizes ...
     
  4. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    2,169
    You should already know the position of your camera if you've built it using matrices. However, it can be extracted out of the view matrix if needed.

    Are you using a perspective projection with a top-down view? And do you need to know the position of the camera, or the position of the 2d view, which is located at view_center - view_size/2 (or the equivalent considering a perspective projection is in use)? If the game is not top-down, then there won't be any equivalent.
     
    Last edited: Oct 10, 2019
  5. SirDude

    SirDude Member

    Joined:
    Mar 16, 2019
    Posts:
    5
    Thank you for your reply.
    I was using the Smooth Camera shown by Shaun Spalding on Youtube, but I am very new to this method so I didn't understand all of it. I want to know the position of the 2d view and can't figure out an easy way to get it...
    This is basically what I was trying to do with the code in the first post, but I don't think it works correctly
     
  6. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,037
  7. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    2,169
    If you show us exactly how you are setting up your camera or your view and projection, we can be sure we are helping you get correct answers to your question.
     

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