3D GMS2 - How to find a position on a model?

T

trentallain

Guest
How do I find the position on a 3D model (Loaded using vertex buffers)?
For example, if I wanted to create an instance at a specific postion on a model (or a special effect like flames), how would I find that? The model is also being transformed, such as scaled and rotated. And also if its worth noting, my models are made of voxels.

Thanks
 

jo-thijs

Member
How do I find the position on a 3D model (Loaded using vertex buffers)?
For example, if I wanted to create an instance at a specific postion on a model (or a special effect like flames), how would I find that? The model is also being transformed, such as scaled and rotated. And also if its worth noting, my models are made of voxels.

Thanks
You'll need to be more specific about what you mean with "specific position on model".
Do you mean you know the exact coordinate before transforming the model and you want to know the coordinate after it being transformed?
In that case, you just need to apply the transformation to your point.
 
T

trentallain

Guest
You'll need to be more specific about what you mean with "specific position on model".
Do you mean you know the exact coordinate before transforming the model and you want to know the coordinate after it being transformed?
In that case, you just need to apply the transformation to your point.
I mean just finding the point in general (whether transformed or not)
 
T

trentallain

Guest
But how do you specify the point?
Can you give a simple example?
Ok, since my models are voxel, they can be drawn 1:1 with pixels. They have been scaled by 5 though. If for example, I had a point in it I wanted to create an instance from (like lasers), and it was at point x+5, y-10, z-12, how would I still find that position after it had been scaled and rotated?
 

jo-thijs

Member
Ok, since my models are voxel, they can be drawn 1:1 with pixels. They have been scaled by 5 though. If for example, I had a point in it I wanted to create an instance from (like lasers), and it was at point x+5, y-10, z-12, how would I still find that position after it had been scaled and rotated?
By scaling and rotating the point in te same manner.
The transormation that gives you scaling and rotation can be written as a matrix multiplication.
You can just simply multiply this matrix with your point to get the transformed point.
How are you currently performing the scaling and rotation?
 
T

trentallain

Guest
matrix_set(matrix_world, matrix_build(x, y, z,xangle-180, yangle, global.ship_pan+90, scale, scale, scale))
vertex_submit(model, pr_trianglelist, texture)
matrix_set(matrix_world, matrix_build(0, 0, 0, 0, 0, 0, 1, 1, 1))
 

jo-thijs

Member
matrix_set(matrix_world, matrix_build(x, y, z,xangle-180, yangle, global.ship_pan+90, scale, scale, scale))
vertex_submit(model, pr_trianglelist, texture)
matrix_set(matrix_world, matrix_build(0, 0, 0, 0, 0, 0, 1, 1, 1))
If you're using GM:S 2, there's a function matrix_transform_vertex, which you can combine with matrix_get to get the final result.
In GM:S 1.4 you can create your own function for matrix_transform_vertex:
Code:
var M = argument0;
var X = argument1;
var Y = argument2;
var Z = argument3;
var F = M[3] * X + M[7] * Y + M[11] * Z + M[15];
var result; result[2] = 0;
result[0] = (M[0] * X + M[4] * Y + M[8] * Z + M[12]) / F;
result[1] = (M[1] * X + M[5] * Y + M[9] * Z + M[13]) / F;
result[2] = (M[2] * X + M[6] * Y + M[10] * Z + M[14]) / F;
return result;
 
Top