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

GameMaker 3D Issues with camera

F

FireflyX91

Guest
Hello Gamemakers, I'm currently working on a 3D project and I've ran into a couple of issues that I can't seem to solve so I was hoping somebody would take a look at my code and help me out.

The problem is that my camera is displaying the world upside down. I believe this is due to GMS2 displaying the Z axis the opposite way to previous versions of GM. However I don't know how to modify this code to display it correctly. The code below was actually taken from an older version and I've had to replace all the d3d functions with their newer equivalents.

This is what I have in my camera objects "Create" event:

Code:
view_enabled = true;
view_set_visible(0,true);

var aspect = view_get_wport(0) / view_get_hport(0);   

camera = camera_create();

projection_matrix = matrix_build_projection_perspective_fov(45,aspect,1,32000);
camera_set_proj_mat(camera,projection_matrix);

view_set_camera(0,camera);

camera_set_update_script(camera,scr_cam_update);
The camera update script "scr_cam_update" is most likely the source of the problem:

Code:
var cam_x = obj_char.x;
var cam_y = obj_char.y;
var cam_z = obj_char.z + obj_char.height;
var cam_dir = obj_char.direction;
var cam_pitch = obj_char.pitch;

var matrix = matrix_build_lookat(
    cam_x,cam_y,cam_z,
    cam_x + lengthdir_x(1, cam_dir),
    cam_y + lengthdir_y(1, cam_dir),
    cam_z + lengthdir_y(1, cam_pitch),
    0,0,1
    );
    
camera_set_view_mat(view_camera[0],matrix);
Thanks for taking the time to view this thread and I hope somebody can point me in the right direction.
 
K

Kobold

Guest
change this
Code:
projection_matrix = matrix_build_projection_perspective_fov(45,aspect,1,32000);
to that:
Code:
projection_matrix = matrix_build_projection_perspective_fov(-45,-aspect,1,32000);
 
F

FireflyX91

Guest
That was even simpler than I thought and it now does what I need. Thanks for your help with that :)
 
Top