digitalmars.D.learn - setting statically sized multi-dimensional arrays

• Spacen Jasset (15/15) Jan 21 2008 I have function below where I try to set a float[4][4] using array
• Ary Borenszweig (11/30) Jan 21 2008 Try putting the "f" suffix on the first zeros in the second, third and
• Spacen Jasset (13/46) Jan 22 2008 It still fails with the same error, I did try adding the 'f' suffix, and...
• Hoenir (4/11) Jan 22 2008 why don't you use an extra function for the conversion of deg to rad? it...
• Hoenir (1/1) Jan 22 2008 Oh and yet another thing: angle is in degrees, why is it a float?
• Bill Baxter (3/4) Jan 22 2008 Maybe he wants better than 1:360 precision?
• Hoenir (2/3) Jan 22 2008 I didn't consider that, thanks for your answer :)
• Bill Baxter (5/17) Jan 22 2008 Unless he's using row vectors and v' = v * R
• Hoenir (2/5) Jan 22 2008 Ah I see, I read it like a normal matrix on paper.
Spacen Jasset <spacenjasset yahoo.co.uk> writes:
```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.

{
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.
```
Jan 21 2008
Ary Borenszweig <ary esperanto.org.ar> writes:
```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.

{
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;

{
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]];
}
```
Jan 21 2008
Spacen Jasset <spacenjassset yahoo.co.uk> writes:
```Ary Borenszweig wrote:
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.

{
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;

{
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]];
}

It still fails with the same error, I did try adding the 'f' suffix, and
it's probably needed, but that didn't fix it.

I have:

On windows:
Digital Mars D Compiler v1.015
Copyright (c) 1999-2007 by Digital Mars written by Walter Bright

And on linux:

gdc (GCC) 4.1.3 20070831 (prerelease gdc 0.25, using dmd 1.021) (Ubuntu
0.25-4.1.2-16ubuntu1)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```
Jan 22 2008
Hoenir <mrmocool gmx.de> writes:
```Spacen Jasset schrieb:
{
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]];
}

why don't you use an extra function for the conversion of deg to rad? it
will get inlined by the compiler so there's no efficiency loss.

btw you rotate clockwise, is this intented?
```
Jan 22 2008
Hoenir <mrmocool gmx.de> writes:
```Oh and yet another thing: angle is in degrees, why is it a float?
```
Jan 22 2008
Bill Baxter <dnewsgroup billbaxter.com> writes:
```Hoenir wrote:
Oh and yet another thing: angle is in degrees, why is it a float?

Maybe he wants better than 1:360 precision?

--bb
```
Jan 22 2008
Hoenir <mrmocool gmx.de> writes:
```Bill Baxter schrieb:
Maybe he wants better than 1:360 precision?

```
Jan 22 2008
Bill Baxter <dnewsgroup billbaxter.com> writes:
```Hoenir wrote:
Spacen Jasset schrieb:
{
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]];
}

why don't you use an extra function for the conversion of deg to rad? it
will get inlined by the compiler so there's no efficiency loss.

btw you rotate clockwise, is this intented?

Unless he's using row vectors and  v' = v * R
Or storing the matrix in column major format for use with Fortran and/or
OpenGL (most likely).

--bb
```
Jan 22 2008
Hoenir <mrmocool gmx.de> writes:
```Bill Baxter schrieb:
Unless he's using row vectors and  v' = v * R
Or storing the matrix in column major format for use with Fortran and/or
OpenGL (most likely).

Ah I see, I read it like a normal matrix on paper.
```
Jan 22 2008