tags:

views:

67

answers:

2
TransformationMatrices[mesh_count-1][0] = n->mTransformation.a1; 
TransformationMatrices[mesh_count-1][1] = n->mTransformation.a2;
TransformationMatrices[mesh_count-1][2] = n->mTransformation.a3;
TransformationMatrices[mesh_count-1][3] = n->mTransformation.a4;
TransformationMatrices[mesh_count-1][4] = n->mTransformation.b1;
TransformationMatrices[mesh_count-1][5] = n->mTransformation.b2;
TransformationMatrices[mesh_count-1][6] = n->mTransformation.b3;
TransformationMatrices[mesh_count-1][7] = n->mTransformation.b4;
TransformationMatrices[mesh_count-1][8] = n->mTransformation.c1;
TransformationMatrices[mesh_count-1][9] = n->mTransformation.c2;
TransformationMatrices[mesh_count-1][10] = n->mTransformation.c3;
TransformationMatrices[mesh_count-1][11] = n->mTransformation.c4;
TransformationMatrices[mesh_count-1][12] = n->mTransformation.d1;
TransformationMatrices[mesh_count-1][13] = n->mTransformation.d2;
TransformationMatrices[mesh_count-1][14] = n->mTransformation.d3;
TransformationMatrices[mesh_count-1][15] = n->mTransformation.d4;

edit: Replace as in replace with a shorter form.

+1  A: 

Well, you have your choice,

  1. A simple way which depends upon implementation-define layout rules. or
  2. A very complex way which is cross-platform, but much more code than you've already got.

Method 1) would go something like this:

 double *dest = &TransformationMatrices[mesh_count-1][0];
 double *src = &n->mTransformation.a1;    

 memcpy(dest, src, sizeof(double) * 16);

This depends on all kinds of undefined behavior, be should work.....

James Curran
+1  A: 

Not completely sure I follow the question, but you can use the preprocessor to shorten this quite a bit. For example,

int WriteIndex = 0;
#define WRITE_MATRIX(prefix) \
    do { \
        TransformationMatrices[mesh_count-1][WriteIndex++] = n->mTransformation.prefix ## 1; \
        TransformationMatrices[mesh_count-1][WriteIndex++] = n->mTransformation.prefix ## 2; \
        TransformationMatrices[mesh_count-1][WriteIndex++] = n->mTransformation.prefix ## 3; \
        TransformationMatrices[mesh_count-1][WriteIndex++] = n->mTransformation.prefix ## 4; \
    } while(0)
WRITE_MATRIX(a);
WRITE_MATRIX(b);
WRITE_MATRIX(c);
WRITE_MATRIX(d);

I wouldn't write the code exactly this way, but it demonstrates the technique...

Aidan Cully
mmm.. that's pretty good. Of course it takes the clutter out of a .c file and puts it it a .h file, but still prettier.
Lela Dax
The #define can go into the .c file just fine, if you're only doing this in one place.
Aidan Cully
Yeah I mean it takes it out of the function that it was before but still prettier for readability in that function.
Lela Dax