returning a multidimensional array

Started by
17 comments, last by Jingo 18 years, 10 months ago
Quote:Original post by Cryoknight
If all you are doing is rotation, sure. But not if you want to be able
to do the full 3d pipeline of matrix multiplications.
If you didn't need the 4x4 matrices, they wouldn't bother using them
in EVERY SINGLE 3d programming book.

All he is talking about is rotations without respect to a 3d pipeline. For all you know this isn't even related to graphics in any way.
Advertisement
True, true.

This being related to many of the most common questions
led me to believe he would be implementing the full pipeline.
Quote:Original post by Polymorphic OOP
void multmat( float (&your_matrix)[3][3], float x, float y, float z, double theta)



if your going to pass bare arrays i would recommend this version as the typical way using pointers just leads to arrays decaying to pointers (pointer decay). You know specifically the dimensions are always the same then you are just losing information using pointers. Statically allocated arrays are rich in information compared to pointers.

void multmat( float (&your_matrix)[3][3], float x, float y, float z, double theta)

is not a good way to do this, instead use this

void multmat( float your_matrix[3][3], float x, float y, float z, double theta)

it will preserve all the dimensional information, and it is passed as a pointer anyways, so don't worry about it being copied every time, 'cause it won't.
Quote:Original post by Raduprv
I would do it like this:

float rm[3][3];float[3][3] multmat(float x, float y, float z, double theta){float c = cos(theta);float s = sin(theta);float t = 1 - cos(theta);rm[0][0] = t*x*x + c;rm[1][0] = t*x*y - s*z;rm[2][0] = t*x*z + s*y;rm[0][1] = t*x*y + s*z;rm[1][1] = t*y*y + c;rm[2][1] = t*y*z - s*x;rm[0][2] = t*x*z - s*y;rm[1][2] = t*y*z + s*x;rm[2][2] = t*z*z + c;}void some_other_function(){//just use rm normally}


And if you need to use multmat from within another file. Or you need to get two different matrices?

Just pass by reference, I see that as the best solution.
-----------------Always look on the bright side of Life!
Quote:Original post by A Guy from CRO
And if you need to use multmat from within another file. Or you need to get two different matrices?

Just pass by reference, I see that as the best solution.


Then you declare it as extern in some other fle.
Quote:Original post by Cryoknight
If all you are doing is rotation, sure. But not if you want to be able
to do the full 3d pipeline of matrix multiplications.
If you didn't need the 4x4 matrices, they wouldn't bother using them
in EVERY SINGLE 3d programming book.


I've seen professional renderers that utilize 4x3 matrices, a 3x3 rotation and then the offset vector. There are plenty of different ways to work with matrices. People find shortcuts, optimizations, etc. Never convince yourself that there is only one right answer to a programming question.
moe.ron
Quote:Original post by Anonymous Poster
void multmat( float (&your_matrix)[3][3], float x, float y, float z, double theta)

is not a good way to do this, instead use this

void multmat( float your_matrix[3][3], float x, float y, float z, double theta)

it will preserve all the dimensional information, and it is passed as a pointer anyways, so don't worry about it being copied every time, 'cause it won't.

Actually, my version is the one that preserves dimension information, yours does not. Yours only preserves the number of columns and not the number of rows, whereas mine preserves both.
Im curious as to why you think

void multmat( float (&your_matrix)[3][3], float x, float y, float z, double theta)

is not a good way to do this.

This topic is closed to new replies.

Advertisement