From 5257780490d49f384f09955b8617e362653fc71b Mon Sep 17 00:00:00 2001 From: Miguel Date: Thu, 16 Aug 2018 10:25:10 -0500 Subject: [PATCH 01/32] Change xy_ratio to xyRatio --- source/tests/perspectivetest.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/tests/perspectivetest.d b/source/tests/perspectivetest.d index 3b9b963..c9cb905 100644 --- a/source/tests/perspectivetest.d +++ b/source/tests/perspectivetest.d @@ -68,7 +68,7 @@ void perspectiveTest() int uZn = perspectiveProgram.getUniformLocation("z_near"); int uZf = perspectiveProgram.getUniformLocation("z_far"); int alpha = perspectiveProgram.getUniformLocation("alpha"); - int xy_ratio = perspectiveProgram.getUniformLocation("xy_ratio"); + int xyRatio = perspectiveProgram.getUniformLocation("xy_ratio"); writeln("uZn location = ", uZn); writeln("zf location = ", uZf); @@ -76,7 +76,7 @@ void perspectiveTest() perspectiveProgram.setUniform!(1, "f")(uZn, [1.0f]); perspectiveProgram.setUniform!(1, "f")(uZf, [10.0f]); perspectiveProgram.setUniform!(1, "f")(alpha, [45.0f]); - perspectiveProgram.setUniform!(1, "f")(xy_ratio, [800.0f / 600.0f]); + perspectiveProgram.setUniform!(1, "f")(xyRatio, [800.0f / 600.0f]); float gotZf = 0.0f; perspectiveProgram.getUniform!"f"(uZf, &gotZf); From c0932a30e5d7e9ea18a63f67c8b5698efe708c55 Mon Sep 17 00:00:00 2001 From: Miguel Date: Sat, 18 Aug 2018 19:40:34 -0500 Subject: [PATCH 02/32] Complete perspective test --- .editorconfig | 7 + format.sh | 2 +- shaders/perspective-vertex.glsl | 5 +- source/.editorconfig | 6 - source/app.d | 2 +- source/heightmap/heightfunction.d | 2 +- source/heightmap/heightmap.d | 92 +++++++------- source/heightmap/quev.d | 180 +++++++++++++------------- source/heightmap/renderer.d | 115 ++++++++--------- source/tests/heightmaptest.d | 14 +- source/tests/perspectivetest.d | 205 +++++++++++++++++------------- 11 files changed, 332 insertions(+), 298 deletions(-) create mode 100644 .editorconfig delete mode 100644 source/.editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..86af6a6 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +# EditorConfig + +root = true + +[*.d] +indent_style = space +max_line_length = 80 diff --git a/format.sh b/format.sh index 7704b99..0c045e3 100644 --- a/format.sh +++ b/format.sh @@ -1,3 +1,3 @@ #!/bin/bash -find . -name "*.d" -exec dfmt -i '{}' ';' +find . -name "*.d" -exec dfmt -i '{}' --indent_style space --max_line_length 80 --soft_max_line_length 80 ';' diff --git a/shaders/perspective-vertex.glsl b/shaders/perspective-vertex.glsl index 751e985..991a65b 100644 --- a/shaders/perspective-vertex.glsl +++ b/shaders/perspective-vertex.glsl @@ -7,6 +7,7 @@ uniform float z_near; uniform float z_far; uniform float alpha; uniform float xy_ratio; +uniform vec3 translation; uniform mat3 rotation; out vec4 v_color; @@ -19,7 +20,9 @@ void main() 0, 0, (z_far + z_near)/(z_far - z_near), -1, 0, 0, 2 * z_far * z_near/(z_far - z_near), 0); - gl_Position = perspective * vec4(in_position, 1); + vec3 rotated = rotation * in_position; + vec3 translated = rotated + translation; + gl_Position = perspective * vec4(translated, 1); v_color = in_color; } diff --git a/source/.editorconfig b/source/.editorconfig deleted file mode 100644 index f71b08a..0000000 --- a/source/.editorconfig +++ /dev/null @@ -1,6 +0,0 @@ -# EditorConfig - -root = true - -[*.d] -indent_style = tab diff --git a/source/app.d b/source/app.d index 7b3b6ba..d107239 100644 --- a/source/app.d +++ b/source/app.d @@ -11,5 +11,5 @@ import daque.math.geometry; void main() { - perspectiveTest(); + perspectiveTest(); } diff --git a/source/heightmap/heightfunction.d b/source/heightmap/heightfunction.d index 0027148..a8f6480 100644 --- a/source/heightmap/heightfunction.d +++ b/source/heightmap/heightfunction.d @@ -2,5 +2,5 @@ module viare.heightmap.heightfunction; interface HeightFunction { - double opCall(double x, double y); + double opCall(double x, double y); } diff --git a/source/heightmap/heightmap.d b/source/heightmap/heightmap.d index ee67bd9..29f79a4 100644 --- a/source/heightmap/heightmap.d +++ b/source/heightmap/heightmap.d @@ -5,62 +5,62 @@ import viare.heightmap.heightfunction; class HeightMap { private: - float[][] m_height; - const uint m_xlength; - const uint m_ylength; + float[][] m_height; + const uint m_xlength; + const uint m_ylength; public: - this(uint width, uint height) - { - m_xlength = width; - m_ylength = height; + this(uint width, uint height) + { + m_xlength = width; + m_ylength = height; - import std.algorithm; + import std.algorithm; - m_height.length = width; - m_height.each!((ref column) => column.length = height); - m_height.each!((ref column) => column.each!((ref element) => element = 0)); - } + m_height.length = width; + m_height.each!((ref column) => column.length = height); + m_height.each!((ref column) => column.each!((ref element) => element = 0)); + } - uint getWidth() - { - return m_xlength; - } + uint getWidth() + { + return m_xlength; + } - uint getHeight() - { - return m_ylength; - } + uint getHeight() + { + return m_ylength; + } - ref float opIndex(uint i, uint j) - { - return m_height[i][j]; - } + ref float opIndex(uint i, uint j) + { + return m_height[i][j]; + } - void fillByHeightFunction(HeightFunction heightFunction) - { - for (uint i; i < m_xlength; i++) - for (uint j; j < m_ylength; j++) - this[i, j] = heightFunction(cast(float) i / m_xlength, cast(float) j / m_ylength); - } + void fillByHeightFunction(HeightFunction heightFunction) + { + for (uint i; i < m_xlength; i++) + for (uint j; j < m_ylength; j++) + this[i, j] = heightFunction(cast(float) i / m_xlength, cast(float) j / m_ylength); + } - void normalize() - { - float lowest = this[0, 0], highest = this[0, 0]; + void normalize() + { + float lowest = this[0, 0], highest = this[0, 0]; - for (uint i; i < m_xlength; i++) - for (uint j; j < m_ylength; j++) - { - if (this[i, j] < lowest) - lowest = this[i, j]; - if (this[i, j] > highest) - highest = this[i, j]; - } + for (uint i; i < m_xlength; i++) + for (uint j; j < m_ylength; j++) + { + if (this[i, j] < lowest) + lowest = this[i, j]; + if (this[i, j] > highest) + highest = this[i, j]; + } - immutable maxRelativeHeight = highest - lowest; + immutable maxRelativeHeight = highest - lowest; - for (uint i; i < m_xlength; i++) - for (uint j; j < m_ylength; j++) - this[i, j] = (this[i, j] - lowest) / maxRelativeHeight; - } + for (uint i; i < m_xlength; i++) + for (uint j; j < m_ylength; j++) + this[i, j] = (this[i, j] - lowest) / maxRelativeHeight; + } } diff --git a/source/heightmap/quev.d b/source/heightmap/quev.d index 21150fe..6d7a631 100644 --- a/source/heightmap/quev.d +++ b/source/heightmap/quev.d @@ -8,111 +8,111 @@ import viare.heightmap.heightfunction; struct QuevCenter { - double[2] position; - double weight; - double base; - double exponent; - double zoom; + double[2] position; + double weight; + double base; + double exponent; + double zoom; } interface QuevCentersGenerator { - QuevCenter[] opCall(uint noCenters); + QuevCenter[] opCall(uint noCenters); } class StdQuevCentersGenerator : QuevCentersGenerator { private: - Params m_params; + Params m_params; public: - struct Params - { - double[2]delegate() positionGenerator; - double delegate() weightGenerator; - double delegate() baseGenerator; - double delegate() exponentGenerator; - double delegate() zoomGenerator; - } - - static Params defaultParams; - - static this() - { - defaultParams.positionGenerator = { - double x = uniform!"[)"(0.0, 1.0); - double y = uniform!"[)"(0.0, 1.0); - double[2] position = [x, y]; - return position; - }; - defaultParams.weightGenerator = { return uniform!"[]"(-1.0, 1.0); }; - defaultParams.baseGenerator = { return uniform!"[]"(20.1, 40.2); }; - defaultParams.exponentGenerator = { return uniform!"[]"(1.2, 1.5); }; - defaultParams.zoomGenerator = { return uniform!"[]"(0.125, 0.175); }; - } - - this(Params params) - { - m_params = params; - } - - this() - { - this(defaultParams); - } - - QuevCenter[] opCall(uint noCenters) - { - QuevCenter[] centers; - for (uint centerNo; centerNo < noCenters; centerNo++) - { - QuevCenter newCenter; - newCenter.position[] = m_params.positionGenerator()[]; - newCenter.weight = m_params.weightGenerator(); - newCenter.base = m_params.baseGenerator(); - newCenter.exponent = m_params.exponentGenerator(); - newCenter.zoom = m_params.zoomGenerator(); - centers ~= newCenter; - } - return centers; - } + struct Params + { + double[2]delegate() positionGenerator; + double delegate() weightGenerator; + double delegate() baseGenerator; + double delegate() exponentGenerator; + double delegate() zoomGenerator; + } + + static Params defaultParams; + + static this() + { + defaultParams.positionGenerator = { + double x = uniform!"[)"(0.0, 1.0); + double y = uniform!"[)"(0.0, 1.0); + double[2] position = [x, y]; + return position; + }; + defaultParams.weightGenerator = { return uniform!"[]"(-1.0, 1.0); }; + defaultParams.baseGenerator = { return uniform!"[]"(20.1, 40.2); }; + defaultParams.exponentGenerator = { return uniform!"[]"(1.2, 1.5); }; + defaultParams.zoomGenerator = { return uniform!"[]"(0.125, 0.175); }; + } + + this(Params params) + { + m_params = params; + } + + this() + { + this(defaultParams); + } + + QuevCenter[] opCall(uint noCenters) + { + QuevCenter[] centers; + for (uint centerNo; centerNo < noCenters; centerNo++) + { + QuevCenter newCenter; + newCenter.position[] = m_params.positionGenerator()[]; + newCenter.weight = m_params.weightGenerator(); + newCenter.base = m_params.baseGenerator(); + newCenter.exponent = m_params.exponentGenerator(); + newCenter.zoom = m_params.zoomGenerator(); + centers ~= newCenter; + } + return centers; + } } class QuevHeightFunction : HeightFunction { private: - QuevCenter[] m_centers; - double[] m_threshholds; + QuevCenter[] m_centers; + double[] m_threshholds; - static immutable epsilon = 0.01; + static immutable epsilon = 0.01; public: - this(QuevCenter[] centers) - { - m_centers.length = centers.length; - m_centers[] = centers[]; - - m_threshholds.length = m_centers.length; - - foreach (uint i, QuevCenter center; m_centers) - { - m_threshholds[i] = center.zoom * pow(-log(epsilon / abs(center.weight)) / log(center.base), - 1.0 / center.exponent); - } - } - - double opCall(double x, double y) - { - double[2] point = [x, y]; - double total = 0.0; - - foreach (uint i, QuevCenter center; m_centers) - { - immutable distanceToCenter = distance!double(point, center.position); - if (distanceToCenter > m_threshholds[i]) - continue; - - total += center.weight * pow(center.base, - -pow(distanceToCenter / center.zoom, center.exponent)); - } - return total; - } + this(QuevCenter[] centers) + { + m_centers.length = centers.length; + m_centers[] = centers[]; + + m_threshholds.length = m_centers.length; + + foreach (uint i, QuevCenter center; m_centers) + { + m_threshholds[i] = center.zoom * pow(-log(epsilon / abs( + center.weight)) / log(center.base), 1.0 / center.exponent); + } + } + + double opCall(double x, double y) + { + double[2] point = [x, y]; + double total = 0.0; + + foreach (uint i, QuevCenter center; m_centers) + { + immutable distanceToCenter = distance!double(point, center.position); + if (distanceToCenter > m_threshholds[i]) + continue; + + total += center.weight * pow(center.base, + -pow(distanceToCenter / center.zoom, center.exponent)); + } + return total; + } } diff --git a/source/heightmap/renderer.d b/source/heightmap/renderer.d index d14b5f1..e8c707f 100644 --- a/source/heightmap/renderer.d +++ b/source/heightmap/renderer.d @@ -8,13 +8,13 @@ import viare.heightmap.heightmap; interface HeightMapRenderer { public: - Image render(HeightMap heightMap); + Image render(HeightMap heightMap); } class WaterTerrainHeightMapRenderer : HeightMapRenderer { public: - /++ + /++ Renders a HeightMap into an Image Params: @@ -23,61 +23,62 @@ public: Returns: The image on which the heightmap was rendered +/ - Image render(HeightMap heightMap) - { - immutable heightMapWidth = heightMap.getWidth(); - immutable heightMapHeight = heightMap.getHeight(); - Image image = new Image(heightMapWidth, heightMapHeight); - - for (uint x; x < heightMapWidth; x++) - { - for (uint y; y < heightMapHeight; y++) - { - immutable cellHeight = heightMap[x, y]; - immutable bool isWater = (cellHeight <= m_waterLevel); - immutable float[3] tint = isWater ? m_waterTint : m_terrainTint; - assert(m_divisions != 0); - immutable heightPerDivision = 1.0f / cast(float) m_divisions; - immutable uint division = cellHeight == 1.0f ? m_divisions - 1 - : cast(uint)(cellHeight / heightPerDivision); - immutable float[3] colorFloat = tint[] * (division * heightPerDivision * 0xFF); - - import std.algorithm; - import std.array; - - Color color; - color.component[0 .. 3] = map!(c => cast(ubyte) c)(colorFloat[]).array; - color.component[3] = 0xFF; - - image[x, y] = color.toInt(); - } - } - - return image; - } - - void setWaterLevel(float waterLevel) - { - m_waterLevel = waterLevel; - } - - void setWaterTint(float[3] waterTint) - { - m_waterTint[] = waterTint[]; - } - - void setTerrainTint(float[3] terrainTint) - { - m_terrainTint[] = terrainTint[]; - } - - void setDivisions(uint divisions) - { - m_divisions = divisions; - } + Image render(HeightMap heightMap) + { + immutable heightMapWidth = heightMap.getWidth(); + immutable heightMapHeight = heightMap.getHeight(); + Image image = new Image(heightMapWidth, heightMapHeight); + + for (uint x; x < heightMapWidth; x++) + { + for (uint y; y < heightMapHeight; y++) + { + immutable cellHeight = heightMap[x, y]; + immutable bool isWater = (cellHeight <= m_waterLevel); + immutable float[3] tint = isWater ? m_waterTint : m_terrainTint; + assert(m_divisions != 0); + immutable heightPerDivision = 1.0f / cast(float) m_divisions; + immutable uint division = cellHeight == 1.0f ? m_divisions - 1 + : cast(uint)(cellHeight / heightPerDivision); + immutable float[3] colorFloat = tint[] * (division * heightPerDivision * 0xFF); + + import std.algorithm; + import std.array; + + Color color; + color.component[0 .. 3] = map!(c => cast(ubyte) c)(colorFloat[]) + .array; + color.component[3] = 0xFF; + + image[x, y] = color.toInt(); + } + } + + return image; + } + + void setWaterLevel(float waterLevel) + { + m_waterLevel = waterLevel; + } + + void setWaterTint(float[3] waterTint) + { + m_waterTint[] = waterTint[]; + } + + void setTerrainTint(float[3] terrainTint) + { + m_terrainTint[] = terrainTint[]; + } + + void setDivisions(uint divisions) + { + m_divisions = divisions; + } private: - float[3] m_waterTint, m_terrainTint; - float m_waterLevel; - uint m_divisions = 0x100; + float[3] m_waterTint, m_terrainTint; + float m_waterLevel; + uint m_divisions = 0x100; } diff --git a/source/tests/heightmaptest.d b/source/tests/heightmaptest.d index 123a38e..a655b20 100644 --- a/source/tests/heightmaptest.d +++ b/source/tests/heightmaptest.d @@ -32,15 +32,15 @@ import viare.heightmap.renderer; void heightMapDebugging() { - immutable noCenters = uniform!"[]"(100, 200); - QuevCenter[] centers = new StdQuevCentersGenerator()(noCenters); - HeightFunction heightFunction = new QuevHeightFunction(centers); + immutable noCenters = uniform!"[]"(100, 200); + QuevCenter[] centers = new StdQuevCentersGenerator()(noCenters); + HeightFunction heightFunction = new QuevHeightFunction(centers); - double first = heightFunction(0, 0); - double second = heightFunction(0.4, 0.4); + double first = heightFunction(0, 0); + double second = heightFunction(0.4, 0.4); - writeln(first); - writeln(second); + writeln(first); + writeln(second); } /* diff --git a/source/tests/perspectivetest.d b/source/tests/perspectivetest.d index c9cb905..f3c10d3 100644 --- a/source/tests/perspectivetest.d +++ b/source/tests/perspectivetest.d @@ -4,7 +4,6 @@ module viare.tests.perspective; import std.stdio; import std.file; import std.ascii; -import std.uni; import std.string; import std.math; import std.random; @@ -33,95 +32,125 @@ import viare.heightmap.renderer; struct Vertex { - float[3] position; - float[4] color; - // dfmt off - static AttributeFormat[] formats = [{ - index: 0, - size : 3, - type : GL_FLOAT, - normalized : GL_FALSE, - stride: Vertex.sizeof, - pointer : cast(void*) Vertex.position.offsetof - }, { - index: 1, - size : 4, - type : GL_FLOAT, - normalized : GL_TRUE, - stride : Vertex.sizeof, - pointer : cast(void*) Vertex.color.offsetof - }]; - // dfmt on + float[3] position; + float[4] color; + static AttributeFormat[] formats = [{ + index: 0, + size: 3, + type: GL_FLOAT, + normalized: GL_FALSE, + stride: Vertex.sizeof, + pointer: cast(void*) Vertex.position.offsetof + }, { + index: 1, + size : 4, + type : GL_FLOAT, + normalized : GL_TRUE, + stride : Vertex.sizeof, + pointer : cast(void*) Vertex.color.offsetof + }]; } void perspectiveTest() { - Window window = new Window("viare perspective test", 800, 600); - - Program perspectiveProgram = new Program(); - Shader vertexShader = new Shader(Shader.Type.Vertex, "shaders/perspective-vertex.glsl"); - Shader fragmentShader = new Shader(Shader.Type.Fragment, "shaders/perspective-fragment.glsl"); - perspectiveProgram.attach(vertexShader); - perspectiveProgram.attach(fragmentShader); - perspectiveProgram.link(); - - int uZn = perspectiveProgram.getUniformLocation("z_near"); - int uZf = perspectiveProgram.getUniformLocation("z_far"); - int alpha = perspectiveProgram.getUniformLocation("alpha"); - int xyRatio = perspectiveProgram.getUniformLocation("xy_ratio"); - - writeln("uZn location = ", uZn); - writeln("zf location = ", uZf); - - perspectiveProgram.setUniform!(1, "f")(uZn, [1.0f]); - perspectiveProgram.setUniform!(1, "f")(uZf, [10.0f]); - perspectiveProgram.setUniform!(1, "f")(alpha, [45.0f]); - perspectiveProgram.setUniform!(1, "f")(xyRatio, [800.0f / 600.0f]); - - float gotZf = 0.0f; - perspectiveProgram.getUniform!"f"(uZf, &gotZf); - - writeln("goZf = ", gotZf); - - // dfmt off - Vertex[] vertices = [{ - position: [0, 0, -1.5], - color : [1, 0, 0, 1] - }, { - position: [1, 0, -1.5], - color : [0, 1, 0, 1] - }, { - position: [0, 1, -1.5], - color : [0, 0, 1, 1] - }]; - // dfmt on - - auto gpuVertices = new GpuArray(vertices, cast(uint) vertices.length, Vertex.formats); - - auto dr = Quaternion!float.getRotation([1, 1, 1], 0.01); - - auto rotation = dr; - - while (window.isOpen()) - { - window.clear(); - - perspectiveProgram.use(); - render(gpuVertices); - - window.print(); - SDL_Event event; - while (SDL_PollEvent(&event)) - { - switch (event.type) - { - case SDL_QUIT: - window.close(); - break; - - default: - break; - } - } - } + // window setup + Window window = new Window("viare perspective test", 800, 600); + + // perspective program setup + Program perspective = new Program(); + Shader vertexShader = new Shader(Shader.Type.Vertex, "shaders/perspective-vertex.glsl"); + Shader fragmentShader = new Shader(Shader.Type.Fragment, "shaders/perspective-fragment.glsl"); + perspective.attach(vertexShader); + perspective.attach(fragmentShader); + perspective.link(); + + immutable uZn = perspective.getUniformLocation("z_near"); + immutable uZf = perspective.getUniformLocation("z_far"); + immutable alpha = perspective.getUniformLocation("alpha"); + immutable xyRatio = perspective.getUniformLocation("xy_ratio"); + immutable rotation = perspective.getUniformLocation("rotation"); + immutable translation = perspective.getUniformLocation("translation"); + + perspective.setUniform!(1, "f")(uZn, [0.1]); + perspective.setUniform!(1, "f")(uZf, [100.0f]); + perspective.setUniform!(1, "f")(alpha, [45.0f]); + perspective.setUniform!(1, "f")(xyRatio, [800.0f / 600.0f]); + perspective.setUniform!(3, "f")(translation, [0.0f, 0.0f, -2.5f]); + + // Vertex specification + Vertex[] vertices = [{ + position: [0, 1, 0], + color : [1, 0, 0, 1] + }, { + position: [1, -1, 0], + color : [0, 1, 0, 1] + }, { + position: [-1, -1, 0], + color : [0, 0, 1, 1] + }]; + foreach(ref v; vertices) + v.position[] = normalize(v.position[]); + + auto gpuVertices = new GpuArray( + vertices, + cast(uint) vertices.length, + Vertex.formats); + + // Translation + float[] translationVector = [0.0f, 0.0f, -2.5f]; + + // Rotation stuff + immutable dr = Quaternion!float.getRotation([1, 0, 0], 0.05); + auto rotationQuaternion = cast(Quaternion!float) dr; + immutable delta = 0.1; + auto scancode = SDL_SCANCODE_W; + pragma(msg, typeof(scancode)); + while (window.isOpen()) + { + // general processing + rotationQuaternion = rotationQuaternion * dr; + + ubyte* key = SDL_GetKeyboardState(null); + if(key[SDL_SCANCODE_W]) + { + translationVector[2] -= delta; + } + if(key[SDL_SCANCODE_S]) + { + translationVector[2] += delta; + } + if(key[SDL_SCANCODE_D]) + { + translationVector[0] += delta; + } + if(key[SDL_SCANCODE_A]) + { + translationVector[0] -= delta; + } + + // pre-rendering operations + perspective.setUniformMatrix(rotation, rotationQuaternion.rotationMatrix()); + perspective.setUniform!(3, "f")(translation, translationVector); + + // rendering + window.clear(); + perspective.use(); + render(gpuVertices); + window.print(); + + // event processing + SDL_Event event; + while (SDL_PollEvent(&event)) + { + switch (event.type) + { + case SDL_QUIT: + window.close(); + break; + + default: + break; + } + } + } } From b7a35e5c26f9976031717e739e09b27211a4f128 Mon Sep 17 00:00:00 2001 From: Miguel Date: Sat, 18 Aug 2018 23:05:47 -0500 Subject: [PATCH 03/32] Use develop branch from libdaque --- dub.json | 2 +- dub.selections.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dub.json b/dub.json index 6375ac8..74a8abf 100644 --- a/dub.json +++ b/dub.json @@ -11,6 +11,6 @@ "dependencies": { "derelict-sdl2": "~>3.0.0-beta", "derelict-gl3": "~>2.0.0-beta", - "libdaque": "0.2.2" + "libdaque": "~develop" } } diff --git a/dub.selections.json b/dub.selections.json index 4cbf6a2..dc6cce7 100644 --- a/dub.selections.json +++ b/dub.selections.json @@ -4,6 +4,6 @@ "derelict-gl3": "2.0.0-beta.6", "derelict-sdl2": "3.0.0-beta.7", "derelict-util": "3.0.0-beta.2", - "libdaque": "0.2.2" + "libdaque": "~develop" } } From 1de64c473f28c471dd7d167d4e2e3a1078b40596 Mon Sep 17 00:00:00 2001 From: Miguel Date: Sat, 18 Aug 2018 23:07:20 -0500 Subject: [PATCH 04/32] Simplify movement code --- source/tests/perspectivetest.d | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/source/tests/perspectivetest.d b/source/tests/perspectivetest.d index f3c10d3..d462542 100644 --- a/source/tests/perspectivetest.d +++ b/source/tests/perspectivetest.d @@ -100,33 +100,29 @@ void perspectiveTest() float[] translationVector = [0.0f, 0.0f, -2.5f]; // Rotation stuff - immutable dr = Quaternion!float.getRotation([1, 0, 0], 0.05); + immutable dr = Quaternion!float.getRotation([1, 3, 7], 0.01); auto rotationQuaternion = cast(Quaternion!float) dr; + immutable delta = 0.1; auto scancode = SDL_SCANCODE_W; - pragma(msg, typeof(scancode)); + float[][SDL_Scancode] movements = + [ + SDL_SCANCODE_W: [0, 0, -delta], + SDL_SCANCODE_S: [0, 0, +delta], + SDL_SCANCODE_D: [+delta, 0, 0], + SDL_SCANCODE_A: [-delta, 0, 0], + SDL_SCANCODE_E: [0, +delta, 0], + SDL_SCANCODE_Q: [0, -delta, 0] + ]; while (window.isOpen()) { // general processing rotationQuaternion = rotationQuaternion * dr; ubyte* key = SDL_GetKeyboardState(null); - if(key[SDL_SCANCODE_W]) - { - translationVector[2] -= delta; - } - if(key[SDL_SCANCODE_S]) - { - translationVector[2] += delta; - } - if(key[SDL_SCANCODE_D]) - { - translationVector[0] += delta; - } - if(key[SDL_SCANCODE_A]) - { - translationVector[0] -= delta; - } + foreach(SDL_Scancode code, float[] movement; movements) + if(key[code]) + translationVector[] += movement[]; // pre-rendering operations perspective.setUniformMatrix(rotation, rotationQuaternion.rotationMatrix()); From 82ba6367c7a2f1c24ac26ae497cfaa0ea638d56a Mon Sep 17 00:00:00 2001 From: Miguel Date: Sat, 18 Aug 2018 23:29:57 -0500 Subject: [PATCH 05/32] Add initial perspective heightmap test setup --- source/app.d | 3 +- source/tests/heightmap-perspective.d | 104 +++++++++++++++++++++++++++ source/tests/perspectivetest.d | 1 + 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 source/tests/heightmap-perspective.d diff --git a/source/app.d b/source/app.d index d107239..1c0cbd1 100644 --- a/source/app.d +++ b/source/app.d @@ -6,10 +6,11 @@ import std.ascii; import viare.tests.perspective; import viare.tests.heightmap; +import viare.tests.heightmapperspective; import daque.math.geometry; void main() { - perspectiveTest(); + heightmapPerspectiveTest(); } diff --git a/source/tests/heightmap-perspective.d b/source/tests/heightmap-perspective.d new file mode 100644 index 0000000..1c07cf6 --- /dev/null +++ b/source/tests/heightmap-perspective.d @@ -0,0 +1,104 @@ +module viare.tests.heightmapperspective; + +import std.stdio; +import std.file; +import std.ascii; +import std.uni; +import std.string; +import std.math; +import std.random; + +import core.thread; + +import derelict.opengl; +import derelict.sdl2.sdl; +import derelict.sdl2.image; + +import daque.math.linear; +import daque.math.geometry; + +import daque.graphics.opengl; +import daque.graphics.sdl; +import daque.graphics.color; +import daque.graphics.image; + +import viare.models; + +import viare.heightmap.quev; +import viare.heightmap.heightmap; +import viare.heightmap.heightfunction; +import viare.heightmap.renderer; + + +void heightmapPerspectiveTest() +{ + Window window = new Window("viare", 800, 800); + + // GLSL textureProgram + Program perspective = new Program([ + new Shader(Shader.Type.Vertex, "shaders/perspective-vertex.glsl"), + new Shader(Shader.Type.Fragment, "shaders/perspective-fragment.glsl")]); + perspective.link(); + + // Uniform setting + immutable uZn = perspective.getUniformLocation("z_near"); + immutable uZf = perspective.getUniformLocation("z_far"); + immutable alpha = perspective.getUniformLocation("alpha"); + immutable xyRatio = perspective.getUniformLocation("xy_ratio"); + immutable rotation = perspective.getUniformLocation("rotation"); + immutable translation = perspective.getUniformLocation("translation"); + + perspective.setUniform!(1, "f")(uZn, [0.1]); + perspective.setUniform!(1, "f")(uZf, [100.0f]); + perspective.setUniform!(1, "f")(alpha, [45.0f]); + perspective.setUniform!(1, "f")(xyRatio, [800.0f / 600.0f]); + perspective.setUniform!(3, "f")(translation, [0.0f, 0.0f, -2.5f]); + + // Height Function + immutable numberOfCenters = uniform!"[]"(300, 400); + QuevCenter[] centers = new StdQuevCentersGenerator()(numberOfCenters); + HeightFunction heightFunction = new QuevHeightFunction(centers); + + // HeightMap Fill + HeightMap heightMap = new HeightMap(100, 100); + writeln("Calculating heights"); + heightMap.fillByHeightFunction(heightFunction); + writeln("Finished calculating heights"); + heightMap.normalize(); + + // Tints + float[3] blueTint = [0.0f, 0.3f, 0.7]; + float[3] greenTint = [0.0f, 0.7f, 0.5f]; + float[3] whiteTint = [1.0f, 1.0f, 1.0f]; + float[3] brownTint = [0.7f, 0.5f, 0.3f]; + + // HeightMap Rendering Configuration + WaterTerrainHeightMapRenderer renderer = new WaterTerrainHeightMapRenderer(); + renderer.setWaterLevel(0.5); + renderer.setWaterTint(blueTint); + renderer.setTerrainTint(brownTint); + renderer.setDivisions(10); + + glEnable(GL_DEPTH_TEST); + // Drawing operations + while (window.isOpen()) + { + window.clear(); + window.print(); + + SDL_Event event; + while (SDL_PollEvent(&event)) + { + switch (event.type) + { + case SDL_QUIT: + window.close(); + break; + default: + break; + } + } + } + + return; +} diff --git a/source/tests/perspectivetest.d b/source/tests/perspectivetest.d index d462542..14f4203 100644 --- a/source/tests/perspectivetest.d +++ b/source/tests/perspectivetest.d @@ -51,6 +51,7 @@ struct Vertex }]; } + void perspectiveTest() { // window setup From 235c4008872cf4991e76f39f3a1682c0c3dccc9e Mon Sep 17 00:00:00 2001 From: Miguel Date: Sat, 18 Aug 2018 23:30:54 -0500 Subject: [PATCH 06/32] Add Vertex module --- source/tests/perspectivetest.d | 21 --------------------- source/vertex.d | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 21 deletions(-) create mode 100644 source/vertex.d diff --git a/source/tests/perspectivetest.d b/source/tests/perspectivetest.d index 14f4203..fad0371 100644 --- a/source/tests/perspectivetest.d +++ b/source/tests/perspectivetest.d @@ -30,27 +30,6 @@ import viare.heightmap.heightmap; import viare.heightmap.heightfunction; import viare.heightmap.renderer; -struct Vertex -{ - float[3] position; - float[4] color; - static AttributeFormat[] formats = [{ - index: 0, - size: 3, - type: GL_FLOAT, - normalized: GL_FALSE, - stride: Vertex.sizeof, - pointer: cast(void*) Vertex.position.offsetof - }, { - index: 1, - size : 4, - type : GL_FLOAT, - normalized : GL_TRUE, - stride : Vertex.sizeof, - pointer : cast(void*) Vertex.color.offsetof - }]; -} - void perspectiveTest() { diff --git a/source/vertex.d b/source/vertex.d new file mode 100644 index 0000000..d274a2b --- /dev/null +++ b/source/vertex.d @@ -0,0 +1,23 @@ +module viare.vertex; + +struct Vertex +{ + float[3] position; + float[4] color; + static AttributeFormat[] formats = [{ + index: 0, + size: 3, + type: GL_FLOAT, + normalized: GL_FALSE, + stride: Vertex.sizeof, + pointer: cast(void*) Vertex.position.offsetof + }, { + index: 1, + size : 4, + type : GL_FLOAT, + normalized : GL_TRUE, + stride : Vertex.sizeof, + pointer : cast(void*) Vertex.color.offsetof + }]; +} + From 9e7fb3d9c1986f35c1ce5e1b8623268039c16f4a Mon Sep 17 00:00:00 2001 From: Miguel Date: Sat, 18 Aug 2018 23:31:34 -0500 Subject: [PATCH 07/32] Add vertex imports --- source/tests/heightmap-perspective.d | 2 ++ source/tests/perspectivetest.d | 1 + 2 files changed, 3 insertions(+) diff --git a/source/tests/heightmap-perspective.d b/source/tests/heightmap-perspective.d index 1c07cf6..88e519d 100644 --- a/source/tests/heightmap-perspective.d +++ b/source/tests/heightmap-perspective.d @@ -29,6 +29,8 @@ import viare.heightmap.heightmap; import viare.heightmap.heightfunction; import viare.heightmap.renderer; +import viare.vertex; + void heightmapPerspectiveTest() { diff --git a/source/tests/perspectivetest.d b/source/tests/perspectivetest.d index fad0371..2433354 100644 --- a/source/tests/perspectivetest.d +++ b/source/tests/perspectivetest.d @@ -29,6 +29,7 @@ import viare.heightmap.quev; import viare.heightmap.heightmap; import viare.heightmap.heightfunction; import viare.heightmap.renderer; +import viare.vertex; void perspectiveTest() From fc4a01d6e22b2d0ddd372f3cc42ee3b38a8cf1b7 Mon Sep 17 00:00:00 2001 From: Miguel Date: Sat, 18 Aug 2018 23:32:46 -0500 Subject: [PATCH 08/32] Fix vertex module imports --- source/vertex.d | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/vertex.d b/source/vertex.d index d274a2b..42847a5 100644 --- a/source/vertex.d +++ b/source/vertex.d @@ -1,5 +1,9 @@ module viare.vertex; +import derelict.opengl; + +import daque.graphics.opengl; + struct Vertex { float[3] position; From 7d907a537f43875017934604c10742ee8e437095 Mon Sep 17 00:00:00 2001 From: Miguel Date: Sun, 19 Aug 2018 02:22:35 -0500 Subject: [PATCH 09/32] Complete test --- + | 133 +++++++++++++++++++++++++++ source/heightmap/quev.d | 4 +- source/heightmap/renderer.d | 49 ++++++++++ source/tests/heightmap-perspective.d | 49 +++++++++- source/vertex.d | 117 +++++++++++++++++++---- 5 files changed, 329 insertions(+), 23 deletions(-) create mode 100644 + diff --git a/+ b/+ new file mode 100644 index 0000000..63d06ec --- /dev/null +++ b/+ @@ -0,0 +1,133 @@ +module viare.heightmap.renderer; + +import daque.graphics.image; +import daque.graphics.color; + +import viare.heightmap.heightmap; + +import viare.vertex; + +interface HeightMapRenderer +{ +public: + Image render(HeightMap heightMap); +} + +class WaterTerrainHeightMapRenderer : HeightMapRenderer +{ +public: + /++ + Renders a HeightMap into an Image + + Params: + heightMap = heightmap to be rendered + + Returns: + The image on which the heightmap was rendered + +/ + Image render(HeightMap heightMap) + { + immutable heightMapWidth = heightMap.getWidth(); + immutable heightMapHeight = heightMap.getHeight(); + Image image = new Image(heightMapWidth, heightMapHeight); + + for (uint x; x < heightMapWidth; x++) + { + for (uint y; y < heightMapHeight; y++) + { + immutable cellHeight = heightMap[x, y]; + immutable bool isWater = (cellHeight <= m_waterLevel); + immutable float[3] tint = isWater ? m_waterTint : m_terrainTint; + assert(m_divisions != 0); + immutable heightPerDivision = 1.0f / cast(float) m_divisions; + immutable uint division = cellHeight == 1.0f ? m_divisions - 1 + : cast(uint)(cellHeight / heightPerDivision); + immutable float[3] colorFloat = tint[] * (division * heightPerDivision * 0xFF); + + import std.algorithm; + import std.array; + + Color color; + color.component[0 .. 3] = map!(c => cast(ubyte) c)(colorFloat[]) + .array; + color.component[3] = 0xFF; + + image[x, y] = color.toInt(); + } + } + + return image; + } + + void setWaterLevel(float waterLevel) + { + m_waterLevel = waterLevel; + } + + void setWaterTint(float[3] waterTint) + { + m_waterTint[] = waterTint[]; + } + + void setTerrainTint(float[3] terrainTint) + { + m_terrainTint[] = terrainTint[]; + } + + void setDivisions(uint divisions) + { + m_divisions = divisions; + } + + Vertex[] getMesh(float height, float[2] size, HeightMap hm) + { + immutable hmWidth = hm.getWidth(); + immutable hmHeight = hm.getHeight(); + float[2] getBase(uint i, uint j) + { + float[2] base; + base[0] = (i + 1.0f) / (hmWidth + 1.0f) * size[0]; + base[1] = (j + 1.0f) / (hmHeight + 1.0f) * size[1]; + return base; + } + Vertex getVertex(uint i, uint j) + { + auto base = getBase(i, j); + float normalHeight = hm[i, j]; + float height = normalHeight * height; + bool isWater = (normalHeight <= m_waterLevel); + auto tint = isWater? m_waterTint: m_terrainTint; + + Vertex v; + v.position[] = [base[0], height, base[1]]; + v.color[0 .. 3] = normalHeight * tint[]; + v.color[3] = 1.0f; + return v; + } + + Vertex[] mesh; + for(uint i; i + 1 < hmWidth; i++) + { + for(uint j; j + 1 < hmHeight; j++) + { + Vertex[2][2] v; + for(uint di; di < 2; di++) + for(uint dj; dj < 2; dj++) + v[di][dj] = getVertex(i + di, j + dj); + mesh ~= v[0][0]; + mesh ~= v[1][0]; + mesh ~= v[0][1]; + + mesh ~= v[1][0]; + mesh ~= v[1][1]; + mesh ~= v[0][1]; + } + } + return mesh; + } + +private: + float[3] m_waterTint, m_terrainTint; + float m_waterLevel; + uint m_divisions = 0x100; +} diff --git a/source/heightmap/quev.d b/source/heightmap/quev.d index 6d7a631..a9bd316 100644 --- a/source/heightmap/quev.d +++ b/source/heightmap/quev.d @@ -45,8 +45,8 @@ public: return position; }; defaultParams.weightGenerator = { return uniform!"[]"(-1.0, 1.0); }; - defaultParams.baseGenerator = { return uniform!"[]"(20.1, 40.2); }; - defaultParams.exponentGenerator = { return uniform!"[]"(1.2, 1.5); }; + defaultParams.baseGenerator = { return uniform!"[]"(1000.1, 1000.2); }; + defaultParams.exponentGenerator = { return uniform!"[]"(1.2, 5.6); }; defaultParams.zoomGenerator = { return uniform!"[]"(0.125, 0.175); }; } diff --git a/source/heightmap/renderer.d b/source/heightmap/renderer.d index e8c707f..510119c 100644 --- a/source/heightmap/renderer.d +++ b/source/heightmap/renderer.d @@ -5,6 +5,8 @@ import daque.graphics.color; import viare.heightmap.heightmap; +import viare.vertex; + interface HeightMapRenderer { public: @@ -77,6 +79,53 @@ public: m_divisions = divisions; } + Vertex[] getMesh(float height, float[2] size, HeightMap hm) + { + immutable hmWidth = hm.getWidth(); + immutable hmHeight = hm.getHeight(); + float[2] getBase(uint i, uint j) + { + float[2] base; + base[0] = (i + 1.0f) / (hmWidth + 1.0f) * size[0] - size[0] * 0.5f; + base[1] = (j + 1.0f) / (hmHeight + 1.0f) * size[1] - size[1] * 0.5f; + return base; + } + Vertex getVertex(uint i, uint j) + { + auto base = getBase(i, j); + float normalHeight = hm[i, j]; + float height = normalHeight * height; + bool isWater = (normalHeight <= m_waterLevel); + auto tint = isWater? m_waterTint: m_terrainTint; + + Vertex v; + v.position[] = [base[0], height, base[1]]; + v.color[0 .. 3] = normalHeight * tint[]; + v.color[3] = 1.0f; + return v; + } + + Vertex[] mesh; + for(uint i; i + 1 < hmWidth; i++) + { + for(uint j; j + 1 < hmHeight; j++) + { + Vertex[2][2] v; + for(uint di; di < 2; di++) + for(uint dj; dj < 2; dj++) + v[di][dj] = getVertex(i + di, j + dj); + mesh ~= v[0][0]; + mesh ~= v[1][0]; + mesh ~= v[0][1]; + + mesh ~= v[1][0]; + mesh ~= v[1][1]; + mesh ~= v[0][1]; + } + } + return mesh; + } + private: float[3] m_waterTint, m_terrainTint; float m_waterLevel; diff --git a/source/tests/heightmap-perspective.d b/source/tests/heightmap-perspective.d index 88e519d..bbef838 100644 --- a/source/tests/heightmap-perspective.d +++ b/source/tests/heightmap-perspective.d @@ -16,6 +16,7 @@ import derelict.sdl2.image; import daque.math.linear; import daque.math.geometry; +import daque.math.quaternion; import daque.graphics.opengl; import daque.graphics.sdl; @@ -50,7 +51,7 @@ void heightmapPerspectiveTest() immutable rotation = perspective.getUniformLocation("rotation"); immutable translation = perspective.getUniformLocation("translation"); - perspective.setUniform!(1, "f")(uZn, [0.1]); + perspective.setUniform!(1, "f")(uZn, [1.0f]); perspective.setUniform!(1, "f")(uZf, [100.0f]); perspective.setUniform!(1, "f")(alpha, [45.0f]); perspective.setUniform!(1, "f")(xyRatio, [800.0f / 600.0f]); @@ -81,13 +82,57 @@ void heightmapPerspectiveTest() renderer.setTerrainTint(brownTint); renderer.setDivisions(10); + Vertex[] hmMesh = renderer.getMesh(5.0f, [20.0f, 20.0f], heightMap); + auto gpuVertices = new GpuArray( + hmMesh, + cast(uint) hmMesh.length, + Vertex.formats); + glEnable(GL_DEPTH_TEST); - // Drawing operations + glDepthMask(GL_TRUE); + glDepthFunc(GL_GREATER); + glClearDepth(0.0); + + // Translation + float[] translationVector = [0.0f, 0.0f, -2.5f]; + + // Rotation stuff + immutable dr = Quaternion!float.getRotation([0, 1, 0], 0.01); + auto rotationQuaternion = cast(Quaternion!float) dr; + + immutable delta = 0.1; + auto scancode = SDL_SCANCODE_W; + float[][SDL_Scancode] movements = + [ + SDL_SCANCODE_W: [0, 0, -delta], + SDL_SCANCODE_S: [0, 0, +delta], + SDL_SCANCODE_D: [+delta, 0, 0], + SDL_SCANCODE_A: [-delta, 0, 0], + SDL_SCANCODE_E: [0, +delta, 0], + SDL_SCANCODE_Q: [0, -delta, 0] + ]; + while (window.isOpen()) { + // model movement + ubyte* key = SDL_GetKeyboardState(null); + foreach(SDL_Scancode code, float[] movement; movements) + if(key[code]) + translationVector[] += movement[]; + + rotationQuaternion = rotationQuaternion * dr; + + // uniform setting + perspective.setUniformMatrix(rotation, rotationQuaternion.rotationMatrix()); + perspective.setUniform!(3, "f")(translation, translationVector); + + // render window.clear(); + perspective.use(); + render(gpuVertices); window.print(); + // event handling SDL_Event event; while (SDL_PollEvent(&event)) { diff --git a/source/vertex.d b/source/vertex.d index 42847a5..e14943f 100644 --- a/source/vertex.d +++ b/source/vertex.d @@ -1,27 +1,106 @@ module viare.vertex; +import std.conv; +import std.string; + import derelict.opengl; import daque.graphics.opengl; -struct Vertex -{ - float[3] position; - float[4] color; - static AttributeFormat[] formats = [{ - index: 0, - size: 3, - type: GL_FLOAT, - normalized: GL_FALSE, - stride: Vertex.sizeof, - pointer: cast(void*) Vertex.position.offsetof - }, { - index: 1, - size : 4, - type : GL_FLOAT, - normalized : GL_TRUE, - stride : Vertex.sizeof, - pointer : cast(void*) Vertex.color.offsetof - }]; +alias Vertex = Vert!"3f.0:position 4fn1:color"; + +// 3f.0:position 4fn1:color +struct MemberInfo +{ + string type; + string identifier; + + string index; + string size; + string glType; + string normalized; +} + +MemberInfo getInfo(string memberString) pure nothrow +{ + string[] parts = split(memberString, ":"); + string first = parts[0]; + string second = parts[1]; + + string type = (first[1] == 'f')? "float" : "float"; + string size = first[0 .. 1]; + + MemberInfo info; + info.type = type ~ "[" ~ size ~ "]"; + info.identifier = second; + info.index = memberString[3 .. 4]; + info.size = size; + info.glType = (type == "float")? "GL_FLOAT" : "GL_FLOAT"; + info.normalized = (memberString[2] == 'n')? "GL_TRUE" : "GL_FALSE"; + return info; +} +MemberInfo[] getInfos(string membersString) pure nothrow +{ + string[] memberString = split(membersString, " "); + MemberInfo[] infos; + foreach(str; memberString) + { + infos ~= getInfo(str); + } + return infos; +} + +string attrFormatString(MemberInfo info) +{ + return "{ index: " ~ info.index ~ + ", size: " ~ info.size ~ + ", type: " ~ info.glType ~ + ", normalized: " ~ info.normalized ~ + ", stride: this.sizeof" ~ + ", pointer: cast(void*) this." ~ info.identifier ~ ".offsetof}"; +} + +string attrFormatStrings(MemberInfo[] infos) +{ + string str = "["; + foreach(uint i, MemberInfo info; infos) + { + str ~= attrFormatString(info); + if(i + 1 < infos.length) + str ~= ", "; + } + str ~= "]"; + return str; +} + +string declaration(MemberInfo info) +{ + return info.type ~ " " ~ info.identifier ~ ";"; +} + +string formStruct(string membersString) +{ + string structString; + auto infos = getInfos(membersString); + foreach(info; infos) + structString ~= declaration(info); + structString ~= "static AttributeFormat[] formats = " ~ attrFormatStrings(infos) ~ ";"; + return structString; +} + +template Vert(string membersString) +{ + struct Vert + { + mixin(formStruct(membersString)); + } +} + +unittest +{ + import std.stdio: writeln; + Vert!"2fn0:position 4fn1:color" vert; + vert.position[] = [3, 4]; + writeln(vert); } From 36e47004629bbe8900da9570c0271c5a18badc57 Mon Sep 17 00:00:00 2001 From: Miguel Date: Sun, 19 Aug 2018 02:32:40 -0500 Subject: [PATCH 10/32] Add divisions support to heightmap renderer mesh method --- source/heightmap/renderer.d | 12 +++++++++--- source/tests/heightmap-perspective.d | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/source/heightmap/renderer.d b/source/heightmap/renderer.d index 510119c..4e6a20e 100644 --- a/source/heightmap/renderer.d +++ b/source/heightmap/renderer.d @@ -94,13 +94,19 @@ public: { auto base = getBase(i, j); float normalHeight = hm[i, j]; - float height = normalHeight * height; + float pointHeight = normalHeight * height; bool isWater = (normalHeight <= m_waterLevel); auto tint = isWater? m_waterTint: m_terrainTint; + immutable heightPerDivision = 1.0f / cast(float) m_divisions; + immutable uint division = normalHeight == 1.0f ? m_divisions - 1 + : cast(uint)(normalHeight / heightPerDivision); + + pointHeight = heightPerDivision * division * height; + Vertex v; - v.position[] = [base[0], height, base[1]]; - v.color[0 .. 3] = normalHeight * tint[]; + v.position[] = [base[0], pointHeight, base[1]]; + v.color[0 .. 3] = heightPerDivision * division * tint[]; v.color[3] = 1.0f; return v; } diff --git a/source/tests/heightmap-perspective.d b/source/tests/heightmap-perspective.d index bbef838..275060e 100644 --- a/source/tests/heightmap-perspective.d +++ b/source/tests/heightmap-perspective.d @@ -63,7 +63,7 @@ void heightmapPerspectiveTest() HeightFunction heightFunction = new QuevHeightFunction(centers); // HeightMap Fill - HeightMap heightMap = new HeightMap(100, 100); + HeightMap heightMap = new HeightMap(70, 70); writeln("Calculating heights"); heightMap.fillByHeightFunction(heightFunction); writeln("Finished calculating heights"); @@ -80,7 +80,7 @@ void heightmapPerspectiveTest() renderer.setWaterLevel(0.5); renderer.setWaterTint(blueTint); renderer.setTerrainTint(brownTint); - renderer.setDivisions(10); + renderer.setDivisions(20); Vertex[] hmMesh = renderer.getMesh(5.0f, [20.0f, 20.0f], heightMap); auto gpuVertices = new GpuArray( From e7c5063b05547e40d8f71214fc62d62f14803fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Omar=20Flores=20Ch=C3=A1vez?= Date: Sun, 19 Aug 2018 18:33:41 -0500 Subject: [PATCH 11/32] Add a writeln() that apparently fixes #3 --- source/heightmap/heightmap.d | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/source/heightmap/heightmap.d b/source/heightmap/heightmap.d index 29f79a4..cbfff02 100644 --- a/source/heightmap/heightmap.d +++ b/source/heightmap/heightmap.d @@ -40,8 +40,14 @@ public: void fillByHeightFunction(HeightFunction heightFunction) { for (uint i; i < m_xlength; i++) + { for (uint j; j < m_ylength; j++) - this[i, j] = heightFunction(cast(float) i / m_xlength, cast(float) j / m_ylength); + { + import std.stdio; + writeln(cast(double)i / m_xlength); /// Don't know why. But fixes problem + this[i, j] = heightFunction(cast(double) i / m_xlength, cast(double) j / m_ylength); + } + } } void normalize() From b1ad7d27c69e4e7ade7e406d9933b0c906422bda Mon Sep 17 00:00:00 2001 From: Miguel Date: Sun, 19 Aug 2018 20:10:41 -0500 Subject: [PATCH 12/32] Only do dirty fix if on Windows --- source/heightmap/heightmap.d | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/heightmap/heightmap.d b/source/heightmap/heightmap.d index cbfff02..72bf703 100644 --- a/source/heightmap/heightmap.d +++ b/source/heightmap/heightmap.d @@ -43,8 +43,11 @@ public: { for (uint j; j < m_ylength; j++) { - import std.stdio; - writeln(cast(double)i / m_xlength); /// Don't know why. But fixes problem + version(Windows) + { + import std.stdio; + writeln(cast(double)i / m_xlength); /// Don't know why. But fixes problem + } this[i, j] = heightFunction(cast(double) i / m_xlength, cast(double) j / m_ylength); } } From 0ded8b95ebdb692a20fd192587c136ebc32b4810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Omar=20Flores=20Ch=C3=A1vez?= Date: Tue, 11 Sep 2018 14:25:19 -0500 Subject: [PATCH 13/32] Update README to add contributing, code of conduct, and references list --- README.md | 47 ++++++++++++++--------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 525de27..e8fa342 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # ViaRE -[![Travis](https://img.shields.io/travis/viare/viare.svg?style=flat-square)](https://travis-ci.org/viare/viare) -[![Codecov](https://img.shields.io/codecov/c/github/viare/viare.svg?style=flat-square)](https://codecov.io/gh/viare/viare) +[![Travis](https://img.shields.io/travis/daque-dev/viare.svg?style=flat-square)](https://travis-ci.org/daque-dev/viare) +[![Codecov](https://img.shields.io/codecov/c/github/daque-dev/viare.svg?style=flat-square)](https://codecov.io/gh/daque-dev/viare) @@ -53,11 +53,14 @@ $ dub --version --- -ViaRE is built using [SDL2](https://www.libsdl.org/download-2.0.php) and Open GL. +ViaRE is built using [SDL2](https://www.libsdl.org/download-2.0.php), +[SDL2_image](https://www.libsdl.org/projects/SDL_image/)and Open GL. Doing a proper SDL2 installation for development on Windows can be tricky. [This video](https://www.youtube.com/watch?v=ybYMOKEW9IY) could be useful. +To install SDL2_image, follow those same instructions. + To install SDL2 on Linux, follow official [SDL instructions](https://wiki.libsdl.org/Installation). We recommend to follow "The Unix Way", as it will avoid missing .so files. @@ -94,44 +97,22 @@ This will run every `unittest` inside sourcecode. - [**quevangel**](https://github.com/quevangel) - *Initial work* - [**davidomarf**](https://github.com/davidomarf) - *Initial work* -See also the list of [contributors](https://github.com/your/project/contributors) who participated in this project. +See also the list of [contributors](https://github.com/daque-dev/viare/graphs/contributors) who participated in this project. ## License This project is licensed under the MIT License - see [LICENSE.md](LICENSE.md) file for details -## Acknowledgments - -* **Martin O'Leary**, [@mewo2](https://twitter.com/mewo2), for writing an extensive guide -on [generating fantasy maps](http://mewo2.com/notes/terrain/) and [naming languages](http://mewo2.com/notes/naming-language/) -* **Amit Patel**, [@redblobgames](https://twitter.com/redblobgames), for his writing about -[polygonal map generation](http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/) - - +As this list is growing bigger and bigger, there's now a separate file [REFERENCES.md](https://github.com/daque-dev/viare/blob/master/REFERENCES.md). +In it, we list all the resources we use to design and build ViaRE. \ No newline at end of file From 10b6db30a44270c2cee28bd6ab6ae9896f7f508b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Omar=20Flores=20Ch=C3=A1vez?= Date: Tue, 11 Sep 2018 14:31:15 -0500 Subject: [PATCH 14/32] Create CODE_OF_CONDUCT.md --- CODE_OF_CONDUCT.md | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 CODE_OF_CONDUCT.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..95fcba3 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,73 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at [contact@daque.me](mailto:contact@daque.me?Subject=Code%20of%20Conduct%20Report). +All complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org From 7456b2fb8ce8322416692e84aef81fde82ffc85c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Omar=20Flores=20Ch=C3=A1vez?= Date: Tue, 11 Sep 2018 15:43:10 -0500 Subject: [PATCH 15/32] Create first rules on CONTRIBUTING.md --- CONTRIBUTING.md | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..2313e3a --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,100 @@ +# Contributing to ViaRE + +Thanks for reading this! That'd mean, hopefully, that you want to contribute +with us. + +We try to make it possible that, by reading some of our code, you'll recognize +our conventions and style. + +But if you're unsure about it, or you just want to know how we get things done, +you should read this. + +## Contents + +- [**Git Flow**](#git-flow) + - [Commiting](#commiting) + - [Branching](#branching) +- [**Code Style**](#code-style) + +## Git Flow + +We use git —surprise!— to control versions. In this section, you can get to +know our workflow in this, and all of our projects. + +### Commiting + +Commited changes should be small, avoiding big chunks of code being created, +modified, or removed. + +Our commiting system is based on modularity. Each one should be able to be +described in one sentence. If you need more than one, maybe you should make +multiple commits. + +Yes, this can cause non—meaningful commits, but it makes easy to track down +bugs and errors. + +If the change of the commit is style related, it doesn't matter the size of the +modified code, as long as it doesn't change functionality. + +### Branching + +We try to follow the branching system published by [Vincent Driessen at nvie](https://nvie.com/posts/a-successful-git-branching-model/). + +`master` only has released versions. + +`develop` is where all approved changes (that are not big enough to make it to +a new version yet) go. + +From develop, we have multiple branches. Branches with meaningful names related +to what is being developed inside each branch. + +Once a new function or a bug-fix is implemented, we [create a Pull Request](#pull-requests) +to merge changes back into `develop`. + +And once we feel that there are enough changes to make a new version of the +project, we [create a Pull Request](#pull-requests) to merge changes into +`master`. + +Each merge into `master` is tagged, meaning there's a new release. +See [Versioning](#versioning). + +## Code Style + +We try to be consistent with our style. When you doubt whether you should write +`blah blah` or `yada yada`, follow the most important rule: +**optimize for readabaility**. + +That said, these are our suggested rules + +- Indent using 4 spaces +- Use spaces after commas (unless separated by newlines): `[1, 2, 3]`, `(a, b, c)`. +- Use spaces after flow control statements: `if ()`, `for ()`, `while ()` +- Use spaces around operators, except unaries: `x + y`, `x == y`, `x++`, `!x`. +- Try to keep the line length at ~85. If exceeded, separate it in different lines. +- `variable_names`, `CONSTANT_NAMES`, `Function_Names`, `StructureNames` +- Use new line before `{` in blocks of code: + ``` + /// Do this + if (condition) + { + + } + + /// Instead of this + if (condition){ + + } + ``` +- Always use curly braces after flow control statements. Even if only it's followed +by only one line: + ``` + /// Do this + if (condition) + { + doSomethingInOneLine() + } + + /// Instead of this + if (condition) + doSomethingInOneLine() + ``` From 66fedbdd741880cebed44342944d2cc0846042b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Omar=20Flores=20Ch=C3=A1vez?= Date: Tue, 11 Sep 2018 16:15:18 -0500 Subject: [PATCH 16/32] Extend CONTRIBUTING rules --- CONTRIBUTING.md | 74 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2313e3a..8345f18 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,6 +15,13 @@ you should read this. - [Commiting](#commiting) - [Branching](#branching) - [**Code Style**](#code-style) +- [**Versioning**](#versioning) +- [**GitHub Related**](#github-related) + - [Issues](#issues) + - [Bugs](#bugs) + - [Enhancements](#enhancements) + - [Pull Requests](#pull-requests) +- [**Thanks!**](#thanks!) ## Git Flow @@ -72,7 +79,7 @@ That said, these are our suggested rules - Use spaces around operators, except unaries: `x + y`, `x == y`, `x++`, `!x`. - Try to keep the line length at ~85. If exceeded, separate it in different lines. - `variable_names`, `CONSTANT_NAMES`, `Function_Names`, `StructureNames` -- Use new line before `{` in blocks of code: +- Insert new line before curly braces in blocks of code: ``` /// Do this if (condition) @@ -85,7 +92,7 @@ That said, these are our suggested rules } ``` -- Always use curly braces after flow control statements. Even if only it's followed +- Always use curly braces after flow control statements. Even if it's followed by only one line: ``` /// Do this @@ -98,3 +105,66 @@ by only one line: if (condition) doSomethingInOneLine() ``` +- + +## Versioning + +We follow [SemVer](https://semver.org/). + +Yup, just read it. Nothing to add. + +## GitHub Related + +### Issues + +If you have a question, don't open an issue. You can read the +[FAQ](https://github.com/daque-dev/viare/blob/master/FAQ.md), or send us an e-mail +at [contact@daque.me](mailto:contact@daque.me?Subject=Question) + +Issues are intended for reporting bugs, or discussing new features. + +Fortunately, GitHub allows us to provide an issue template. When you try to file +a new issue, you'll see it. Try to fill it with all the info you can. + +Not all fields are required for every new issue. It depends on whether it is a bug +report, or an enhancement discussion. + +#### Bugs + +The most important thing, is providing the necessary information to allow us to +reproduce the problem. **Try to be as descriptive as possible.** + +Again, the best way to learn how to file an issue, is by taking a look at our +[issue template](https://github.com/daque-dev/viare/issues/new). + +#### Enhancements + +This includes style changes, new features implementation, and general discussion +on how to make ViaRE better. + +We are more permissive on the structure of these issues. Anyways, you should still +try to be as descriptive as possible. + +### Pull Requests + +Firs, you should read [Git Flow](#git-flow) and [Code Style](#code-style) sections. + +Once you have some changes that you'd like to see merged into our codebase, [open a +Pull Request](https://github.com/daque-dev/viare/pull/new/master). We also have +a PR template, that you'll see once you try to open one. + +Again, the most important thing is that you describe what changes you've made, and +why you made them. + +--- + +## Thanks! + +All that said, we will be very thankful and happy if you decide to contribute with +the project. + +Don't be afraid to contribute if you feel you can't fulfil all of the rules in here. + +We will help you to help us. + +Cheers! \ No newline at end of file From c0ff723caca71668a7fbba9c3f3553f6410f5dbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Omar=20Flores=20Ch=C3=A1vez?= Date: Tue, 11 Sep 2018 16:59:33 -0500 Subject: [PATCH 17/32] Fix style issues --- CONTRIBUTING.md | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8345f18..0c95c80 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,7 +21,7 @@ you should read this. - [Bugs](#bugs) - [Enhancements](#enhancements) - [Pull Requests](#pull-requests) -- [**Thanks!**](#thanks!) +- [**Thanks!**](#thanks) ## Git Flow @@ -80,32 +80,35 @@ That said, these are our suggested rules - Try to keep the line length at ~85. If exceeded, separate it in different lines. - `variable_names`, `CONSTANT_NAMES`, `Function_Names`, `StructureNames` - Insert new line before curly braces in blocks of code: - ``` - /// Do this - if (condition) - { - } +```js - /// Instead of this - if (condition){ +// Do this +if (condition) +{ + +} + +// Instead of this +if (condition){ + +} +``` - } - ``` - Always use curly braces after flow control statements. Even if it's followed by only one line: - ``` - /// Do this + + ```js + // Do this if (condition) { doSomethingInOneLine() } - /// Instead of this + // Instead of this if (condition) doSomethingInOneLine() ``` -- ## Versioning From 089a159077ce368a0c190d7c27f67b9297273208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Omar=20Flores=20Ch=C3=A1vez?= Date: Tue, 11 Sep 2018 17:22:40 -0500 Subject: [PATCH 18/32] Sectionize Issue template into Bug report/Enhancement idea --- .github/ISSUE_TEMPLATE.md | 69 +++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index b1be05d..20974a7 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,33 +1,62 @@ - + + + + + + + + ## Expected Behavior - - + ## Current Behavior - - - -## Possible Solution - - + -## Steps to Reproduce (for bugs) +## Steps to Reproduce 1. 2. -3. -4. ## Context - - + + + ## Your Environment - -* Version used: -* Environment name and version (e.g. PHP 5.4 on nginx 1.9.1): -* Server type and version: -* Operating System and version: -* Link to your project: + + +* ViaRE (release or commit): +* DMD: +* SDL2: +* SDL2_image: +* OpenGL: +* OS: + +## Possible Solution + + + + + + + + + + +## Suggested change + + + + +## Context + + + + +## Possible Implementation Design + + + + From 580547a4db92ccf36f384e09eb2adfec621d89ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Omar=20Flores=20Ch=C3=A1vez?= Date: Tue, 11 Sep 2018 17:26:21 -0500 Subject: [PATCH 19/32] Update Pull Request to accept non-issue-started PRs --- .github/PULL_REQUEST_TEMPLATE.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index fab5004..174d759 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -3,14 +3,10 @@ ## Description -## Related Issue - - - - - ## Motivation and Context + + ## How Has This Been Tested? From 7b962e20307eac5a75a5c9ec3053ee6ef3edeca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Omar=20Flores=20Ch=C3=A1vez?= Date: Tue, 11 Sep 2018 17:27:42 -0500 Subject: [PATCH 20/32] Move meta docs into .github/ to clean root directory --- .github/CODE_OF_CONDUCT.md | 73 ++++++++++++++++ .github/CONTRIBUTING.md | 173 +++++++++++++++++++++++++++++++++++++ 2 files changed, 246 insertions(+) create mode 100644 .github/CODE_OF_CONDUCT.md create mode 100644 .github/CONTRIBUTING.md diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..95fcba3 --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,73 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at [contact@daque.me](mailto:contact@daque.me?Subject=Code%20of%20Conduct%20Report). +All complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..0c95c80 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,173 @@ +# Contributing to ViaRE + +Thanks for reading this! That'd mean, hopefully, that you want to contribute +with us. + +We try to make it possible that, by reading some of our code, you'll recognize +our conventions and style. + +But if you're unsure about it, or you just want to know how we get things done, +you should read this. + +## Contents + +- [**Git Flow**](#git-flow) + - [Commiting](#commiting) + - [Branching](#branching) +- [**Code Style**](#code-style) +- [**Versioning**](#versioning) +- [**GitHub Related**](#github-related) + - [Issues](#issues) + - [Bugs](#bugs) + - [Enhancements](#enhancements) + - [Pull Requests](#pull-requests) +- [**Thanks!**](#thanks) + +## Git Flow + +We use git —surprise!— to control versions. In this section, you can get to +know our workflow in this, and all of our projects. + +### Commiting + +Commited changes should be small, avoiding big chunks of code being created, +modified, or removed. + +Our commiting system is based on modularity. Each one should be able to be +described in one sentence. If you need more than one, maybe you should make +multiple commits. + +Yes, this can cause non—meaningful commits, but it makes easy to track down +bugs and errors. + +If the change of the commit is style related, it doesn't matter the size of the +modified code, as long as it doesn't change functionality. + +### Branching + +We try to follow the branching system published by [Vincent Driessen at nvie](https://nvie.com/posts/a-successful-git-branching-model/). + +`master` only has released versions. + +`develop` is where all approved changes (that are not big enough to make it to +a new version yet) go. + +From develop, we have multiple branches. Branches with meaningful names related +to what is being developed inside each branch. + +Once a new function or a bug-fix is implemented, we [create a Pull Request](#pull-requests) +to merge changes back into `develop`. + +And once we feel that there are enough changes to make a new version of the +project, we [create a Pull Request](#pull-requests) to merge changes into +`master`. + +Each merge into `master` is tagged, meaning there's a new release. +See [Versioning](#versioning). + +## Code Style + +We try to be consistent with our style. When you doubt whether you should write +`blah blah` or `yada yada`, follow the most important rule: +**optimize for readabaility**. + +That said, these are our suggested rules + +- Indent using 4 spaces +- Use spaces after commas (unless separated by newlines): `[1, 2, 3]`, `(a, b, c)`. +- Use spaces after flow control statements: `if ()`, `for ()`, `while ()` +- Use spaces around operators, except unaries: `x + y`, `x == y`, `x++`, `!x`. +- Try to keep the line length at ~85. If exceeded, separate it in different lines. +- `variable_names`, `CONSTANT_NAMES`, `Function_Names`, `StructureNames` +- Insert new line before curly braces in blocks of code: + +```js + +// Do this +if (condition) +{ + +} + +// Instead of this +if (condition){ + +} +``` + +- Always use curly braces after flow control statements. Even if it's followed +by only one line: + + ```js + // Do this + if (condition) + { + doSomethingInOneLine() + } + + // Instead of this + if (condition) + doSomethingInOneLine() + ``` + +## Versioning + +We follow [SemVer](https://semver.org/). + +Yup, just read it. Nothing to add. + +## GitHub Related + +### Issues + +If you have a question, don't open an issue. You can read the +[FAQ](https://github.com/daque-dev/viare/blob/master/FAQ.md), or send us an e-mail +at [contact@daque.me](mailto:contact@daque.me?Subject=Question) + +Issues are intended for reporting bugs, or discussing new features. + +Fortunately, GitHub allows us to provide an issue template. When you try to file +a new issue, you'll see it. Try to fill it with all the info you can. + +Not all fields are required for every new issue. It depends on whether it is a bug +report, or an enhancement discussion. + +#### Bugs + +The most important thing, is providing the necessary information to allow us to +reproduce the problem. **Try to be as descriptive as possible.** + +Again, the best way to learn how to file an issue, is by taking a look at our +[issue template](https://github.com/daque-dev/viare/issues/new). + +#### Enhancements + +This includes style changes, new features implementation, and general discussion +on how to make ViaRE better. + +We are more permissive on the structure of these issues. Anyways, you should still +try to be as descriptive as possible. + +### Pull Requests + +Firs, you should read [Git Flow](#git-flow) and [Code Style](#code-style) sections. + +Once you have some changes that you'd like to see merged into our codebase, [open a +Pull Request](https://github.com/daque-dev/viare/pull/new/master). We also have +a PR template, that you'll see once you try to open one. + +Again, the most important thing is that you describe what changes you've made, and +why you made them. + +--- + +## Thanks! + +All that said, we will be very thankful and happy if you decide to contribute with +the project. + +Don't be afraid to contribute if you feel you can't fulfil all of the rules in here. + +We will help you to help us. + +Cheers! \ No newline at end of file From 49203175bc1043239b204de249b9ff6429f4a47d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Omar=20Flores=20Ch=C3=A1vez?= Date: Tue, 11 Sep 2018 17:28:32 -0500 Subject: [PATCH 21/32] Move meta docs into .github/ to clean root directory --- CODE_OF_CONDUCT.md | 73 ------------------- CONTRIBUTING.md | 173 --------------------------------------------- 2 files changed, 246 deletions(-) delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index 95fcba3..0000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,73 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and -our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, sex characteristics, gender identity and expression, -level of experience, education, socio-economic status, nationality, personal -appearance, race, religion, or sexual identity and orientation. - -## Our Standards - -Examples of behavior that contributes to creating a positive environment -include: - -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members - -Examples of unacceptable behavior by participants include: - -* The use of sexualized language or imagery and unwelcome sexual attention or - advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic - address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Our Responsibilities - -Project maintainers are responsible for clarifying the standards of acceptable -behavior and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behavior. - -Project maintainers have the right and responsibility to remove, edit, or -reject comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. - -## Scope - -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at [contact@daque.me](mailto:contact@daque.me?Subject=Code%20of%20Conduct%20Report). -All complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain confidentiality with regard to the reporter of an incident. -Further details of specific enforcement policies may be posted separately. - -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html - -[homepage]: https://www.contributor-covenant.org diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 0c95c80..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,173 +0,0 @@ -# Contributing to ViaRE - -Thanks for reading this! That'd mean, hopefully, that you want to contribute -with us. - -We try to make it possible that, by reading some of our code, you'll recognize -our conventions and style. - -But if you're unsure about it, or you just want to know how we get things done, -you should read this. - -## Contents - -- [**Git Flow**](#git-flow) - - [Commiting](#commiting) - - [Branching](#branching) -- [**Code Style**](#code-style) -- [**Versioning**](#versioning) -- [**GitHub Related**](#github-related) - - [Issues](#issues) - - [Bugs](#bugs) - - [Enhancements](#enhancements) - - [Pull Requests](#pull-requests) -- [**Thanks!**](#thanks) - -## Git Flow - -We use git —surprise!— to control versions. In this section, you can get to -know our workflow in this, and all of our projects. - -### Commiting - -Commited changes should be small, avoiding big chunks of code being created, -modified, or removed. - -Our commiting system is based on modularity. Each one should be able to be -described in one sentence. If you need more than one, maybe you should make -multiple commits. - -Yes, this can cause non—meaningful commits, but it makes easy to track down -bugs and errors. - -If the change of the commit is style related, it doesn't matter the size of the -modified code, as long as it doesn't change functionality. - -### Branching - -We try to follow the branching system published by [Vincent Driessen at nvie](https://nvie.com/posts/a-successful-git-branching-model/). - -`master` only has released versions. - -`develop` is where all approved changes (that are not big enough to make it to -a new version yet) go. - -From develop, we have multiple branches. Branches with meaningful names related -to what is being developed inside each branch. - -Once a new function or a bug-fix is implemented, we [create a Pull Request](#pull-requests) -to merge changes back into `develop`. - -And once we feel that there are enough changes to make a new version of the -project, we [create a Pull Request](#pull-requests) to merge changes into -`master`. - -Each merge into `master` is tagged, meaning there's a new release. -See [Versioning](#versioning). - -## Code Style - -We try to be consistent with our style. When you doubt whether you should write -`blah blah` or `yada yada`, follow the most important rule: -**optimize for readabaility**. - -That said, these are our suggested rules - -- Indent using 4 spaces -- Use spaces after commas (unless separated by newlines): `[1, 2, 3]`, `(a, b, c)`. -- Use spaces after flow control statements: `if ()`, `for ()`, `while ()` -- Use spaces around operators, except unaries: `x + y`, `x == y`, `x++`, `!x`. -- Try to keep the line length at ~85. If exceeded, separate it in different lines. -- `variable_names`, `CONSTANT_NAMES`, `Function_Names`, `StructureNames` -- Insert new line before curly braces in blocks of code: - -```js - -// Do this -if (condition) -{ - -} - -// Instead of this -if (condition){ - -} -``` - -- Always use curly braces after flow control statements. Even if it's followed -by only one line: - - ```js - // Do this - if (condition) - { - doSomethingInOneLine() - } - - // Instead of this - if (condition) - doSomethingInOneLine() - ``` - -## Versioning - -We follow [SemVer](https://semver.org/). - -Yup, just read it. Nothing to add. - -## GitHub Related - -### Issues - -If you have a question, don't open an issue. You can read the -[FAQ](https://github.com/daque-dev/viare/blob/master/FAQ.md), or send us an e-mail -at [contact@daque.me](mailto:contact@daque.me?Subject=Question) - -Issues are intended for reporting bugs, or discussing new features. - -Fortunately, GitHub allows us to provide an issue template. When you try to file -a new issue, you'll see it. Try to fill it with all the info you can. - -Not all fields are required for every new issue. It depends on whether it is a bug -report, or an enhancement discussion. - -#### Bugs - -The most important thing, is providing the necessary information to allow us to -reproduce the problem. **Try to be as descriptive as possible.** - -Again, the best way to learn how to file an issue, is by taking a look at our -[issue template](https://github.com/daque-dev/viare/issues/new). - -#### Enhancements - -This includes style changes, new features implementation, and general discussion -on how to make ViaRE better. - -We are more permissive on the structure of these issues. Anyways, you should still -try to be as descriptive as possible. - -### Pull Requests - -Firs, you should read [Git Flow](#git-flow) and [Code Style](#code-style) sections. - -Once you have some changes that you'd like to see merged into our codebase, [open a -Pull Request](https://github.com/daque-dev/viare/pull/new/master). We also have -a PR template, that you'll see once you try to open one. - -Again, the most important thing is that you describe what changes you've made, and -why you made them. - ---- - -## Thanks! - -All that said, we will be very thankful and happy if you decide to contribute with -the project. - -Don't be afraid to contribute if you feel you can't fulfil all of the rules in here. - -We will help you to help us. - -Cheers! \ No newline at end of file From ca9a0e1281dc5ed51d2fcb2281a02df97c5ef7fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Omar=20Flores=20Ch=C3=A1vez?= Date: Tue, 11 Sep 2018 17:43:28 -0500 Subject: [PATCH 22/32] Add REFERENCES file --- REFERENCES.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 REFERENCES.md diff --git a/REFERENCES.md b/REFERENCES.md new file mode 100644 index 0000000..457bdd4 --- /dev/null +++ b/REFERENCES.md @@ -0,0 +1,29 @@ +# References that got ViaRE to be born in our brains + +## Antrpology and History + +Harari, Y. N. (2014). *Sapiens: A brief history of humankind.* London: Vintage Books. + +Bryson, B. (2003). *A Short History of Nearly Everything.* London: Black Swan Books. + +## Geology + +Huggett, R. J. (2017). *Fundamentals of geomorphology.* London: Routledge. + +Wilson, J. P., & Gallant, J. C. (2000). *Terrain analysis: Principles and applications*. New York: Wiley. + +## Urban... + +### Transport + +Rodrigue, J., Comtois, C., & Slack, B. (2013). *The geography of transport systems.* New York: Routledge. + +### Design & planning + +McLaren, D., & Agyeman, J. (2017). *Sharing cities: A case for truly smart and sustainable cities.* Cambridge: MIT Press. + +Troy, P. N. (2004). *The structure and form of the Australian city: Prospects for improved urban planning.* Brisbane: Urban Policy Program, Griffith University. + +### Growth + +Reissman, L. (1964). *The urban process: Cities in industrial societies.* New York: Free Press of Glencoe. \ No newline at end of file From f9982225f0c55cfaab7c5d5b34f22e221db95d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Omar=20Flores=20Ch=C3=A1vez?= Date: Fri, 14 Sep 2018 20:48:59 -0500 Subject: [PATCH 23/32] Add Branching name convention inside git->branching --- .github/CONTRIBUTING.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 0c95c80..9d85ab4 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -55,6 +55,9 @@ a new version yet) go. From develop, we have multiple branches. Branches with meaningful names related to what is being developed inside each branch. +A branch name must be short and descriptive, all lowercase. +Again, keep modularity in mind. For branches with multiple words `use-hyphens`. + Once a new function or a bug-fix is implemented, we [create a Pull Request](#pull-requests) to merge changes back into `develop`. From e47b62af4cc81d9f2d6ebd279282a653e1efa7e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Omar=20Flores=20Ch=C3=A1vez?= Date: Fri, 14 Sep 2018 20:52:33 -0500 Subject: [PATCH 24/32] Add Branching name convention inside code-style section --- .github/CONTRIBUTING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 9d85ab4..77d1dcf 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -82,6 +82,7 @@ That said, these are our suggested rules - Use spaces around operators, except unaries: `x + y`, `x == y`, `x++`, `!x`. - Try to keep the line length at ~85. If exceeded, separate it in different lines. - `variable_names`, `CONSTANT_NAMES`, `Function_Names`, `StructureNames` +- Write branch names in all lowercase, separeted with hyphens, and avoiding verbs: `graphics-simplification`, `docs`, `population-dynamics` - Insert new line before curly braces in blocks of code: ```js From 3a053c28c1d5d479815b3b2ee03dcea8a832b1b3 Mon Sep 17 00:00:00 2001 From: Miguel Date: Sun, 30 Sep 2018 19:09:02 -0500 Subject: [PATCH 25/32] Change all camelCase and CamelCase identifiers to snake_case and Snake_Case identifiers. This commit makes viare compatible with CONTRIBUTING.md file's described coding style. --- source/app.d | 2 +- source/heightmap/heightmap.d | 28 ++-- source/heightmap/quev.d | 57 ++++---- source/heightmap/renderer.d | 201 +++++++++++++-------------- source/tests/heightmap-perspective.d | 119 +++++++++------- source/tests/heightmaptest.d | 13 -- source/tests/perspectivetest.d | 67 ++++----- source/vertex.d | 62 ++++----- 8 files changed, 277 insertions(+), 272 deletions(-) diff --git a/source/app.d b/source/app.d index 1c0cbd1..eed13cf 100644 --- a/source/app.d +++ b/source/app.d @@ -12,5 +12,5 @@ import daque.math.geometry; void main() { - heightmapPerspectiveTest(); + Heightmap_Perspective_Test(); } diff --git a/source/heightmap/heightmap.d b/source/heightmap/heightmap.d index 72bf703..e362e29 100644 --- a/source/heightmap/heightmap.d +++ b/source/heightmap/heightmap.d @@ -2,7 +2,7 @@ module viare.heightmap.heightmap; import viare.heightmap.heightfunction; -class HeightMap +class Heightmap { private: float[][] m_height; @@ -10,6 +10,7 @@ private: const uint m_ylength; public: + this(uint width, uint height) { m_xlength = width; @@ -22,12 +23,12 @@ public: m_height.each!((ref column) => column.each!((ref element) => element = 0)); } - uint getWidth() + uint Get_Width() { return m_xlength; } - uint getHeight() + uint Get_Height() { return m_ylength; } @@ -37,7 +38,7 @@ public: return m_height[i][j]; } - void fillByHeightFunction(HeightFunction heightFunction) + void Fill_By_Height_Function(HeightFunction height_function) { for (uint i; i < m_xlength; i++) { @@ -48,28 +49,39 @@ public: import std.stdio; writeln(cast(double)i / m_xlength); /// Don't know why. But fixes problem } - this[i, j] = heightFunction(cast(double) i / m_xlength, cast(double) j / m_ylength); + this[i, j] = height_function(cast(double) i / m_xlength, cast(double) j / m_ylength); } } } - void normalize() + void Normalize() { float lowest = this[0, 0], highest = this[0, 0]; for (uint i; i < m_xlength; i++) + { for (uint j; j < m_ylength; j++) { if (this[i, j] < lowest) + { lowest = this[i, j]; + } + if (this[i, j] > highest) + { highest = this[i, j]; + } } + } - immutable maxRelativeHeight = highest - lowest; + immutable max_relative_height = highest - lowest; for (uint i; i < m_xlength; i++) + { for (uint j; j < m_ylength; j++) - this[i, j] = (this[i, j] - lowest) / maxRelativeHeight; + { + this[i, j] = (this[i, j] - lowest) / max_relative_height; + } + } } } diff --git a/source/heightmap/quev.d b/source/heightmap/quev.d index a9bd316..411dacf 100644 --- a/source/heightmap/quev.d +++ b/source/heightmap/quev.d @@ -23,55 +23,55 @@ interface QuevCentersGenerator class StdQuevCentersGenerator : QuevCentersGenerator { private: - Params m_params; + Parameters m_parameters; public: - struct Params + struct Parameters { - double[2]delegate() positionGenerator; - double delegate() weightGenerator; - double delegate() baseGenerator; - double delegate() exponentGenerator; - double delegate() zoomGenerator; + double[2]delegate() position_generator; + double delegate() weight_generator; + double delegate() base_generator; + double delegate() exponent_generator; + double delegate() zoom_generator; } - static Params defaultParams; + static Parameters default_parameters; static this() { - defaultParams.positionGenerator = { + default_parameters.position_generator = { double x = uniform!"[)"(0.0, 1.0); double y = uniform!"[)"(0.0, 1.0); double[2] position = [x, y]; return position; }; - defaultParams.weightGenerator = { return uniform!"[]"(-1.0, 1.0); }; - defaultParams.baseGenerator = { return uniform!"[]"(1000.1, 1000.2); }; - defaultParams.exponentGenerator = { return uniform!"[]"(1.2, 5.6); }; - defaultParams.zoomGenerator = { return uniform!"[]"(0.125, 0.175); }; + default_parameters.weight_generator = { return uniform!"[]"(-1.0, 1.0); }; + default_parameters.base_generator = { return uniform!"[]"(1000.1, 1000.2); }; + default_parameters.exponent_generator = { return uniform!"[]"(1.2, 5.6); }; + default_parameters.zoom_generator = { return uniform!"[]"(0.125, 0.175); }; } - this(Params params) + this(Parameters parameters) { - m_params = params; + m_parameters = parameters; } this() { - this(defaultParams); + this(default_parameters); } - QuevCenter[] opCall(uint noCenters) + QuevCenter[] opCall(uint no_centers) { QuevCenter[] centers; - for (uint centerNo; centerNo < noCenters; centerNo++) + for (uint center_number; center_number < no_centers; center_number++) { - QuevCenter newCenter; - newCenter.position[] = m_params.positionGenerator()[]; - newCenter.weight = m_params.weightGenerator(); - newCenter.base = m_params.baseGenerator(); - newCenter.exponent = m_params.exponentGenerator(); - newCenter.zoom = m_params.zoomGenerator(); - centers ~= newCenter; + QuevCenter center; + center.position[] = m_parameters.position_generator()[]; + center.weight = m_parameters.weight_generator(); + center.base = m_parameters.base_generator(); + center.exponent = m_parameters.exponent_generator(); + center.zoom = m_parameters.zoom_generator(); + centers ~= center; } return centers; } @@ -85,6 +85,7 @@ private: static immutable epsilon = 0.01; public: + this(QuevCenter[] centers) { m_centers.length = centers.length; @@ -106,12 +107,12 @@ public: foreach (uint i, QuevCenter center; m_centers) { - immutable distanceToCenter = distance!double(point, center.position); - if (distanceToCenter > m_threshholds[i]) + immutable distance_to_center = distance!double(point, center.position); + if (distance_to_center > m_threshholds[i]) continue; total += center.weight * pow(center.base, - -pow(distanceToCenter / center.zoom, center.exponent)); + -pow(distance_to_center / center.zoom, center.exponent)); } return total; } diff --git a/source/heightmap/renderer.d b/source/heightmap/renderer.d index 4e6a20e..6e120ab 100644 --- a/source/heightmap/renderer.d +++ b/source/heightmap/renderer.d @@ -7,133 +7,126 @@ import viare.heightmap.heightmap; import viare.vertex; -interface HeightMapRenderer +struct WaterTerrainHeightmapRenderSettings { public: - Image render(HeightMap heightMap); + float[3] water_tint = [0.0, 0.0, 1.0], terrain_tint = [0.0, 1.0, 0.0]; + float water_level = 0.0f; + uint divisions = 0x100; } -class WaterTerrainHeightMapRenderer : HeightMapRenderer +Vertex[] Get_Heightmap_Mesh(WaterTerrainHeightmapRenderSettings render_settings, float height, float[2] size, Heightmap heightmap) { -public: - /++ - Renders a HeightMap into an Image + immutable heightmap_width = heightmap.Get_Width(); + immutable heightmap_height = heightmap.Get_Height(); - Params: - heightMap = heightmap to be rendered + float[2] Get_Base(uint i, uint j) + { + float[2] base; + base[0] = (i + 1.0f) / (heightmap_width + 1.0f) * size[0] - size[0] * 0.5f; + base[1] = (j + 1.0f) / (heightmap_height + 1.0f) * size[1] - size[1] * 0.5f; + return base; + } - Returns: - The image on which the heightmap was rendered - +/ - Image render(HeightMap heightMap) + Vertex Get_Vertex(uint i, uint j) { - immutable heightMapWidth = heightMap.getWidth(); - immutable heightMapHeight = heightMap.getHeight(); - Image image = new Image(heightMapWidth, heightMapHeight); + auto base = Get_Base(i, j); + float normal_height = heightmap[i, j]; + float point_height = normal_height * height; + bool is_water = (normal_height <= render_settings.water_level); + auto tint = is_water? render_settings.water_tint: render_settings.terrain_tint; + + immutable height_per_division = 1.0f / cast(float) render_settings.divisions; + immutable uint division = + normal_height == 1.0f ? + render_settings.divisions - 1 + : + cast(uint)(normal_height / height_per_division); + + point_height = height_per_division * division * height; + + Vertex vertex; + vertex.position[] = [base[0], point_height, base[1]]; + vertex.color[0 .. 3] = height_per_division * division * tint[]; + vertex.color[3] = 1.0f; + return vertex; + } - for (uint x; x < heightMapWidth; x++) + Vertex[] mesh; + for(uint i; i + 1 < heightmap_width; i++) + { + for(uint j; j + 1 < heightmap_height; j++) { - for (uint y; y < heightMapHeight; y++) + Vertex[2][2] vertex; + + for(uint di; di < 2; di++) { - immutable cellHeight = heightMap[x, y]; - immutable bool isWater = (cellHeight <= m_waterLevel); - immutable float[3] tint = isWater ? m_waterTint : m_terrainTint; - assert(m_divisions != 0); - immutable heightPerDivision = 1.0f / cast(float) m_divisions; - immutable uint division = cellHeight == 1.0f ? m_divisions - 1 - : cast(uint)(cellHeight / heightPerDivision); - immutable float[3] colorFloat = tint[] * (division * heightPerDivision * 0xFF); - - import std.algorithm; - import std.array; - - Color color; - color.component[0 .. 3] = map!(c => cast(ubyte) c)(colorFloat[]) - .array; - color.component[3] = 0xFF; - - image[x, y] = color.toInt(); + for(uint dj; dj < 2; dj++) + { + vertex[di][dj] = Get_Vertex(i + di, j + dj); + } } - } - return image; - } + mesh ~= vertex[0][0]; + mesh ~= vertex[1][0]; + mesh ~= vertex[0][1]; - void setWaterLevel(float waterLevel) - { - m_waterLevel = waterLevel; + mesh ~= vertex[1][0]; + mesh ~= vertex[1][1]; + mesh ~= vertex[0][1]; + } } - void setWaterTint(float[3] waterTint) - { - m_waterTint[] = waterTint[]; - } + return mesh; +} +/++ + Renders a Heightmap into an Image - void setTerrainTint(float[3] terrainTint) - { - m_terrainTint[] = terrainTint[]; - } + Params: + heightMap = heightmap to be rendered - void setDivisions(uint divisions) - { - m_divisions = divisions; - } + Returns: + The image on which the heightmap was rendered ++/ - Vertex[] getMesh(float height, float[2] size, HeightMap hm) +Image Render(WaterTerrainHeightmapRenderSettings render_settings, Heightmap heightmap) +{ + immutable heightmap_width = heightmap.Get_Width(); + immutable heightmap_height = heightmap.Get_Height(); + Image image = new Image(heightmap_width, heightmap_height); + + for (uint x; x < heightmap_width; x++) { - immutable hmWidth = hm.getWidth(); - immutable hmHeight = hm.getHeight(); - float[2] getBase(uint i, uint j) - { - float[2] base; - base[0] = (i + 1.0f) / (hmWidth + 1.0f) * size[0] - size[0] * 0.5f; - base[1] = (j + 1.0f) / (hmHeight + 1.0f) * size[1] - size[1] * 0.5f; - return base; - } - Vertex getVertex(uint i, uint j) + for (uint y; y < heightmap_height; y++) { - auto base = getBase(i, j); - float normalHeight = hm[i, j]; - float pointHeight = normalHeight * height; - bool isWater = (normalHeight <= m_waterLevel); - auto tint = isWater? m_waterTint: m_terrainTint; - - immutable heightPerDivision = 1.0f / cast(float) m_divisions; - immutable uint division = normalHeight == 1.0f ? m_divisions - 1 - : cast(uint)(normalHeight / heightPerDivision); - - pointHeight = heightPerDivision * division * height; - - Vertex v; - v.position[] = [base[0], pointHeight, base[1]]; - v.color[0 .. 3] = heightPerDivision * division * tint[]; - v.color[3] = 1.0f; - return v; - } + immutable cell_height = heightmap[x, y]; - Vertex[] mesh; - for(uint i; i + 1 < hmWidth; i++) - { - for(uint j; j + 1 < hmHeight; j++) - { - Vertex[2][2] v; - for(uint di; di < 2; di++) - for(uint dj; dj < 2; dj++) - v[di][dj] = getVertex(i + di, j + dj); - mesh ~= v[0][0]; - mesh ~= v[1][0]; - mesh ~= v[0][1]; - - mesh ~= v[1][0]; - mesh ~= v[1][1]; - mesh ~= v[0][1]; - } + immutable bool is_water = (cell_height <= render_settings.water_level); + + immutable float[3] tint = is_water ? render_settings.water_tint : render_settings.terrain_tint; + + assert(render_settings.divisions != 0); + + immutable height_per_division = 1.0f / cast(float) render_settings.divisions; + + immutable uint division = + cell_height == 1.0f? + render_settings.divisions - 1 + : + cast(uint)(cell_height / height_per_division); + + immutable float[3] color_float = tint[] * (division * height_per_division * 0xFF); + + import std.algorithm; + import std.array; + + Color color; + color.component[0 .. 3] = map!(c => cast(ubyte) c)(color_float[]).array; + color.component[3] = 0xFF; + + image[x, y] = color.toInt(); } - return mesh; } -private: - float[3] m_waterTint, m_terrainTint; - float m_waterLevel; - uint m_divisions = 0x100; + return image; } diff --git a/source/tests/heightmap-perspective.d b/source/tests/heightmap-perspective.d index 275060e..0db968b 100644 --- a/source/tests/heightmap-perspective.d +++ b/source/tests/heightmap-perspective.d @@ -33,7 +33,7 @@ import viare.heightmap.renderer; import viare.vertex; -void heightmapPerspectiveTest() +void Heightmap_Perspective_Test() { Window window = new Window("viare", 800, 800); @@ -58,79 +58,91 @@ void heightmapPerspectiveTest() perspective.setUniform!(3, "f")(translation, [0.0f, 0.0f, -2.5f]); // Height Function - immutable numberOfCenters = uniform!"[]"(300, 400); - QuevCenter[] centers = new StdQuevCentersGenerator()(numberOfCenters); - HeightFunction heightFunction = new QuevHeightFunction(centers); + immutable number_of_centers = uniform!"[]"(300, 400); + QuevCenter[] centers = new StdQuevCentersGenerator()(number_of_centers); + HeightFunction height_function = new QuevHeightFunction(centers); - // HeightMap Fill - HeightMap heightMap = new HeightMap(70, 70); + // Heightmap Fill + Heightmap heightmap = new Heightmap(70, 70); writeln("Calculating heights"); - heightMap.fillByHeightFunction(heightFunction); + heightmap.Fill_By_Height_Function(height_function); writeln("Finished calculating heights"); - heightMap.normalize(); + heightmap.Normalize(); + // // Tints - float[3] blueTint = [0.0f, 0.3f, 0.7]; - float[3] greenTint = [0.0f, 0.7f, 0.5f]; - float[3] whiteTint = [1.0f, 1.0f, 1.0f]; - float[3] brownTint = [0.7f, 0.5f, 0.3f]; - - // HeightMap Rendering Configuration - WaterTerrainHeightMapRenderer renderer = new WaterTerrainHeightMapRenderer(); - renderer.setWaterLevel(0.5); - renderer.setWaterTint(blueTint); - renderer.setTerrainTint(brownTint); - renderer.setDivisions(20); - - Vertex[] hmMesh = renderer.getMesh(5.0f, [20.0f, 20.0f], heightMap); - auto gpuVertices = new GpuArray( - hmMesh, - cast(uint) hmMesh.length, - Vertex.formats); - + float[3] blue_tint = [0.0f, 0.3f, 0.7]; + float[3] green_tint = [0.0f, 0.7f, 0.5f]; + float[3] white_tint = [1.0f, 1.0f, 1.0f]; + float[3] brown_tint = [0.7f, 0.5f, 0.3f]; + // + + // Heightmap Rendering + WaterTerrainHeightmapRenderSettings heightmap_render_settings = {water_level: 0.5, water_tint: blue_tint, terrain_tint: brown_tint, divisions: 20}; + Vertex[] heightmap_mesh = Get_Heightmap_Mesh(heightmap_render_settings, 5.0f, [20.0f, 20.0f], heightmap); + GpuArray heightmap_mesh_in_gpu = new GpuArray(heightmap_mesh, cast(uint) heightmap_mesh.length, Vertex.formats); + // + + // Depth mask OpenGL configuration glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); glDepthFunc(GL_GREATER); glClearDepth(0.0); + // - // Translation - float[] translationVector = [0.0f, 0.0f, -2.5f]; - - // Rotation stuff - immutable dr = Quaternion!float.getRotation([0, 1, 0], 0.01); - auto rotationQuaternion = cast(Quaternion!float) dr; - - immutable delta = 0.1; - auto scancode = SDL_SCANCODE_W; - float[][SDL_Scancode] movements = + // Model translation + float[] model_translation = [0.0f, 0.0f, -2.5f]; + // + + // Model rotation + immutable model_step_rotation = Quaternion!float.getRotation([0, 1, 0], 0.01); + auto model_rotation = cast(Quaternion!float) model_step_rotation; + // + + // Controller configuration + immutable controller_movement = 0.1; + float[][SDL_Scancode] controller_movements = [ - SDL_SCANCODE_W: [0, 0, -delta], - SDL_SCANCODE_S: [0, 0, +delta], - SDL_SCANCODE_D: [+delta, 0, 0], - SDL_SCANCODE_A: [-delta, 0, 0], - SDL_SCANCODE_E: [0, +delta, 0], - SDL_SCANCODE_Q: [0, -delta, 0] + SDL_SCANCODE_W: [0, 0, -controller_movement], + SDL_SCANCODE_S: [0, 0, +controller_movement], + SDL_SCANCODE_D: [+controller_movement, 0, 0], + SDL_SCANCODE_A: [-controller_movement, 0, 0], + SDL_SCANCODE_E: [0, +controller_movement, 0], + SDL_SCANCODE_Q: [0, -controller_movement, 0] ]; + // while (window.isOpen()) { - // model movement - ubyte* key = SDL_GetKeyboardState(null); - foreach(SDL_Scancode code, float[] movement; movements) - if(key[code]) - translationVector[] += movement[]; - - rotationQuaternion = rotationQuaternion * dr; + // keyboard state querying + ubyte* keyboard_state = SDL_GetKeyboardState(null); + // + + // controller action taking + foreach(SDL_Scancode controller_key_scancode, float[] controller_movement; controller_movements) + { + if (keyboard_state[controller_key_scancode]) + { + model_translation[] += controller_movement[]; + } + } + // + + // step rotation + model_rotation = model_rotation * model_step_rotation; + // // uniform setting - perspective.setUniformMatrix(rotation, rotationQuaternion.rotationMatrix()); - perspective.setUniform!(3, "f")(translation, translationVector); + perspective.setUniformMatrix(rotation, model_rotation.rotationMatrix()); + perspective.setUniform!(3, "f")(translation, model_translation); + // - // render + // rendering window.clear(); perspective.use(); - render(gpuVertices); + render(heightmap_mesh_in_gpu); window.print(); + // // event handling SDL_Event event; @@ -145,6 +157,7 @@ void heightmapPerspectiveTest() break; } } + // } return; diff --git a/source/tests/heightmaptest.d b/source/tests/heightmaptest.d index a655b20..7756a06 100644 --- a/source/tests/heightmaptest.d +++ b/source/tests/heightmaptest.d @@ -30,19 +30,6 @@ import viare.heightmap.heightmap; import viare.heightmap.heightfunction; import viare.heightmap.renderer; -void heightMapDebugging() -{ - immutable noCenters = uniform!"[]"(100, 200); - QuevCenter[] centers = new StdQuevCentersGenerator()(noCenters); - HeightFunction heightFunction = new QuevHeightFunction(centers); - - double first = heightFunction(0, 0); - double second = heightFunction(0.4, 0.4); - - writeln(first); - writeln(second); -} - /* deprecated void heightMapTest() { diff --git a/source/tests/perspectivetest.d b/source/tests/perspectivetest.d index 2433354..67e71cb 100644 --- a/source/tests/perspectivetest.d +++ b/source/tests/perspectivetest.d @@ -32,17 +32,17 @@ import viare.heightmap.renderer; import viare.vertex; -void perspectiveTest() +void Perspective_Test() { // window setup Window window = new Window("viare perspective test", 800, 600); // perspective program setup Program perspective = new Program(); - Shader vertexShader = new Shader(Shader.Type.Vertex, "shaders/perspective-vertex.glsl"); - Shader fragmentShader = new Shader(Shader.Type.Fragment, "shaders/perspective-fragment.glsl"); - perspective.attach(vertexShader); - perspective.attach(fragmentShader); + Shader vertex_shader = new Shader(Shader.Type.Vertex, "shaders/perspective-vertex.glsl"); + Shader fragment_shader = new Shader(Shader.Type.Fragment, "shaders/perspective-fragment.glsl"); + perspective.attach(vertex_shader); + perspective.attach(fragment_shader); perspective.link(); immutable uZn = perspective.getUniformLocation("z_near"); @@ -58,8 +58,8 @@ void perspectiveTest() perspective.setUniform!(1, "f")(xyRatio, [800.0f / 600.0f]); perspective.setUniform!(3, "f")(translation, [0.0f, 0.0f, -2.5f]); - // Vertex specification - Vertex[] vertices = [{ + // Triangle vertices specification + Vertex[] triangle_vertices = [{ position: [0, 1, 0], color : [1, 0, 0, 1] }, { @@ -69,50 +69,51 @@ void perspectiveTest() position: [-1, -1, 0], color : [0, 0, 1, 1] }]; - foreach(ref v; vertices) + foreach(ref v; triangle_vertices) v.position[] = normalize(v.position[]); - - auto gpuVertices = new GpuArray( - vertices, - cast(uint) vertices.length, - Vertex.formats); + auto triangle_vertices_in_gpu = new GpuArray(triangle_vertices, cast(uint) triangle_vertices.length, Vertex.formats); + // // Translation - float[] translationVector = [0.0f, 0.0f, -2.5f]; + float[] model_translation = [0.0f, 0.0f, -2.5f]; // Rotation stuff - immutable dr = Quaternion!float.getRotation([1, 3, 7], 0.01); - auto rotationQuaternion = cast(Quaternion!float) dr; + immutable model_step_rotation = Quaternion!float.getRotation([1, 3, 7], 0.01); + auto model_rotation = cast(Quaternion!float) model_step_rotation; - immutable delta = 0.1; - auto scancode = SDL_SCANCODE_W; - float[][SDL_Scancode] movements = + immutable controller_movement = 0.1; + float[][SDL_Scancode] controller_movements = [ - SDL_SCANCODE_W: [0, 0, -delta], - SDL_SCANCODE_S: [0, 0, +delta], - SDL_SCANCODE_D: [+delta, 0, 0], - SDL_SCANCODE_A: [-delta, 0, 0], - SDL_SCANCODE_E: [0, +delta, 0], - SDL_SCANCODE_Q: [0, -delta, 0] + SDL_SCANCODE_W: [0, 0, -controller_movement], + SDL_SCANCODE_S: [0, 0, +controller_movement], + SDL_SCANCODE_D: [+controller_movement, 0, 0], + SDL_SCANCODE_A: [-controller_movement, 0, 0], + SDL_SCANCODE_E: [0, +controller_movement, 0], + SDL_SCANCODE_Q: [0, -controller_movement, 0] ]; while (window.isOpen()) { // general processing - rotationQuaternion = rotationQuaternion * dr; + model_rotation = model_rotation * model_step_rotation; - ubyte* key = SDL_GetKeyboardState(null); - foreach(SDL_Scancode code, float[] movement; movements) - if(key[code]) - translationVector[] += movement[]; + // keyboard state query + ubyte* keyboard_state = SDL_GetKeyboardState(null); + foreach(SDL_Scancode code, float[] movement; controller_movements) + { + if(keyboard_state[code]) + { + model_translation[] += movement[]; + } + } // pre-rendering operations - perspective.setUniformMatrix(rotation, rotationQuaternion.rotationMatrix()); - perspective.setUniform!(3, "f")(translation, translationVector); + perspective.setUniformMatrix(rotation, model_rotation.rotationMatrix()); + perspective.setUniform!(3, "f")(translation, model_translation); // rendering window.clear(); perspective.use(); - render(gpuVertices); + render(triangle_vertices_in_gpu); window.print(); // event processing diff --git a/source/vertex.d b/source/vertex.d index e14943f..4732dfe 100644 --- a/source/vertex.d +++ b/source/vertex.d @@ -7,65 +7,66 @@ import derelict.opengl; import daque.graphics.opengl; -alias Vertex = Vert!"3f.0:position 4fn1:color"; +alias Vertex = DefineVertex!"3f.0:position 4fn1:color"; // 3f.0:position 4fn1:color struct MemberInfo { string type; string identifier; - string index; string size; - string glType; + string gl_type; string normalized; } -MemberInfo getInfo(string memberString) pure nothrow +MemberInfo Get_Info(string member_string) pure nothrow { - string[] parts = split(memberString, ":"); + string[] parts = split(member_string, ":"); string first = parts[0]; string second = parts[1]; string type = (first[1] == 'f')? "float" : "float"; string size = first[0 .. 1]; - MemberInfo info; - info.type = type ~ "[" ~ size ~ "]"; - info.identifier = second; - info.index = memberString[3 .. 4]; - info.size = size; - info.glType = (type == "float")? "GL_FLOAT" : "GL_FLOAT"; - info.normalized = (memberString[2] == 'n')? "GL_TRUE" : "GL_FALSE"; + MemberInfo info = { + type: type ~ "[" ~ size ~ "]", + identifier: second, + index: member_string[3 .. 4], + size: size, + gl_type: (type == "float")? "GL_FLOAT" : "GL_FLOAT", + normalized: (member_string[2] == 'n')? "GL_TRUE" : "GL_FALSE" + }; return info; } -MemberInfo[] getInfos(string membersString) pure nothrow + +MemberInfo[] Get_Infos(string members_string) pure nothrow { - string[] memberString = split(membersString, " "); + string[] member_string = split(members_string, " "); MemberInfo[] infos; - foreach(str; memberString) + foreach(str; member_string) { - infos ~= getInfo(str); + infos ~= Get_Info(str); } return infos; } -string attrFormatString(MemberInfo info) +string Get_AttributeFormat_String(MemberInfo info) { return "{ index: " ~ info.index ~ ", size: " ~ info.size ~ - ", type: " ~ info.glType ~ + ", type: " ~ info.gl_type ~ ", normalized: " ~ info.normalized ~ ", stride: this.sizeof" ~ ", pointer: cast(void*) this." ~ info.identifier ~ ".offsetof}"; } -string attrFormatStrings(MemberInfo[] infos) +string Get_AttributeFormat_Strings(MemberInfo[] infos) { string str = "["; foreach(uint i, MemberInfo info; infos) { - str ~= attrFormatString(info); + str ~= Get_AttributeFormat_String(info); if(i + 1 < infos.length) str ~= ", "; } @@ -73,27 +74,24 @@ string attrFormatStrings(MemberInfo[] infos) return str; } -string declaration(MemberInfo info) +string Get_Declaration(MemberInfo info) { return info.type ~ " " ~ info.identifier ~ ";"; } -string formStruct(string membersString) +string Form_Struct(string members_string) { - string structString; - auto infos = getInfos(membersString); + string struct_string; + auto infos = Get_Infos(members_string); foreach(info; infos) - structString ~= declaration(info); - structString ~= "static AttributeFormat[] formats = " ~ attrFormatStrings(infos) ~ ";"; - return structString; + struct_string ~= Get_Declaration(info); + struct_string ~= "static AttributeFormat[] formats = " ~ Get_AttributeFormat_Strings(infos) ~ ";"; + return struct_string; } -template Vert(string membersString) +struct DefineVertex(string members_string) { - struct Vert - { - mixin(formStruct(membersString)); - } + mixin(Form_Struct(members_string)); } unittest From a126a2e207529cecaea1ed01b60aebc48810f676 Mon Sep 17 00:00:00 2001 From: Miguel Date: Sun, 30 Sep 2018 19:48:09 -0500 Subject: [PATCH 26/32] Delete + accidental file. --- + | 133 -------------------------------------------------------------- 1 file changed, 133 deletions(-) delete mode 100644 + diff --git a/+ b/+ deleted file mode 100644 index 63d06ec..0000000 --- a/+ +++ /dev/null @@ -1,133 +0,0 @@ -module viare.heightmap.renderer; - -import daque.graphics.image; -import daque.graphics.color; - -import viare.heightmap.heightmap; - -import viare.vertex; - -interface HeightMapRenderer -{ -public: - Image render(HeightMap heightMap); -} - -class WaterTerrainHeightMapRenderer : HeightMapRenderer -{ -public: - /++ - Renders a HeightMap into an Image - - Params: - heightMap = heightmap to be rendered - - Returns: - The image on which the heightmap was rendered - +/ - Image render(HeightMap heightMap) - { - immutable heightMapWidth = heightMap.getWidth(); - immutable heightMapHeight = heightMap.getHeight(); - Image image = new Image(heightMapWidth, heightMapHeight); - - for (uint x; x < heightMapWidth; x++) - { - for (uint y; y < heightMapHeight; y++) - { - immutable cellHeight = heightMap[x, y]; - immutable bool isWater = (cellHeight <= m_waterLevel); - immutable float[3] tint = isWater ? m_waterTint : m_terrainTint; - assert(m_divisions != 0); - immutable heightPerDivision = 1.0f / cast(float) m_divisions; - immutable uint division = cellHeight == 1.0f ? m_divisions - 1 - : cast(uint)(cellHeight / heightPerDivision); - immutable float[3] colorFloat = tint[] * (division * heightPerDivision * 0xFF); - - import std.algorithm; - import std.array; - - Color color; - color.component[0 .. 3] = map!(c => cast(ubyte) c)(colorFloat[]) - .array; - color.component[3] = 0xFF; - - image[x, y] = color.toInt(); - } - } - - return image; - } - - void setWaterLevel(float waterLevel) - { - m_waterLevel = waterLevel; - } - - void setWaterTint(float[3] waterTint) - { - m_waterTint[] = waterTint[]; - } - - void setTerrainTint(float[3] terrainTint) - { - m_terrainTint[] = terrainTint[]; - } - - void setDivisions(uint divisions) - { - m_divisions = divisions; - } - - Vertex[] getMesh(float height, float[2] size, HeightMap hm) - { - immutable hmWidth = hm.getWidth(); - immutable hmHeight = hm.getHeight(); - float[2] getBase(uint i, uint j) - { - float[2] base; - base[0] = (i + 1.0f) / (hmWidth + 1.0f) * size[0]; - base[1] = (j + 1.0f) / (hmHeight + 1.0f) * size[1]; - return base; - } - Vertex getVertex(uint i, uint j) - { - auto base = getBase(i, j); - float normalHeight = hm[i, j]; - float height = normalHeight * height; - bool isWater = (normalHeight <= m_waterLevel); - auto tint = isWater? m_waterTint: m_terrainTint; - - Vertex v; - v.position[] = [base[0], height, base[1]]; - v.color[0 .. 3] = normalHeight * tint[]; - v.color[3] = 1.0f; - return v; - } - - Vertex[] mesh; - for(uint i; i + 1 < hmWidth; i++) - { - for(uint j; j + 1 < hmHeight; j++) - { - Vertex[2][2] v; - for(uint di; di < 2; di++) - for(uint dj; dj < 2; dj++) - v[di][dj] = getVertex(i + di, j + dj); - mesh ~= v[0][0]; - mesh ~= v[1][0]; - mesh ~= v[0][1]; - - mesh ~= v[1][0]; - mesh ~= v[1][1]; - mesh ~= v[0][1]; - } - } - return mesh; - } - -private: - float[3] m_waterTint, m_terrainTint; - float m_waterLevel; - uint m_divisions = 0x100; -} From 003ae19779a3cde98c5ff6522764aff1089aabfd Mon Sep 17 00:00:00 2001 From: Miguel Date: Sun, 30 Sep 2018 19:49:26 -0500 Subject: [PATCH 27/32] Delete now deprecated format-related files. --- .editorconfig | 7 ------- format.sh | 3 --- 2 files changed, 10 deletions(-) delete mode 100644 .editorconfig delete mode 100644 format.sh diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 86af6a6..0000000 --- a/.editorconfig +++ /dev/null @@ -1,7 +0,0 @@ -# EditorConfig - -root = true - -[*.d] -indent_style = space -max_line_length = 80 diff --git a/format.sh b/format.sh deleted file mode 100644 index 0c045e3..0000000 --- a/format.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -find . -name "*.d" -exec dfmt -i '{}' --indent_style space --max_line_length 80 --soft_max_line_length 80 ';' From a8b720cf0363049e9f2b3750258598ffc1cf83e3 Mon Sep 17 00:00:00 2001 From: Miguel Date: Sun, 14 Oct 2018 01:10:29 -0500 Subject: [PATCH 28/32] Remove tests to make the project compile --- source/app.d | 5 - source/heightmap/renderer.d | 8 +- source/tests/heightmap-perspective.d | 151 --------------------------- source/tests/heightmaptest.d | 139 ------------------------ source/tests/perspectivetest.d | 133 ----------------------- source/vertex.d | 106 ------------------- 6 files changed, 6 insertions(+), 536 deletions(-) delete mode 100644 source/tests/heightmap-perspective.d delete mode 100644 source/tests/heightmaptest.d delete mode 100644 source/tests/perspectivetest.d delete mode 100644 source/vertex.d diff --git a/source/app.d b/source/app.d index 1c0cbd1..826759b 100644 --- a/source/app.d +++ b/source/app.d @@ -4,13 +4,8 @@ import std.stdio; import std.file; import std.ascii; -import viare.tests.perspective; -import viare.tests.heightmap; -import viare.tests.heightmapperspective; - import daque.math.geometry; void main() { - heightmapPerspectiveTest(); } diff --git a/source/heightmap/renderer.d b/source/heightmap/renderer.d index 4e6a20e..a326b48 100644 --- a/source/heightmap/renderer.d +++ b/source/heightmap/renderer.d @@ -5,14 +5,18 @@ import daque.graphics.color; import viare.heightmap.heightmap; -import viare.vertex; - interface HeightMapRenderer { public: Image render(HeightMap heightMap); } +struct Vertex +{ + float[3] position; + float[4] color; +} + class WaterTerrainHeightMapRenderer : HeightMapRenderer { public: diff --git a/source/tests/heightmap-perspective.d b/source/tests/heightmap-perspective.d deleted file mode 100644 index 275060e..0000000 --- a/source/tests/heightmap-perspective.d +++ /dev/null @@ -1,151 +0,0 @@ -module viare.tests.heightmapperspective; - -import std.stdio; -import std.file; -import std.ascii; -import std.uni; -import std.string; -import std.math; -import std.random; - -import core.thread; - -import derelict.opengl; -import derelict.sdl2.sdl; -import derelict.sdl2.image; - -import daque.math.linear; -import daque.math.geometry; -import daque.math.quaternion; - -import daque.graphics.opengl; -import daque.graphics.sdl; -import daque.graphics.color; -import daque.graphics.image; - -import viare.models; - -import viare.heightmap.quev; -import viare.heightmap.heightmap; -import viare.heightmap.heightfunction; -import viare.heightmap.renderer; - -import viare.vertex; - - -void heightmapPerspectiveTest() -{ - Window window = new Window("viare", 800, 800); - - // GLSL textureProgram - Program perspective = new Program([ - new Shader(Shader.Type.Vertex, "shaders/perspective-vertex.glsl"), - new Shader(Shader.Type.Fragment, "shaders/perspective-fragment.glsl")]); - perspective.link(); - - // Uniform setting - immutable uZn = perspective.getUniformLocation("z_near"); - immutable uZf = perspective.getUniformLocation("z_far"); - immutable alpha = perspective.getUniformLocation("alpha"); - immutable xyRatio = perspective.getUniformLocation("xy_ratio"); - immutable rotation = perspective.getUniformLocation("rotation"); - immutable translation = perspective.getUniformLocation("translation"); - - perspective.setUniform!(1, "f")(uZn, [1.0f]); - perspective.setUniform!(1, "f")(uZf, [100.0f]); - perspective.setUniform!(1, "f")(alpha, [45.0f]); - perspective.setUniform!(1, "f")(xyRatio, [800.0f / 600.0f]); - perspective.setUniform!(3, "f")(translation, [0.0f, 0.0f, -2.5f]); - - // Height Function - immutable numberOfCenters = uniform!"[]"(300, 400); - QuevCenter[] centers = new StdQuevCentersGenerator()(numberOfCenters); - HeightFunction heightFunction = new QuevHeightFunction(centers); - - // HeightMap Fill - HeightMap heightMap = new HeightMap(70, 70); - writeln("Calculating heights"); - heightMap.fillByHeightFunction(heightFunction); - writeln("Finished calculating heights"); - heightMap.normalize(); - - // Tints - float[3] blueTint = [0.0f, 0.3f, 0.7]; - float[3] greenTint = [0.0f, 0.7f, 0.5f]; - float[3] whiteTint = [1.0f, 1.0f, 1.0f]; - float[3] brownTint = [0.7f, 0.5f, 0.3f]; - - // HeightMap Rendering Configuration - WaterTerrainHeightMapRenderer renderer = new WaterTerrainHeightMapRenderer(); - renderer.setWaterLevel(0.5); - renderer.setWaterTint(blueTint); - renderer.setTerrainTint(brownTint); - renderer.setDivisions(20); - - Vertex[] hmMesh = renderer.getMesh(5.0f, [20.0f, 20.0f], heightMap); - auto gpuVertices = new GpuArray( - hmMesh, - cast(uint) hmMesh.length, - Vertex.formats); - - glEnable(GL_DEPTH_TEST); - glDepthMask(GL_TRUE); - glDepthFunc(GL_GREATER); - glClearDepth(0.0); - - // Translation - float[] translationVector = [0.0f, 0.0f, -2.5f]; - - // Rotation stuff - immutable dr = Quaternion!float.getRotation([0, 1, 0], 0.01); - auto rotationQuaternion = cast(Quaternion!float) dr; - - immutable delta = 0.1; - auto scancode = SDL_SCANCODE_W; - float[][SDL_Scancode] movements = - [ - SDL_SCANCODE_W: [0, 0, -delta], - SDL_SCANCODE_S: [0, 0, +delta], - SDL_SCANCODE_D: [+delta, 0, 0], - SDL_SCANCODE_A: [-delta, 0, 0], - SDL_SCANCODE_E: [0, +delta, 0], - SDL_SCANCODE_Q: [0, -delta, 0] - ]; - - while (window.isOpen()) - { - // model movement - ubyte* key = SDL_GetKeyboardState(null); - foreach(SDL_Scancode code, float[] movement; movements) - if(key[code]) - translationVector[] += movement[]; - - rotationQuaternion = rotationQuaternion * dr; - - // uniform setting - perspective.setUniformMatrix(rotation, rotationQuaternion.rotationMatrix()); - perspective.setUniform!(3, "f")(translation, translationVector); - - // render - window.clear(); - perspective.use(); - render(gpuVertices); - window.print(); - - // event handling - SDL_Event event; - while (SDL_PollEvent(&event)) - { - switch (event.type) - { - case SDL_QUIT: - window.close(); - break; - default: - break; - } - } - } - - return; -} diff --git a/source/tests/heightmaptest.d b/source/tests/heightmaptest.d deleted file mode 100644 index a655b20..0000000 --- a/source/tests/heightmaptest.d +++ /dev/null @@ -1,139 +0,0 @@ -// Core of the game -module viare.tests.heightmap; - -import std.stdio; -import std.file; -import std.ascii; -import std.uni; -import std.string; -import std.math; -import std.random; - -import core.thread; - -import derelict.opengl; -import derelict.sdl2.sdl; -import derelict.sdl2.image; - -import daque.math.linear; -import daque.math.geometry; - -import daque.graphics.opengl; -import daque.graphics.sdl; -import daque.graphics.color; -import daque.graphics.image; - -import viare.models; - -import viare.heightmap.quev; -import viare.heightmap.heightmap; -import viare.heightmap.heightfunction; -import viare.heightmap.renderer; - -void heightMapDebugging() -{ - immutable noCenters = uniform!"[]"(100, 200); - QuevCenter[] centers = new StdQuevCentersGenerator()(noCenters); - HeightFunction heightFunction = new QuevHeightFunction(centers); - - double first = heightFunction(0, 0); - double second = heightFunction(0.4, 0.4); - - writeln(first); - writeln(second); -} - -/* -deprecated void heightMapTest() -{ - Window window = new Window("viare", 800, 800); - - // GLSL textureProgram - Program textureProgram = new Program([new Shader(Shader.Type.Vertex, "shaders/texture-vertex.glsl"), - new Shader(Shader.Type.Fragment, "shaders/texture-fragment.glsl")]); - textureProgram.link(); - - // Model setup - Vertex[] squareData = SQUARE_VERTICES.dup; - Vertex[] frontSquareData; - frontSquareData.length = squareData.length; - frontSquareData[] = squareData[]; - import std.algorithm; - frontSquareData.each!((ref v) => v.position[2] += 0.5); - - auto square = new GpuArray!Vertex(SQUARE_VERTICES.dup); - auto frontSquare = new GpuArray!Vertex(frontSquareData); - - // Texture creation - Texture testTexture = new Texture(100, 100); - Texture frontTexture = new Texture(100, 100); - - // Height Function - immutable numberOfCenters = uniform!"[]"(300, 400); - QuevCenter[] centers = new StdQuevCentersGenerator()(numberOfCenters); - HeightFunction heightFunction = new QuevHeightFunction(centers); - - // HeightMap Fill - HeightMap heightMap = new HeightMap(testTexture.width, testTexture.height); - writeln("Calculating heights"); - heightMap.fillByHeightFunction(heightFunction); - writeln("Finished calculating heights"); - heightMap.normalize(); - - // Tints - float[3] blueTint = [0.0f, 0.3f, 0.7]; - float[3] greenTint = [0.0f, 0.7f, 0.5f]; - float[3] whiteTint = [1.0f, 1.0f, 1.0f]; - float[3] brownTint = [0.7f, 0.5f, 0.3f]; - - // HeightMap Rendering Configuration - WaterTerrainHeightMapRenderer renderer = new WaterTerrainHeightMapRenderer(); - renderer.setWaterLevel(0.5); - renderer.setWaterTint(blueTint); - renderer.setTerrainTint(brownTint); - renderer.setDivisions(10); - - // HeightMap rendering - writeln("Rendering"); - Image image = renderer.render(heightMap); - testTexture.updateRegion(0, 0, testTexture.width, testTexture.height, - image.linearize!(MatrixOrder.RowMajor)()); - writeln("Finished rendering"); - - - setTextureUnit(0, testTexture); - setTextureUnit(1, frontTexture); - - glEnable(GL_DEPTH_TEST); - // Drawing operations - while (window.isOpen()) - { - window.clear(); - - textureProgram.use(); - - textureProgram.setUniform1i("sampler", 0); - render(square); - - textureProgram.setUniform1i("sampler", 1); - render(frontSquare); - - window.print(); - - SDL_Event event; - while (SDL_PollEvent(&event)) - { - switch (event.type) - { - case SDL_QUIT: - window.close(); - break; - default: - break; - } - } - } - - return; -} -*/ diff --git a/source/tests/perspectivetest.d b/source/tests/perspectivetest.d deleted file mode 100644 index 2433354..0000000 --- a/source/tests/perspectivetest.d +++ /dev/null @@ -1,133 +0,0 @@ -// Core of the game -module viare.tests.perspective; - -import std.stdio; -import std.file; -import std.ascii; -import std.string; -import std.math; -import std.random; - -import core.thread; - -import derelict.opengl; -import derelict.sdl2.sdl; -import derelict.sdl2.image; - -import daque.math.geometry; -import daque.math.linear; -import daque.math.quaternion; - -import daque.graphics.opengl; -import daque.graphics.color; -import daque.graphics.image; -import daque.graphics.sdl; - -import viare.models; - -import viare.heightmap.quev; -import viare.heightmap.heightmap; -import viare.heightmap.heightfunction; -import viare.heightmap.renderer; -import viare.vertex; - - -void perspectiveTest() -{ - // window setup - Window window = new Window("viare perspective test", 800, 600); - - // perspective program setup - Program perspective = new Program(); - Shader vertexShader = new Shader(Shader.Type.Vertex, "shaders/perspective-vertex.glsl"); - Shader fragmentShader = new Shader(Shader.Type.Fragment, "shaders/perspective-fragment.glsl"); - perspective.attach(vertexShader); - perspective.attach(fragmentShader); - perspective.link(); - - immutable uZn = perspective.getUniformLocation("z_near"); - immutable uZf = perspective.getUniformLocation("z_far"); - immutable alpha = perspective.getUniformLocation("alpha"); - immutable xyRatio = perspective.getUniformLocation("xy_ratio"); - immutable rotation = perspective.getUniformLocation("rotation"); - immutable translation = perspective.getUniformLocation("translation"); - - perspective.setUniform!(1, "f")(uZn, [0.1]); - perspective.setUniform!(1, "f")(uZf, [100.0f]); - perspective.setUniform!(1, "f")(alpha, [45.0f]); - perspective.setUniform!(1, "f")(xyRatio, [800.0f / 600.0f]); - perspective.setUniform!(3, "f")(translation, [0.0f, 0.0f, -2.5f]); - - // Vertex specification - Vertex[] vertices = [{ - position: [0, 1, 0], - color : [1, 0, 0, 1] - }, { - position: [1, -1, 0], - color : [0, 1, 0, 1] - }, { - position: [-1, -1, 0], - color : [0, 0, 1, 1] - }]; - foreach(ref v; vertices) - v.position[] = normalize(v.position[]); - - auto gpuVertices = new GpuArray( - vertices, - cast(uint) vertices.length, - Vertex.formats); - - // Translation - float[] translationVector = [0.0f, 0.0f, -2.5f]; - - // Rotation stuff - immutable dr = Quaternion!float.getRotation([1, 3, 7], 0.01); - auto rotationQuaternion = cast(Quaternion!float) dr; - - immutable delta = 0.1; - auto scancode = SDL_SCANCODE_W; - float[][SDL_Scancode] movements = - [ - SDL_SCANCODE_W: [0, 0, -delta], - SDL_SCANCODE_S: [0, 0, +delta], - SDL_SCANCODE_D: [+delta, 0, 0], - SDL_SCANCODE_A: [-delta, 0, 0], - SDL_SCANCODE_E: [0, +delta, 0], - SDL_SCANCODE_Q: [0, -delta, 0] - ]; - while (window.isOpen()) - { - // general processing - rotationQuaternion = rotationQuaternion * dr; - - ubyte* key = SDL_GetKeyboardState(null); - foreach(SDL_Scancode code, float[] movement; movements) - if(key[code]) - translationVector[] += movement[]; - - // pre-rendering operations - perspective.setUniformMatrix(rotation, rotationQuaternion.rotationMatrix()); - perspective.setUniform!(3, "f")(translation, translationVector); - - // rendering - window.clear(); - perspective.use(); - render(gpuVertices); - window.print(); - - // event processing - SDL_Event event; - while (SDL_PollEvent(&event)) - { - switch (event.type) - { - case SDL_QUIT: - window.close(); - break; - - default: - break; - } - } - } -} diff --git a/source/vertex.d b/source/vertex.d deleted file mode 100644 index e14943f..0000000 --- a/source/vertex.d +++ /dev/null @@ -1,106 +0,0 @@ -module viare.vertex; - -import std.conv; -import std.string; - -import derelict.opengl; - -import daque.graphics.opengl; - -alias Vertex = Vert!"3f.0:position 4fn1:color"; - -// 3f.0:position 4fn1:color -struct MemberInfo -{ - string type; - string identifier; - - string index; - string size; - string glType; - string normalized; -} - -MemberInfo getInfo(string memberString) pure nothrow -{ - string[] parts = split(memberString, ":"); - string first = parts[0]; - string second = parts[1]; - - string type = (first[1] == 'f')? "float" : "float"; - string size = first[0 .. 1]; - - MemberInfo info; - info.type = type ~ "[" ~ size ~ "]"; - info.identifier = second; - info.index = memberString[3 .. 4]; - info.size = size; - info.glType = (type == "float")? "GL_FLOAT" : "GL_FLOAT"; - info.normalized = (memberString[2] == 'n')? "GL_TRUE" : "GL_FALSE"; - return info; -} -MemberInfo[] getInfos(string membersString) pure nothrow -{ - string[] memberString = split(membersString, " "); - MemberInfo[] infos; - foreach(str; memberString) - { - infos ~= getInfo(str); - } - return infos; -} - -string attrFormatString(MemberInfo info) -{ - return "{ index: " ~ info.index ~ - ", size: " ~ info.size ~ - ", type: " ~ info.glType ~ - ", normalized: " ~ info.normalized ~ - ", stride: this.sizeof" ~ - ", pointer: cast(void*) this." ~ info.identifier ~ ".offsetof}"; -} - -string attrFormatStrings(MemberInfo[] infos) -{ - string str = "["; - foreach(uint i, MemberInfo info; infos) - { - str ~= attrFormatString(info); - if(i + 1 < infos.length) - str ~= ", "; - } - str ~= "]"; - return str; -} - -string declaration(MemberInfo info) -{ - return info.type ~ " " ~ info.identifier ~ ";"; -} - -string formStruct(string membersString) -{ - string structString; - auto infos = getInfos(membersString); - foreach(info; infos) - structString ~= declaration(info); - structString ~= "static AttributeFormat[] formats = " ~ attrFormatStrings(infos) ~ ";"; - return structString; -} - -template Vert(string membersString) -{ - struct Vert - { - mixin(formStruct(membersString)); - } -} - -unittest -{ - import std.stdio: writeln; - Vert!"2fn0:position 4fn1:color" vert; - vert.position[] = [3, 4]; - writeln(vert); -} - From f545fa90373c530ab39c76f5900590826eb5bceb Mon Sep 17 00:00:00 2001 From: Miguel Date: Tue, 16 Oct 2018 11:27:24 -0500 Subject: [PATCH 29/32] Change to numbered libdaque version --- dub.json | 2 +- dub.selections.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dub.json b/dub.json index 74a8abf..e8bdfc4 100644 --- a/dub.json +++ b/dub.json @@ -11,6 +11,6 @@ "dependencies": { "derelict-sdl2": "~>3.0.0-beta", "derelict-gl3": "~>2.0.0-beta", - "libdaque": "~develop" + "libdaque": "~>0.3.1-develop" } } diff --git a/dub.selections.json b/dub.selections.json index dc6cce7..0994db9 100644 --- a/dub.selections.json +++ b/dub.selections.json @@ -1,9 +1,9 @@ { "fileVersion": 1, "versions": { - "derelict-gl3": "2.0.0-beta.6", + "derelict-gl3": "2.0.0-beta.7", "derelict-sdl2": "3.0.0-beta.7", "derelict-util": "3.0.0-beta.2", - "libdaque": "~develop" + "libdaque": "0.3.1-develop" } } From 85c109051addbe11851eb1e6307b889e51e603a3 Mon Sep 17 00:00:00 2001 From: Miguel Date: Tue, 16 Oct 2018 11:48:31 -0500 Subject: [PATCH 30/32] Define current coding standard followed --- coding-style.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 coding-style.md diff --git a/coding-style.md b/coding-style.md new file mode 100644 index 0000000..231d7cb --- /dev/null +++ b/coding-style.md @@ -0,0 +1 @@ +currently using Daque's coding-standard **v1.0**. From 4e2eab0b53dfac47e5ef8e50b523f78f3874ef10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Omar=20Flores=20Ch=C3=A1vez?= Date: Tue, 16 Oct 2018 14:10:52 -0500 Subject: [PATCH 31/32] Remove REFERENCES.md As discussed in private chat, it's better to have a dedicated repository to references, to handle our content curation in a more organized way. --- REFERENCES.md | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 REFERENCES.md diff --git a/REFERENCES.md b/REFERENCES.md deleted file mode 100644 index 457bdd4..0000000 --- a/REFERENCES.md +++ /dev/null @@ -1,29 +0,0 @@ -# References that got ViaRE to be born in our brains - -## Antrpology and History - -Harari, Y. N. (2014). *Sapiens: A brief history of humankind.* London: Vintage Books. - -Bryson, B. (2003). *A Short History of Nearly Everything.* London: Black Swan Books. - -## Geology - -Huggett, R. J. (2017). *Fundamentals of geomorphology.* London: Routledge. - -Wilson, J. P., & Gallant, J. C. (2000). *Terrain analysis: Principles and applications*. New York: Wiley. - -## Urban... - -### Transport - -Rodrigue, J., Comtois, C., & Slack, B. (2013). *The geography of transport systems.* New York: Routledge. - -### Design & planning - -McLaren, D., & Agyeman, J. (2017). *Sharing cities: A case for truly smart and sustainable cities.* Cambridge: MIT Press. - -Troy, P. N. (2004). *The structure and form of the Australian city: Prospects for improved urban planning.* Brisbane: Urban Policy Program, Griffith University. - -### Growth - -Reissman, L. (1964). *The urban process: Cities in industrial societies.* New York: Free Press of Glencoe. \ No newline at end of file From 914b1b8044b2e588246803a4dc8df70ee2ddb5ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Omar=20Flores=20Ch=C3=A1vez?= Date: Thu, 18 Oct 2018 10:38:43 -0500 Subject: [PATCH 32/32] Delete coding-style.md --- coding-style.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 coding-style.md diff --git a/coding-style.md b/coding-style.md deleted file mode 100644 index 231d7cb..0000000 --- a/coding-style.md +++ /dev/null @@ -1 +0,0 @@ -currently using Daque's coding-standard **v1.0**.