setting statically sized multi-dimensional arrays
Ary Borenszweig
ary at esperanto.org.ar
Mon Jan 21 20:50:53 PST 2008
Spacen Jasset escribió:
> I have function below where I try to set a float[4][4] using array
> syntax. This doesn't work. Am I doing it wrongly, or is this not
> supported in dmd version 1? I seem to remember seeing something about
> this but can't remember where.
>
>
>
> void MakeRotationAboutX(float[4][4] m, float angle)
> {
> m[] = [[1f, 0, 0, 0],
> [0, cos(angle * PI / 180), sin(angle * PI / 180), 0],
> [0, -sin(angle * PI / 180), cos(angle * PI / 180), 0],
> [0, 0, 0, 1]];
> }
>
> main.d:501: Error: cannot implicitly convert expression
> ..lots of stuff..
> of type float[][4u] to float[4u]
> Command /usr/bin/rebuild returned with code 256, aborting.
Try putting the "f" suffix on the first zeros in the second, third and
foruth rows, too. It works for me:
import std.math;
void MakeRotationAboutX(float[4][4] m, float angle)
{
m[] = [[1f, 0, 0, 0],
[0f, cos(angle * PI / 180), sin(angle * PI / 180), 0],
[0f, -sin(angle * PI / 180), cos(angle * PI / 180), 0],
[0f, 0, 0, 1]];
}
More information about the Digitalmars-d-learn
mailing list