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

GameMaker [SOLVED]How to multiply 3x3 matrixes through GPU?

Dupletor

Member
The problem is pretty simple, I have a triangle (x1,y1,z1,x2,y2,z2,x3,y3,z3) and I want to rotate it around one of the axis with GPU, by multiplying the triangle with a 3d rotation matrix.

However, the death of the d3d functions made it terribly harder, as most guides are in obsolete d3d.

"Thee transforms have been replaced with matrix functions now! Using matrix_build in combination with matrix_set(matrix_world, matrix) for the most part."

I couldn't find amongst the "gpu_" functions one that could help creating my own solution, and the documentation for matrix_multiply is pretty terrible. Not only it does not say if it can be done through GPU, it also exclusively uses 4x4 matrixes, so I can't even know if I'm supposed to only use it for Quaternions. :p So... How am I supposed to use the matrix functions to solve the problem? '-'
 

Dupletor

Member
Get it, will give it a try. Thanks for the explanation.
(Finally understood how the matrix_build() works)
However, how efficient is it? I can't do the entire process in CPU, it would be terribly slow for a very small amount of triangles. And my model got a reasonable amount of them...
Doesn't say in specification, does it use GPU? :p
 

Dupletor

Member
I succeeded comparing what I'm doing to it and getting the same result when both models rotate around (0,0,0).
However, I'm not rotating my model around [0,0,0], I am rotating around [0,700,0], which I guess makes me need to change the first 3 parameters.

How? Setting the first 3 parameters to 0,700,0 will work for some angles, but not for others, so I guess it does not change the rotation center...
 

Dupletor

Member
Did it! Modified the model so that it will construct itself around 0 instead of around the center coordinations, that is much better in a programming matter, working with relative coordinations. Then I sequentially translate it to the center.

Also, it is CLEARLY more effective. My fps skyrocketed from barely 40 to 560. I guess it uses GPU naturally?
Thank you very much with the directions provided.
 

Karlstens

Member
Did it! Modified the model so that it will construct itself around 0 instead of around the center coordinations, that is much better in a programming matter, working with relative coordinations. Then I sequentially translate it to the center.

Also, it is CLEARLY more effective. My fps skyrocketed from barely 40 to 560. I guess it uses GPU naturally?
Thank you very much with the directions provided.
I'd love to see some sample code of what you've done here, as I too am learning how to create simple triangles and rotate them.

Code:
// in my draw event of an object
// wanting to rotate the primative draw with my object angle
// I think I need to use a matrix, but first time using them

draw_primitive_begin(pr_trianglelist);

draw_vertex_colour(x+_x[0],    y+_y[0], c_blue, 1);
draw_vertex_colour(x+_x[1],    y+_y[1], c_green, 1);
draw_vertex_colour(x+_x[5],    y+_y[5], c_red, 1);

draw_vertex_colour(x+_x[4],    y+_y[4], c_red, 1);
draw_vertex_colour(x+_x[2],    y+_y[2], c_green, 1);
draw_vertex_colour(x+_x[3],    y+_y[3], c_blue, 1);


draw_primitive_end();
This obviously draws two triangles that locate with the object, but fail to rotate - which is where I'm needing to learn Matrix commands.


EDIT: oohhhh, getting closer!

Code:
var matrix = matrix_build(0,0,0,0,0,_a++,1,1,1);
matrix_set(matrix_world, matrix);

draw_primitive_begin(pr_trianglelist);
draw_vertex_colour(x+_x[0],    y+_y[0], c_blue, 1);
draw_vertex_colour(x+_x[1],    y+_y[1], c_green, 1);
draw_vertex_colour(x+_x[5],    y+_y[5], c_red, 1);

draw_vertex_colour(x+_x[4],    y+_y[4], c_red, 1);
draw_vertex_colour(x+_x[2],    y+_y[2], c_green, 1);
draw_vertex_colour(x+_x[3],    y+_y[3], c_blue, 1);
draw_primitive_end(); 

matrix_set(matrix_world,matrix_build_identity());
 
Last edited:
Top