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

3D 3D vertex unaffected by 3D camera?

Hi! I'm just starting with 3D, going through some tutorials but there are some informations I can't find.

Setup :
The green ground is a tileset layer setup in the room.
The white rectangle is vertex drawn using a vertex buffer (code sample below).
3d camera.


3D_testVertex.gif

Scripts used to draw the white triangles :
GML:
vbuffer = vertex_create_buffer();
vertex_begin(vbuffer, vertex_format);

var x1 = 400;
var y1 = 400;
var x2 = 600;
var y2 = 600;

vertex_add_point(vbuffer, x1, y1, 100,        0, 0, 1,        0, 0,    c_white, 1);
vertex_add_point(vbuffer, x2, y1, 100,        0, 0, 1,        0, 0,    c_white, 1);
vertex_add_point(vbuffer, x2, y2, 100,        0, 0, 1,        0, 0,    c_white, 1);

vertex_add_point(vbuffer, x2, y2, 100,        0, 0, 1,        0, 0,    c_white, 1);
vertex_add_point(vbuffer, x1, y2, 100,        0, 0, 1,        0, 0,    c_white, 1);
vertex_add_point(vbuffer, x1, y1, 100,        0, 0, 1,        0, 0,    c_white, 1);

vertex_end(vbuffer);


function vertex_add_point(vbuffer, xx, yy, zz, nx, ny, nz, utex, vtex, color, alpha)
{
    vertex_position_3d(vbuffer, xx, yy, zz);
    vertex_normal(vbuffer, nx, ny, nz);
    vertex_texcoord(vbuffer, utex, vtex);
    vertex_color(vbuffer, color, alpha);
}
MY QUESTIONS ARE :
Why is the white rectangle unaffected by the camera?

How do I clear the background so there's no residual green pixel from the ground layer? (Clear Buffer Display doesn't do it)

Thanks!
 
Why is the white rectangle unaffected by the camera?
Where is your vertex_submit for the white rectangle?

How do I clear the background so there's no residual green pixel from the ground layer? (Clear Buffer Display doesn't do it)
Make sure there's a background layer at the bottom of the layers that is set to an opaque color so that there's something to clear the screen with.
 
Ok! Background fixed! Thanks for that!

The vertex_submit is in a draw event.
[ EDIT ] : I tried changing it to Draw Begin event and it's now affected by the camera but that seems... counter-intuitive?
 
Ok! Background fixed! Thanks for that!

The vertex_submit is in a draw event.
[ EDIT ] : I tried changing it to Draw Begin event and it's now affected by the camera but that seems... counter-intuitive?
Is this perhaps an order of operations issue? Where are you making changes to the camera? And where are you running the vertex submit? Is this all happening in a single object or multiple?

I usually like to set things up so that whatever object is handling the camera also handles all of the vertex submits to make sure everything is done in the correct order. This specifics can vary from:
  • storing all the vertex buffers in a global array/data structure and looping through the array/data structure when the time comes and running all the vertex submits
  • manually executing all other draw events inside of a with statement from a camera object's draw event at the appropriate time
 
Thanks a lot for your answers! This is very helpful.
I'll look into it carefully and should be able to figure it out. I'll try to post anything useful once I get it!
 
I'm getting somewhere with drawing the squares but the texture doesn't come out as expected.
Here is the testing texture I'm using to draw on the squares :
test_texture.png

Here is what it draws :
screenshot_incorrectTexture.png

Instead of drawing the texture from the specified sprite, it seems to be taking it from the whole texture page. (??)

The code I use to draw and manage the camera :
GML:
var n = array_length(global.vertexes);
for (var i = 0; i < n; i++)
    vertex_submit(global.vertexes[i], pr_trianglelist, sprite_get_texture(spr_texture, 0));

var camera = camera_get_active();
camera_set_view_mat(camera, matrix_build_lookat(0,0,400,room_width,room_height,0,0,0,-1));
camera_set_proj_mat(camera,matrix_build_projection_perspective_fov(60,window_get_width() / window_get_height(),3,30000));
camera_apply(camera);
(the code to build the vertexes is basically the same as in my original post, except different coords.)
 
Last edited:
Top