C++ code to D (multi dem 3d mesh)
Joel
joelcnz at gmail.com
Tue Oct 27 07:00:07 UTC 2020
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))];
More information about the Digitalmars-d-learn
mailing list