Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
May 02, 2015 How to I translate this C++ structure/array | ||||
---|---|---|---|---|
| ||||
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 Re: How to I translate this C++ structure/array | ||||
---|---|---|---|---|
| ||||
Posted in reply to WhatMeWorry | 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 03, 2015 Re: How to I translate this C++ structure/array | ||||
---|---|---|---|---|
| ||||
Posted in reply to anonymous | On Saturday, 2 May 2015 at 22:36:29 UTC, anonymous wrote:
> 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.
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 Re: How to I translate this C++ structure/array | ||||
---|---|---|---|---|
| ||||
Posted in reply to WhatMeWorry | On Sunday, 3 May 2015 at 02:31:51 UTC, WhatMeWorry wrote: > On Saturday, 2 May 2015 at 22:36:29 UTC, anonymous wrote: [...] >> [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. 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 */ |
May 03, 2015 Re: How to I translate this C++ structure/array | ||||
---|---|---|---|---|
| ||||
Posted in reply to anonymous | On Sunday, 3 May 2015 at 10:56:44 UTC, anonymous wrote:
> On Sunday, 3 May 2015 at 02:31:51 UTC, WhatMeWorry wrote:
>> On Saturday, 2 May 2015 at 22:36:29 UTC, anonymous wrote:
> [...]
>>> [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.
>
> 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 */
Oh, sure. Code has been changed. Bad habits are hard to kill.
|
May 03, 2015 Re: How to I translate this C++ structure/array | ||||
---|---|---|---|---|
| ||||
Posted in reply to anonymous | On Sunday, 3 May 2015 at 10:56:44 UTC, anonymous wrote:
> On Sunday, 3 May 2015 at 02:31:51 UTC, WhatMeWorry wrote:
>> On Saturday, 2 May 2015 at 22:36:29 UTC, anonymous wrote:
> [...]
>>> [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.
>
> 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 */
Oh sure, I've changed the code. I wish D had been my first language.
|
Copyright © 1999-2021 by the D Language Foundation