GameMaker I need help from 3D experts. [Solved]

JaimitoEs

Member
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



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:

kraifpatrik

(edited)
GameMaker Dev.
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

Member
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!
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.
 

JaimitoEs

Member
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:

JaimitoEs

Member
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:

JaimitoEs

Member
Bug fixed with camera systems, DarkSpine works properly in GMS2, now i have a problem with the function "draw_get_pixel" in perspective mode...The function works properly with a 2D camera returning the code color, but when i switch to a 3D perspective, this function does not get any color, retuning me a value of 0, any idea? For 2d, i´m calling this function in the step event... Can be this the problem? And...Why this work perfectly in 2D mode, the manual said we are getting the pixel color from the screen buffer right?
 

Bart

WiseBart
There are two things I can think of that may be causing this.

Where do you want to get the pixel value from? The application surface? Another surface? The back buffer?
draw_getpixel takes the pixel value from the current render target, but I'm not too sure what that is in the Step event.

Another possible cause is the way that the camera system works.
While it may look like the view and projection matrices are only used during the Draw events for the actual drawing, they're actually "in use" outside of it, too. That is, if you have the matrices set indirectly by assigning a view_camera.
You can verify that by showing the values of mouse_x and mouse_y in the Step event. When you have a perspective transformation set, the values of those will be transformed as well.
A similar thing may be going on with the x and y values that you pass to draw_getpixel.

If that's actually the case, the most straightforward way to get the pixel value you're looking for would be in the appropriate Draw event. Which, in this case, would be the Post Draw event, where you can get the pixel value on the application surface by using surface_getpixel.

Hope this may help a bit :)
 
Last edited:

JaimitoEs

Member
There are two things I can think of that may be causing this.

Where do you want to get the pixel value from? The application surface? Another surface? The back buffer?
draw_getpixel takes the pixel value from the current render target, but I'm not too sure what that is in the Step event.

Another possible cause is the way that the camera system works.
While it may look like the view and projection matrices are only used during the Draw events for the actual drawing, they're actually "in use" outside of it, too.
You can verify that by showing the values of mouse_x and mouse_y in the Step event. When you have a perspective transformation set, the values of those will be transformed as well.
A similar thing may be going on with the x and y values that you pass to draw_getpixel.

If that's actually the case, the most straightforward way to get the pixel value you're looking for would be in the appropriate Draw event. Which, in this case, would be the Post Draw event, where you can get the pixel value on the application surface by using surface_getpixel.

Hope this may help a bit :)
Hey! Thanks for the replie!

Yes, i´ve revamped the camera system, now is different than the GMS1 version and you can manage this like a 3D camera, with Fov and Aspect. Yes , i´ve create my own mouse system but, i´m calling this function using the Mouse GUI coordinates, and this works perfectly with the 2D camera, i was suposed is the same concept for the 3D camera because the device gui mouse coordinates does not change and i´m getting the pixel from the screen buffer. I would say, thinking about you are telling me, i´m not using any surface for the final render, i´m drawing directly to the screen. I did not know the function "surface_getpixel", this is a big help, Thanks!:) And i want to catch the pixel from the final render but... ¿Is there a variable that identifies the screen buffer if we are not using any surface? maybe this function can help!
 
Top