• 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!

Camera Projection Matrizes..?

S

SirDude

Guest
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.
 

Yal

šŸ§ *penguin noises*
GMC Elder
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.
 
S

SirDude

Guest
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.
Unfortunately, camera_get_view_x and camera_get_view_y are (for whatever reason) always 0 using Projection Matrizes ...
 
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:
S

SirDude

Guest
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.
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...
view_center - view_size/2
This is basically what I was trying to do with the code in the first post, but I don't think it works correctly
 
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.
 
Top