• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

 Add pivot/origin point to matrix_build [SUGESTION]

when using sprites... (that already have a defined origin point)
matrix_build is okay..

but when using surfaces (origin point is always [0,0])
matrix_build could have an advanced mode to help with that...

instead of :
Code:
///matrix_build_adv(x, y, z, xpivot, ypivot, zpivot, rotationx, rotationy, rotationz, xscale, yscale, zscale)

// if there is rotation
if (argument6 || argument7 || argument8) {
    var rotation = matrix_build(0, 0, 0, argument6, argument7, argument8, 1, 1, 1);
   
    // if there is a pivot point
    if (argument3 || argument4 || argument5) {
        // create a -pivot point matrix
        var i_origin = matrix_build(-argument3, -argument4, -argument5, 0, 0, 0, 1, 1, 1);
        // create a pivot point matrix
        var origin = matrix_build(argument3, argument4, argument5, 0, 0, 0, 1, 1, 1);
        
        //multiply ((pivot inverse * rotation) * pivot)
        rotation = matrix_multiply(matrix_multiply(i_origin, rotation), origin);
    }
}

// build the position + scale matrix
var position = matrix_build(argument0, argument1, argument2, 0, 0, 0, argument9, argument10, argument11);

// apply the rotation to the previous matrix
transform = matrix_multiply(rotation, position);
which needs 4x matrix_build and 3x matrix_multiply... and keeping in mind that surfaces origin point is [0, 0] and by what I was told this will not change... I think this would be a good addition to the GML function set.
What do you think?!

NOTE:
I was going to ask for matrix2d functions as 99% of the gamemaker games are 2d
but I gave up as I don't think it will done.
 
Last edited:

Binsk

Member
A somewhat simpler version I whipped up. Only two multiplies and three builds:
Code:
///@name matrix_build_adv
///@description Build a matrix that rotates around a custom pivot point
///@param x
///@param y
///@param z
///@param xpivot
///@param ypivot
///@param zpivot
///@param rotationx
///@param rotationy
///@param rotationz
///@param xscale
///@param yscale
///@param zscale
       
// Translate so that the origin is at our pivot point
// Also, scale the image here so it scales around the local axes
var __matrixOrigin = matrix_build(-argument3 * argument9,
                                 -argument4 * argument10,
                                 -argument5 * argument11,
                                 0, 0, 0,
                                 argument9, argument10, argument11);

// Rotate the image around our new origin
var __matrixRotation = matrix_build(0, 0, 0,
                                   argument6, argument7, argument8,
                                    1, 1, 1);
                             
// Translate the image back to the final draw position:
var __matrixTranslate = matrix_build(argument0 + argument3,
                                    argument1 + argument4,
                                    argument2 + argument5,
                                    0, 0, 0,
                                    1, 1, 1);
                     
// Two matrix multiplications to combine our results           
var __matrixFinal = matrix_multiply(__matrixOrigin, __matrixRotation);
__matrixFinal = matrix_multiply(__matrixFinal, __matrixTranslate);
return __matrixFinal;
Honestly that isn't all that bad. Building a matrix that does the 'complex' task that you desire is going to require more complex math. Whether you program it yourself or it is programmed into GameMaker, it is going to have to do something like this either way.

Since the above script can be written easily and very little time I, personally, think it is unnecessary. That is just my opinion, though.
 
A somewhat simpler version I whipped up. Only two multiplies and three builds:
Code:
///@name matrix_build_adv
///@description Build a matrix that rotates around a custom pivot point
///@param x
///@param y
///@param z
///@param xpivot
///@param ypivot
///@param zpivot
///@param rotationx
///@param rotationy
///@param rotationz
///@param xscale
///@param yscale
///@param zscale
      
// Translate so that the origin is at our pivot point
// Also, scale the image here so it scales around the local axes
var __matrixOrigin = matrix_build(-argument3 * argument9,
                                 -argument4 * argument10,
                                 -argument5 * argument11,
                                 0, 0, 0,
                                 argument9, argument10, argument11);

// Rotate the image around our new origin
var __matrixRotation = matrix_build(0, 0, 0,
                                   argument6, argument7, argument8,
                                    1, 1, 1);
                            
// Translate the image back to the final draw position:
var __matrixTranslate = matrix_build(argument0 + argument3,
                                    argument1 + argument4,
                                    argument2 + argument5,
                                    0, 0, 0,
                                    1, 1, 1);
                    
// Two matrix multiplications to combine our results          
var __matrixFinal = matrix_multiply(__matrixOrigin, __matrixRotation);
__matrixFinal = matrix_multiply(__matrixFinal, __matrixTranslate);
return __matrixFinal;
Honestly that isn't all that bad. Building a matrix that does the 'complex' task that you desire is going to require more complex math. Whether you program it yourself or it is programmed into GameMaker, it is going to have to do something like this either way.

Since the above script can be written easily and very little time I, personally, think it is unnecessary. That is just my opinion, though.
Yeah that is simpler... but then again.... doing it with a build in function would be faster because it would already be optimised for that... and also would be programmed in native language (also makes it faster, I think)
 

Mike

nobody important
GMC Elder
We have no plans to add this, especially as it's easy to do in GML using functions that already exist.

It would be a little faster sure, but not much - especially if you use YYC, then it would be about the same.
 
Okay, then :) thank for your answer (if it performance is about the same, its not a big deal. As you said it is easily done, via scripting :)
 
Top