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

3D Camera is being drawn to surface upside down

F

Freddie The Potato

Guest
I've created 2 cameras.
Code:
global.mainCamera = cameraCreate();
global.utilityCamera = cameraCreate();
A cameraController object updates mainCamera's view and projection matrices every frame based on its position and rotation.

I can draw the scene onto a surface like so:
Code:
surface_set_target(surf);

draw_clear_alpha(0, 0);

camera_apply(global.mainCamera);
with (objDrawable) {
    event_perform(ev_draw, 0);
}

surface_reset_target();
It works as expected.


However, something strange happens when I do this:
Code:
camera_set_view_mat(global.utilityCamera, camera_get_view_mat(global.mainCamera));
camera_set_proj_mat(global.utilityCamera, camera_get_proj_mat(global.mainCamera));
  
surface_set_target(surf);

draw_clear_alpha(0,0);

camera_apply(global.utilityCamera);
with (objDrawable) {
    event_perform(ev_draw, 0);
}

surface_reset_target();
Everything is drawn upside down :(

I have no idea why this happens. In both instances the same view and projection matrices are being used. (Or so I think. Maybe camera_get_view_mat is giving me a modified matrix??)
Any tips would be greatly appreciated!
 
F

Freddie The Potato

Guest
So after looking at the contents of projection matrices both before and after being applied to cameras, I think I've figured out what's causing this issue.

Game Maker seems to flip projections upside down after setting them to cameras. Getting the matrix from the camera with camera_get_proj_mat returns a matrix wherein the 6th value is always the inverse of its original value.

This probably explains why the up-vectors of view matrices always seem to point in the wrong direction...
Just another one of Game Maker's quirks I guess ¯\_(ツ)_/¯

Anyway, it can be easily fixed by manually inverting the 6th value in the projection matrix back to its original value.
Code:
proj = camera_get_proj_mat(global.mainCamera);
proj[5] *= -1;
 
Last edited by a moderator:
I don't have GMS2, but I've been hearing about this flipping of the y axis for ages, and I knew that it was related to the inversion of the sign in the projection matrix at the location that you identified. But for the life of me I couldn't figure out why they chose to do this. Was it because the application surface was being drawn upside down??? Or why it seemed to be an issue only some of the time.

But based on your info I think I understand at least when the problem is likely to happen. Every time the projection matrix is set it must invert the sign of that value. Which means if you get and reset the same matrix, it will have flipped that sign x2. Which is really stupid. I noticed a similiar problem in GMS1, where if you get and set a projection matrix it will make all graphics blurry, because every time you do, gamemaker automatically adds a mysterious (but tiny) translation to the matrix.
 
Last edited:
Top