GameMaker How should I properly use camera_set_view_angle()

D

Double7

Guest
Hey guys, getting used to GMS2 now and trying to figure out the camera system. The current effect I am going for is for the camera to rotate to a certain angle on command. However I am currently having an issue where the screen just goes black anytime I use camera_set_view_angle().

The video shows my issue


Here is an update on my findings after playing around in a different project for a bit.

1) calling camera_set_view_angle() on the default camera given by the engine will result in the proper effect
2) calling the function on a camera that was initialized with camera_create() and modified with camera_set_proj_mat() and camera_set_view_mat() will result in the screen turning black. (even if I copy the matrices directly from the default camera)

So this is leading me to believe that one of two things are leading to my issue. Which as usual is one of the following...

I'm stupid : I don't understand something set up within the default camera that allows the camera to avoid this issue. Which if applied to my created cameras would also fix this problem.
or
GM is stupid : Meaning camera_set_view_angle() only works with non-programmer created cameras

Seeing as most of the time I reach this conclusion it is the former that usually reveals to be the truth, I am going to keep digging into this. However the debugger doesn't seem to give too much info on cameras. Making this more difficult.

Ok, so I went through all of the possible gets and sets and figured out that setting the matrices for the camera does not set the variables view_height and view_width within the camera. You have to set these manually to ensure that they are not 0.

Hence a 0x0 view ported will be all black (or whatever background you have).

So if you want to rotate a camera you made, you need to make sure that you set these variables as well as the matrices.


EDIT:

So this fixes the problem if the cameras are not moving. If the cameras are moving then there are still issues where the screen either goes black or resets the angle every frame that the matrix is reset, even if I save and set the angle each time.

Going to sleep on this one I guess.
 
Last edited by a moderator:

samspade

Member
Without seeing you're code, its a little hard to tell. But in generally, don't use camera_set_view_angle with custom cameras. If you're going to use the matrix set up, then you need to rotate the matrix manually because that is built in to the matrix function. matrix_build_lookat sets the angle directly. So when you all camera_set_view_mat and give it a matrix, you're giving it an angle.

I would use this tutorial to set up a camera:

 
D

Double7

Guest
Without seeing you're code, its a little hard to tell. But in generally, don't use camera_set_view_angle with custom cameras. If you're going to use the matrix set up, then you need to rotate the matrix manually because that is built in to the matrix function. matrix_build_lookat sets the angle directly. So when you all camera_set_view_mat and give it a matrix, you're giving it an angle.

I would use this tutorial to set up a camera:

Thanks!
The code can be seen in the video I posted. I saw that altering the matrix would allow for you to rotate the view, but I also saw that it wasn't a one to one rotation and I am not sure how to do the math for that to get it to rotate a certain number of degrees.
 

samspade

Member
Thanks!
The code can be seen in the video I posted. I saw that altering the matrix would allow for you to rotate the view, but I also saw that it wasn't a one to one rotation and I am not sure how to do the math for that to get it to rotate a certain number of degrees.
Rotating using the matrix is more complicated, and generally unnecessary since the camera functions work fine once you understand them and are more simple. To understanding rotating the matrix you have to understand vectors and importantly how to calculate vectors to get an angle. Here a post that explains it: https://forum.yoyogames.com/index.p...amera-rotation-help-solved.52487/#post-320850. It's definitely worth understanding, but its probably unnecessary for the reason stated above. One note on that link is at the time I still used matrix views, I have since seen the wisdom of switching, and would definitely recommend it.

Also, most people arn't going to (don't want to, can't) watch a video for code, so that's why the forum rules say post it.
 
D

Double7

Guest
Rotating using the matrix is more complicated, and generally unnecessary since the camera functions work fine once you understand them and are more simple. To understanding rotating the matrix you have to understand vectors and importantly how to calculate vectors to get an angle. Here a post that explains it: https://forum.yoyogames.com/index.p...amera-rotation-help-solved.52487/#post-320850. It's definitely worth understanding, but its probably unnecessary for the reason stated above. One note on that link is at the time I still used matrix views, I have since seen the wisdom of switching, and would definitely recommend it.

Also, most people arn't going to (don't want to, can't) watch a video for code, so that's why the forum rules say post it.
Gotcha, I will do both next time. I just thought the video would help demonstrate what I was trying to say the best.
I also have no idea how that thread never showed on any searches I did on this site / google.
 
Top