Bart
WiseBart
Hi all.
I'm trying to use matrix_transform_vertex to apply the model-view-projection matrix to a point, similar to what happens in the vertex shader.
For some reason the only point that I can get right is (0, 0, 0). And I currently don't see what is wrong.
Here is my current code:
The camera is located at (352, 0, 0) and looking towards (0, 0, 0).
A cube of size 100 is drawn at the origin with its center point there.
Using the above code, I'd expect one of the corner points, e.g. (50, 50, -50), to be drawn at the exact location on screen in the Draw GUI event. But it's not: Moving the point forward and backward along +x should result in a slight change along the horizontal axis because of the perspective projection but nothing seems to change.
The GUI and the viewport are the same size: 1280 x 720.
Anyone has some insight on what is going wrong here?
It seems like I'm missing something.
I'm trying to use matrix_transform_vertex to apply the model-view-projection matrix to a point, similar to what happens in the vertex shader.
For some reason the only point that I can get right is (0, 0, 0). And I currently don't see what is wrong.
Here is my current code:
Code:
/// Create event
cam = view_camera[0];
///*
//mat_proj = matrix_build_projection_perspective_fov(45, 16/9, .1, 32000);
mat_proj = matrix_build_projection_perspective(1280, 720, 200, 32000);
mat_view = matrix_build_lookat(x, y, 0, 0, 0, 0, 0, 0, -1);
camera_set_proj_mat(cam, mat_proj);
camera_set_view_mat(cam, mat_view);
mat_world = matrix_get(matrix_world); // identity matrix by default
mat_transform = matrix_multiply(mat_view, mat_proj); // mat_transform = mat_proj * mat_view;
mat_transform = matrix_multiply(mat_world, mat_transform);
co = [0, 0, 0];
//*/
Code:
/// @description Draw GUI - draw indicator sprite
vert = matrix_transform_vertex(mat_transform, co[0], co[1], co[2]);
draw_sprite(spr_indicator, 0, view_wport[0]/2 - vert[0], view_hport[0]/2 - vert[1]); // lookat point is at center of screen
draw_text(5, 5, "In: " + string(co));
draw_text(5, 25, "Out: " + string(vert));
A cube of size 100 is drawn at the origin with its center point there.
Using the above code, I'd expect one of the corner points, e.g. (50, 50, -50), to be drawn at the exact location on screen in the Draw GUI event. But it's not: Moving the point forward and backward along +x should result in a slight change along the horizontal axis because of the perspective projection but nothing seems to change.
The GUI and the viewport are the same size: 1280 x 720.
Anyone has some insight on what is going wrong here?
It seems like I'm missing something.