I have struct:
struct mat4 {
float m[16];
mat4();
...
float *getFloat();
}
float *mat4::getFloat() {
return m;
}
Now I want to make m equal to m from newly created matrix r:
void mat4::rotate(vec3 v) {
mat4 r, rx, ry, rz;
...
matrix calculations
...
m = *r.getFloat();
}
But this gives me error “incompatible types in assignment of ‘float’ to ‘float [16]’”
I have searched Google and tried different ways but no success so far.
Please tell me how could I do that?
r.getFloat()is returning a pointer to a single float. This is dereferenced to give a single float, and then assigned to an array of 16 floats.Assuming that
mcontains the entire state ofmat4, you can use the built in assignment operator:The compiler will automatically implement the struct dump/ memcpy to copy all 16 floats.