www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - C++ code to D (multi dem 3d mesh)

reply Joel <joelcnz gmail.com> writes:
```
struct vec3d
{
	float x, y, z;
}

struct triangle
{
	vec3d[3] p;
}

struct mesh
{
	triangle[] tris;
}

// This here
meshCube.tris = {

		// SOUTH
		{ 0.0f, 0.0f, 0.0f,    0.0f, 1.0f, 0.0f,    1.0f, 1.0f, 0.0f },
		{ 0.0f, 0.0f, 0.0f,    1.0f, 1.0f, 0.0f,    1.0f, 0.0f, 0.0f },

		// EAST
		{ 1.0f, 0.0f, 0.0f,    1.0f, 1.0f, 0.0f,    1.0f, 1.0f, 1.0f },
		{ 1.0f, 0.0f, 0.0f,    1.0f, 1.0f, 1.0f,    1.0f, 0.0f, 1.0f },

		// NORTH
		{ 1.0f, 0.0f, 1.0f,    1.0f, 1.0f, 1.0f,    0.0f, 1.0f, 1.0f },
		{ 1.0f, 0.0f, 1.0f,    0.0f, 1.0f, 1.0f,    0.0f, 0.0f, 1.0f },

		// WEST
		{ 0.0f, 0.0f, 1.0f,    0.0f, 1.0f, 1.0f,    0.0f, 1.0f, 0.0f },
		{ 0.0f, 0.0f, 1.0f,    0.0f, 1.0f, 0.0f,    0.0f, 0.0f, 0.0f },

		// TOP
		{ 0.0f, 1.0f, 0.0f,    0.0f, 1.0f, 1.0f,    1.0f, 1.0f, 1.0f },
		{ 0.0f, 1.0f, 0.0f,    1.0f, 1.0f, 1.0f,    1.0f, 1.0f, 0.0f },

		// BOTTOM
		{ 1.0f, 0.0f, 1.0f,    0.0f, 0.0f, 1.0f,    0.0f, 0.0f, 0.0f },
		{ 1.0f, 0.0f, 1.0f,    0.0f, 0.0f, 0.0f,    1.0f, 0.0f, 0.0f },

		};
```

See:
https://youtu.be/ih20l3pJoeU
https://github.com/OneLoneCoder/videos/blob/master/OneLoneCoder_olcEngine3D_Part1.cpp
Oct 26 2020
next sibling parent Joel <joelcnz gmail.com> writes:
On Monday, 26 October 2020 at 23:38:22 UTC, Joel wrote:
 ```
 struct vec3d
 {
 	float x, y, z;
 }

 struct triangle
 {
 	vec3d[3] p;
 }

 struct mesh
 {
 	triangle[] tris;
 }

 // This here
 meshCube.tris = {

 		// SOUTH
 		{ 0.0f, 0.0f, 0.0f,    0.0f, 1.0f, 0.0f,    1.0f, 1.0f, 0.0f 
 },
 		{ 0.0f, 0.0f, 0.0f,    1.0f, 1.0f, 0.0f,    1.0f, 0.0f, 0.0f 
 },

 		// EAST
 		{ 1.0f, 0.0f, 0.0f,    1.0f, 1.0f, 0.0f,    1.0f, 1.0f, 1.0f 
 },
 		{ 1.0f, 0.0f, 0.0f,    1.0f, 1.0f, 1.0f,    1.0f, 0.0f, 1.0f 
 },

 		// NORTH
 		{ 1.0f, 0.0f, 1.0f,    1.0f, 1.0f, 1.0f,    0.0f, 1.0f, 1.0f 
 },
 		{ 1.0f, 0.0f, 1.0f,    0.0f, 1.0f, 1.0f,    0.0f, 0.0f, 1.0f 
 },

 		// WEST
 		{ 0.0f, 0.0f, 1.0f,    0.0f, 1.0f, 1.0f,    0.0f, 1.0f, 0.0f 
 },
 		{ 0.0f, 0.0f, 1.0f,    0.0f, 1.0f, 0.0f,    0.0f, 0.0f, 0.0f 
 },

 		// TOP
 		{ 0.0f, 1.0f, 0.0f,    0.0f, 1.0f, 1.0f,    1.0f, 1.0f, 1.0f 
 },
 		{ 0.0f, 1.0f, 0.0f,    1.0f, 1.0f, 1.0f,    1.0f, 1.0f, 0.0f 
 },

 		// BOTTOM
 		{ 1.0f, 0.0f, 1.0f,    0.0f, 0.0f, 1.0f,    0.0f, 0.0f, 0.0f 
 },
 		{ 1.0f, 0.0f, 1.0f,    0.0f, 0.0f, 0.0f,    1.0f, 0.0f, 0.0f 
 },

 		};
 ```

 See:
 https://youtu.be/ih20l3pJoeU
 https://github.com/OneLoneCoder/videos/blob/master/OneLoneCoder_olcEngine3D_Part1.cpp
This is what I came up with: meshCube.tris = // south [triangle(vec3d(0f,0f,0f)), triangle(vec3d(0f,1f,0f)), triangle(vec3d(1f,1f,0f)), triangle(vec3d(0f,0f,0f)), triangle(vec3d(1f,1f,0f)), triangle(vec3d(1f,0f,0f)), // east triangle(vec3d(1f,0f,0f)), triangle(vec3d(1f,1f,0f)), triangle(vec3d(1f,1f,1f)), triangle(vec3d(1f,0f,0f)), triangle(vec3d(1f,1f,1f)), triangle(vec3d(1f,0f,1f)), // north triangle(vec3d(1f,0f,1f)), triangle(vec3d(1f,1f,1f)), triangle(vec3d(0f,1f,1f)), triangle(vec3d(1f,0f,1f)), triangle(vec3d(0f,1f,1f)), triangle(vec3d(0f,0f,1f)), // west triangle(vec3d(0f,0f,1f)), triangle(vec3d(0f,1f,1f)), triangle(vec3d(0f,1f,0f)), triangle(vec3d(0f,0f,1f)), triangle(vec3d(0f,1f,0f)), triangle(vec3d(0f,0f,0f)), // top triangle(vec3d(0f,1f,0f)), triangle(vec3d(0f,1f,1f)), triangle(vec3d(1f,1f,1f)), triangle(vec3d(0f,1f,0f)), triangle(vec3d(1f,1f,1f)), triangle(vec3d(1f,1f,0f)), // bottom triangle(vec3d(1f,0f,1f)), triangle(vec3d(0f,0f,1f)), triangle(vec3d(0f,0f,0f)), triangle(vec3d(1f,0f,1f)), triangle(vec3d(0f,0f,0f)), triangle(vec3d(1f,0f,0f))];
Oct 27 2020
prev sibling parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Monday, 26 October 2020 at 23:38:22 UTC, Joel wrote:
 ```
 struct vec3d
 {
 	float x, y, z;
 }

 [...]
It's not really clear what your question is.
Oct 27 2020
parent reply Joel <joelcnz gmail.com> writes:
On Tuesday, 27 October 2020 at 07:17:46 UTC, Imperatorn wrote:
 On Monday, 26 October 2020 at 23:38:22 UTC, Joel wrote:
 ```
 struct vec3d
 {
 	float x, y, z;
 }

 [...]
It's not really clear what your question is.
I'm trying to convert from C++ code to D code, see where I've put '// This here' - with all the data. I found one way. I think I've thought of another way too.
Oct 27 2020
parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Tuesday, 27 October 2020 at 07:32:30 UTC, Joel wrote:
 On Tuesday, 27 October 2020 at 07:17:46 UTC, Imperatorn wrote:
 On Monday, 26 October 2020 at 23:38:22 UTC, Joel wrote:
 ```
 struct vec3d
 {
 	float x, y, z;
 }

 [...]
It's not really clear what your question is.
I'm trying to convert from C++ code to D code, see where I've put '// This here' - with all the data. I found one way. I think I've thought of another way too.
Ok, some steps have to be done manually. Just wanted to share some links that might be interesting when converting in the future: https://github.com/lhamot/CPP2D https://github.com/jacob-carlborg/dstep https://github.com/atilaneves/dpp http://www.swig.org/Doc4.0/D.html https://dlang.org/htod.html
Oct 27 2020
parent Joel <joelcnz gmail.com> writes:
On Tuesday, 27 October 2020 at 08:14:28 UTC, Imperatorn wrote:
 On Tuesday, 27 October 2020 at 07:32:30 UTC, Joel wrote:
 On Tuesday, 27 October 2020 at 07:17:46 UTC, Imperatorn wrote:
 On Monday, 26 October 2020 at 23:38:22 UTC, Joel wrote:
 ```
 struct vec3d
 {
 	float x, y, z;
 }

 [...]
It's not really clear what your question is.
I'm trying to convert from C++ code to D code, see where I've put '// This here' - with all the data. I found one way. I think I've thought of another way too.
Ok, some steps have to be done manually. Just wanted to share some links that might be interesting when converting in the future: https://github.com/lhamot/CPP2D https://github.com/jacob-carlborg/dstep https://github.com/atilaneves/dpp http://www.swig.org/Doc4.0/D.html https://dlang.org/htod.html
Thanks, I've bookmarked this.
Oct 27 2020