1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GMS 2 I need help from 3D experts. [Solved]

Discussion in 'Advanced Programming Discussion' started by JaimitoEs, Jan 22, 2020.

Tags:
  1. JaimitoEs

    JaimitoEs Member

    Joined:
    Aug 9, 2016
    Posts:
    220
    Hi everyone! I´m finishing the GMS2 version of my editor, but I have encountered a problem that leads me, I put you in situation:

    Code:
    /*
    ///GMS1 Activating the z-buffer
    { { 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1 },  }///Default World
    { { 1,0,0,0,0,1,0,0,0,0,1,0,-640,-360,1920,1 },  }Default View
    { { 2,0,0,0,0,3.56,0,0,0,0,1.00,1,-0.00,0.00,-1.00,0 },  }Default Projection
    
    ///GMS2 Activating the z-buffer
    { { 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1 },  }///Default World
    { { 1,0,0,0,0,1,0,0,0,0,1,0,-640,-360,16000,1 },  }Default View
    { { 0.00,0,0,0,0,-0.00,0,0,0,0,0.00,0,0,0,0,1 },  }Default Projection
    */
    
    Create event:
    
    Proj = [2,0,0,0,0,3.56,0,0,0,0,1.00,1,-0.00,0.00,-0.00,0];
    In GMS1, to handle an orthographic 3d plane, what I do is transform the matrices into the draw event of my camera when the 3d is activated, in this way I get the desired perspective and i can toggle between 2d-3d.

    Remaining our code for the draw event:
    Code:
    if(start_3d)
    {
     var m = matrix_build(0,0,-
     z,y_rotation,x_rotation,z_rotation,1,-1,1);
     var v = matrix_get(matrix_view);
     var f = matrix_multiply(v,m);
     matrix_set(matrix_view,f);
    }
    I have already read the entire manual on the new camera functions to see if this method was compatible with GMS2. I have seen that the projection has changed, and if I propose the same method as in GMS1 to create the perspective, I see that the Y axis is inverted, so far so good, I change the value to positive but, my plane has no perspective. I decide to replicate the GMS1 projection and set this to the default camera (view_camera [0]), and I get the exact perspective I had! I already have 3D! But there comes another problem, I totally lose control over the editor, the traditional 2D coordinates axis stops working. It made me think that I should control my camera as if it were 2d and draw the perspective from the Draw event of the camera, so I decide to pass the GMS1 projection matrix directly in this event. Good news, I have control of the editor again, but the camera draws the stage from its point of origin in the world (32000, or 16000 seems to be looking the image...).
    Any idea how to make the GMS1 projection matrix compatible for GMS2?

    Last Try GMS2 passing the old projection matrix:
    Create event : Proj = [2,0,0,0,0,3.56,0,0,0,0,1.00,1,-0.00,0.00,-0.00,0]///Default Gms1 Projection.

    and the Draw event:
    Code:
    if(start_3d)
    {
     matrix_set(matrix_projection, Proj);
     var m = matrix_build(0,0,- z,y_rotation,x_rotation,z_rotation,1,-1,1);
     var v = matrix_get(matrix_view);
     var f = matrix_multiply(v,m);
     matrix_set(matrix_view,f);
    }
    
    The result

    [​IMG]

    If i set the projection from the function "camera_set_proj_mat" in the "Create event", the world is represented correctly, but i loose the tradicional 2d x/y coordinate system.
    Also i see when i draw from the Gui in a depth <= 0, the input boxes are not drawn, I guess it has to do with leaving the zbuffer drawing region... but i´m confused in this moment.

    Edit 1: I have a new track that confuses me even more, some terrains are drawn in cullOn mode, and these are not represented on the screen, it makes me think that the projection is reversed, but I am not able to reverse it ...

    Any idea where I may be failing? Thanks in advance.
     
    Last edited: Jan 22, 2020
  2. kraifpatrik

    kraifpatrik Member

    Joined:
    Jun 23, 2016
    Posts:
    148
    Hey there, I don't have access to GM right now, so I can't test things out, but I remembered that based on the docs, matrices were changed from column-major to row-major (see matrix_build in GMS1 and GMS2). So maybe transposing your GMS1 matrices (if you write them into arrays directly) may result into the same behavior in GMS2? Not entirely sure about that though!
     
    JaimitoEs likes this.
  3. JaimitoEs

    JaimitoEs Member

    Joined:
    Aug 9, 2016
    Posts:
    220
    Hey @kraifpatrik ! Thanks for the reply! That make all the sense! As long as I can, I will try to transpose the matrix and see the result! Again thank you very much!!
     
  4. JaimitoEs

    JaimitoEs Member

    Joined:
    Aug 9, 2016
    Posts:
    220
    Unfortunately not, if I transpose the matrix, black screen.

    I have also done a test creating a matrix with the function "matrix_build_projection_perspective" to debug the default matrix and it gives me the same values as in GMS1, i think the problem is how i´m handling the camera system, I am creating a conflict with the default camera or something similar, I will recreate it by assigning the values into another camera.
     
  5. JaimitoEs

    JaimitoEs Member

    Joined:
    Aug 9, 2016
    Posts:
    220
    Well, there are things that have changed in the view matrix...

    If I configure a camera in 2d, with the Mouse Scroll I can handle the size of the view. But debuging the matrix view, the values of the new size of my view are not reflected.

    Are the matrix view represented by this?:
    [ vec x, 0, 0, 0, 0, vec y, 0, 0, 0, 0, -center-x position, -center-y position, 16000 (nearest depth plane? This value only change with a perspective view tweaking the z coord), 1 (farthest depth plane?)].

    I´m setting up a default camera using "view_camera[0]", in a camera object without following this, i am making this manually using the viewPos function, this camera object is placed in the room with a depth of 32000.
    So my question is, why can't you see the size of the view reflected in this matrix? Is this matrix designed for 3d even for 2d cameras? Why does the "camera_set_view_size" function not take effect when I assign a perspective matrix?

    In Gms1, The value[14] of a view matrix is the camera width aspect. In Gms2, this value is the depth?

    I'd rather ask before I start changing things like crazy ...

    Well...setting a matrix projection and view into the draw event and debugging:

    view current "matrix_get"
    { { 1,0,0,0,0,-1,0,0,0,0,1,0,-673,349,15999,1 }, } Matrix view
    { { 2,0,0,0,0,3.56,0,0,0,0,1,1,0,0,-1,0 }, } Matrix Projection
    view camera " "camera_get_mat"
    { { 1,0,0,0,0,1,0,0,0,0,1,0,-673,-349,16000,1 }, } Matrix view
    { { 0.00,0,0,0,0,-0.00,0,0,0,0,0.00,0,0,0,0,1 }, } ???????? Matrix Projection

    I´m only using directly the default camera "view_camera[0]" to set the view size and position. So, i have 2 projections? that means i´m overllaping a matrix projection instead to swap the camera projection?
     
    Last edited: Jan 24, 2020
  6. JaimitoEs

    JaimitoEs Member

    Joined:
    Aug 9, 2016
    Posts:
    220
    Ok found the problem, first, if you want to manipulate a camera on the draw event, you need to use the function camera_apply,.....The second problem, i need to reorder the creation of vertices from the terrain Scripts... Sorry for disturbing with something already anwsered...Let´s go!
     
    Last edited: Jan 25, 2020

Share This Page