AlessioForlanteDev
Member
Hey guys! I hope this is complex enough for this section.
I am making a 2d top-down game with (important) 3D elements. This means I am using the matrix projections and all that.
My issue is that the lighting system I was using no longer works, as it doesn't match the world anymore.
Everyone told me it was fixable by using "camera_apply" however I used it in every possible place and yield no results, so I had someone help me.
He had "fixed" it (I put it in quotation marks because while it didn't completely match up and told me it was impossible to completely fix unless I rewrote it for 3d, however it was good enough for my purpose). The problem is he pretty much ghosted me and I don't want to bother him anymore.
He had told me that what he did was simply "normalized view matrices". I can't find any simple documentation online on how to do this and I don't understand the math at all. Some help would be greatly appreciated, as the game "engine" is pretty much complete (after months of work) after this is fixed.
I will post my camera code below.
create event: (I know there's alot of legacy GM1 stuff here...)
surface_resize(application_surface, global.resolution_w, global.resolution_h);
cameradifference = 0
//setting stuff
__view_set(e__VW.WView, 0, global.default_camera_w)
__view_set(- e__VW.HView, 0, -global.default_camera_h )
__view_set( e__VW.HBorder, 0, global.default_camera_w )
__view_set( e__VW.VBorder, 0, global.default_camera_h)
__view_set( e__VW.HSpeed, 0, -1 )
__view_set( e__VW.VSpeed, 0, -1 )
__view_set( e__VW.Object, 0, obj_camera )
__view_set( e__VW.Visible, 1, false )
__view_set( e__VW.Visible, 2, false )
view_enabled[1] = false
view_enabled[2] = false
__view_set( e__VW.Visible, 0, true );
view_enabled[0] = true;
// setting the splitscreen stuff
if !instance_exists(obj_slavecamera_p1) and instance_exists(obj_player1) instance_create(x,y,obj_slavecamera_p1)
if !instance_exists(obj_slavecamera_p2) and instance_exists(obj_player2) instance_create(x,y,obj_slavecamera_p2)
The update script:
obj_camera.cameradistance= (-(700+obj_camera.cameradifference + obj_camera.playermultizoom )* (obj_camera.carzoom))
mLookat = matrix_build_lookat(obj_camera.x,obj_camera.y,obj_camera.cameradistance,obj_camera.x,obj_camera.y-7,190,0,0,1)
//mLookat = matrix_build_lookat(obj_camera.x,obj_camera.y,-900,obj_camera.x,obj_camera.y-7,190,0,0,1)
//Assign the matrix to the camera. This updates were the camera is looking from, without having to unnecessarily update the projection.
camera_set_view_mat(view_camera[0], mLookat);
projMat = matrix_build_projection_perspective_fov(60, (global.default_camera_w)/global.default_camera_h, 32, 32000 );
camera_set_proj_mat(view_camera[0], projMat );
camera_apply( camera_get_active());
I am making a 2d top-down game with (important) 3D elements. This means I am using the matrix projections and all that.
My issue is that the lighting system I was using no longer works, as it doesn't match the world anymore.
Everyone told me it was fixable by using "camera_apply" however I used it in every possible place and yield no results, so I had someone help me.
He had "fixed" it (I put it in quotation marks because while it didn't completely match up and told me it was impossible to completely fix unless I rewrote it for 3d, however it was good enough for my purpose). The problem is he pretty much ghosted me and I don't want to bother him anymore.
He had told me that what he did was simply "normalized view matrices". I can't find any simple documentation online on how to do this and I don't understand the math at all. Some help would be greatly appreciated, as the game "engine" is pretty much complete (after months of work) after this is fixed.
I will post my camera code below.
create event: (I know there's alot of legacy GM1 stuff here...)
surface_resize(application_surface, global.resolution_w, global.resolution_h);
cameradifference = 0
//setting stuff
__view_set(e__VW.WView, 0, global.default_camera_w)
__view_set(- e__VW.HView, 0, -global.default_camera_h )
__view_set( e__VW.HBorder, 0, global.default_camera_w )
__view_set( e__VW.VBorder, 0, global.default_camera_h)
__view_set( e__VW.HSpeed, 0, -1 )
__view_set( e__VW.VSpeed, 0, -1 )
__view_set( e__VW.Object, 0, obj_camera )
__view_set( e__VW.Visible, 1, false )
__view_set( e__VW.Visible, 2, false )
view_enabled[1] = false
view_enabled[2] = false
__view_set( e__VW.Visible, 0, true );
view_enabled[0] = true;
// setting the splitscreen stuff
if !instance_exists(obj_slavecamera_p1) and instance_exists(obj_player1) instance_create(x,y,obj_slavecamera_p1)
if !instance_exists(obj_slavecamera_p2) and instance_exists(obj_player2) instance_create(x,y,obj_slavecamera_p2)
The update script:
obj_camera.cameradistance= (-(700+obj_camera.cameradifference + obj_camera.playermultizoom )* (obj_camera.carzoom))
mLookat = matrix_build_lookat(obj_camera.x,obj_camera.y,obj_camera.cameradistance,obj_camera.x,obj_camera.y-7,190,0,0,1)
//mLookat = matrix_build_lookat(obj_camera.x,obj_camera.y,-900,obj_camera.x,obj_camera.y-7,190,0,0,1)
//Assign the matrix to the camera. This updates were the camera is looking from, without having to unnecessarily update the projection.
camera_set_view_mat(view_camera[0], mLookat);
projMat = matrix_build_projection_perspective_fov(60, (global.default_camera_w)/global.default_camera_h, 32, 32000 );
camera_set_proj_mat(view_camera[0], projMat );
camera_apply( camera_get_active());