digitalmars.D.learn - How to I translate this C++ structure/array
- WhatMeWorry (35/35) May 02 2015 This is probably trivial but I just can't make a break thru.
- anonymous (11/26) May 02 2015 You have to be explicit:
- WhatMeWorry (4/34) May 02 2015 Thanks. I assume you would prefer I use triangle[] but with
- anonymous (6/11) May 03 2015 No no, Vertex[6] as a type is fine. It's about where you put that
- WhatMeWorry (2/14) May 03 2015 Oh, sure. Code has been changed. Bad habits are hard to kill.
- WhatMeWorry (3/15) May 03 2015 Oh sure, I've changed the code. I wish D had been my first
This is probably trivial but I just can't make a break thru.
I've got C++ code using glm like so:
struct Vertex
{
glm::vec3 position;
glm::vec3 color;
}
Vertex triangle[] =
[
glm::vec3(0.0, 1.0, 0.0),
glm::vec3(1.0, 0.0, 0.0), // red
// code removed for brevity.
];
And in D I'm using the gl3n library instead of glm.
struct Vertex
{
vec3 position;
vec3 color;
}
Vertex triangle[6] =
[
vec3(0.0, 1.0, 0.0),
vec3(1.0, 0.0, 0.0), // red
// code removed for brevity.
];
I keep getting the following:
MeGlWindow.d(171): Error: cannot implicitly convert expression
(Vector([0.000000F, 1.00000F, 0.000000F])) of type Vector!(float,
3) to Vertex
MeGlWindow.d(172): Error: cannot implicitly convert expression
(Vector([1.00000F, 0.000000F, 0.000000F])) of type Vector!(float,
3) to Vertex
MeGlWindow.d(174): Error: cannot implicitly convert expression
(Vector([-1F, -1F, 0.000000F])) of type Vector!(float, 3) to
Vertex
May 02 2015
On Saturday, 2 May 2015 at 22:01:10 UTC, WhatMeWorry wrote:
struct Vertex
{
vec3 position;
vec3 color;
}
Vertex triangle[6] =
[
vec3(0.0, 1.0, 0.0),
vec3(1.0, 0.0, 0.0), // red
// code removed for brevity.
];
I keep getting the following:
MeGlWindow.d(171): Error: cannot implicitly convert expression
(Vector([0.000000F, 1.00000F, 0.000000F])) of type
Vector!(float, 3) to Vertex
You have to be explicit:
Vertex[6] triangle = /* [1] */
[
Vertex(
vec3(0.0, 1.0, 0.0),
vec3(1.0, 0.0, 0.0), // red
),
...
];
[1] `Vertex triangle[6]` works, but please don't do that.
May 02 2015
On Saturday, 2 May 2015 at 22:36:29 UTC, anonymous wrote:On Saturday, 2 May 2015 at 22:01:10 UTC, WhatMeWorry wrote:Thanks. I assume you would prefer I use triangle[] but with OpenGL calls the dynamic arrays don't work. But maybe that is another question for another time.struct Vertex { vec3 position; vec3 color; } Vertex triangle[6] = [ vec3(0.0, 1.0, 0.0), vec3(1.0, 0.0, 0.0), // red // code removed for brevity. ]; I keep getting the following: MeGlWindow.d(171): Error: cannot implicitly convert expression (Vector([0.000000F, 1.00000F, 0.000000F])) of type Vector!(float, 3) to VertexYou have to be explicit: Vertex[6] triangle = /* [1] */ [ Vertex( vec3(0.0, 1.0, 0.0), vec3(1.0, 0.0, 0.0), // red ), ... ]; [1] `Vertex triangle[6]` works, but please don't do that.
May 02 2015
On Sunday, 3 May 2015 at 02:31:51 UTC, WhatMeWorry wrote:On Saturday, 2 May 2015 at 22:36:29 UTC, anonymous wrote:[...]No no, Vertex[6] as a type is fine. It's about where you put that "[6]": Vertex[6] triangle; /* D style - yay */ Vertex triangle[6]; /* C style - boo */[1] `Vertex triangle[6]` works, but please don't do that.Thanks. I assume you would prefer I use triangle[] but with OpenGL calls the dynamic arrays don't work. But maybe that is another question for another time.
May 03 2015
On Sunday, 3 May 2015 at 10:56:44 UTC, anonymous wrote:On Sunday, 3 May 2015 at 02:31:51 UTC, WhatMeWorry wrote:Oh, sure. Code has been changed. Bad habits are hard to kill.On Saturday, 2 May 2015 at 22:36:29 UTC, anonymous wrote:[...]No no, Vertex[6] as a type is fine. It's about where you put that "[6]": Vertex[6] triangle; /* D style - yay */ Vertex triangle[6]; /* C style - boo */[1] `Vertex triangle[6]` works, but please don't do that.Thanks. I assume you would prefer I use triangle[] but with OpenGL calls the dynamic arrays don't work. But maybe that is another question for another time.
May 03 2015
On Sunday, 3 May 2015 at 10:56:44 UTC, anonymous wrote:On Sunday, 3 May 2015 at 02:31:51 UTC, WhatMeWorry wrote:Oh sure, I've changed the code. I wish D had been my first language.On Saturday, 2 May 2015 at 22:36:29 UTC, anonymous wrote:[...]No no, Vertex[6] as a type is fine. It's about where you put that "[6]": Vertex[6] triangle; /* D style - yay */ Vertex triangle[6]; /* C style - boo */[1] `Vertex triangle[6]` works, but please don't do that.Thanks. I assume you would prefer I use triangle[] but with OpenGL calls the dynamic arrays don't work. But maybe that is another question for another time.
May 03 2015









"WhatMeWorry" <kheaser gmail.com> 