• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

 Can no longer save, change, then re-apply camera view and projection matrix.

A

Andy

Guest
Can no longer save, change, then re-apply camera view and projection matrix.
If I try to,
1: Save my current 3D camera matrices.
2: Set my camera to use new 2D matrices for temporary drawing.
3: Reset back to the saved (3D matrices.
The 3D camera seems to be upside down. Before the update it would reset the camera perfectly.



Code:
/// @description

//
gpu_set_ztestenable(true);
gpu_set_zwriteenable(true);

// Apply 3d mats
var _x = room_width/2;
var _y = room_height/2;
var _view = matrix_build_lookat(_x-480, _y, -240, _x, _y, 0, 0, 0, -1);
var _proj = matrix_build_projection_perspective_fov(-60, -view_wport[view_current]/view_hport[view_current], 1.0, 32000.0);
camera_set_view_mat(view_camera[view_current], _view);
camera_set_proj_mat(view_camera[view_current], _proj);
camera_apply(view_camera[view_current]);

// Draw floor 1
draw_sprite(spr_floor1, 1, room_width/2, room_height/2);

// Save mats
var _save_view = camera_get_view_mat(view_camera[view_current]);
var _save_proj = camera_get_proj_mat(view_camera[view_current]);

// Apply 2d "GUI" mats
var _x = view_wport[view_current]/2;
var _y = view_hport[view_current]/2;
var _view = matrix_build_lookat(_x, _y, -16000, _x, _y, 0, 0, 1, 0);
var _proj = matrix_build_projection_ortho(view_wport[view_current], view_hport[view_current], 1.0, 32000.0);
camera_set_view_mat(view_camera[view_current], _view);
camera_set_proj_mat(view_camera[view_current], _proj);
camera_apply(view_camera[view_current]);

// Draw text
draw_text(100, 100, "Hello world");

// Reset to saved mats
camera_set_view_mat(view_camera[view_current], _save_view);
camera_set_proj_mat(view_camera[view_current], _save_proj);
camera_apply(view_camera[view_current]);

// If you uncomment the section below (manually setting up the 3d mats again) everything works.
// I used to be able to just apply the saved mats.


// Apply 3d mats
gpu_set_ztestenable(true);
gpu_set_zwriteenable(true);
var _x = room_width/2;
var _y = room_height/2;
var _view = matrix_build_lookat(_x-480, _y, -240, _x, _y, 0, 0, 0, -1);
var _proj = matrix_build_projection_perspective_fov(-60, -view_wport[view_current]/view_hport[view_current], 1.0, 32000.0);
camera_set_view_mat(view_camera[view_current], _view);
camera_set_proj_mat(view_camera[view_current], _proj);
camera_apply(view_camera[view_current]);


// Draw floor 2
draw_sprite(spr_floor2, 1, room_width/2, room_height/2);
Example: http://www.filedropper.com/cammatrixbroke
 
Top