diff --git a/examples/dminer/src/dminer/core/terrain.d b/examples/dminer/src/dminer/core/terrain.d index 2310200d..8b3a77d2 100644 --- a/examples/dminer/src/dminer/core/terrain.d +++ b/examples/dminer/src/dminer/core/terrain.d @@ -117,6 +117,17 @@ struct TerrainGen { return 0; return data[(y << ypow) + y + x]; } + int getHeightDiff(int x, int y) { + import std.algorithm; + int h0 = get(x, y); + int h1 = get(x+1, y)-h0; + int h2 = get(x-1, y)-h0; + int h3 = get(x, y+1)-h0; + int h4 = get(x, y-1)-h0; + int mindh = min(h1, h2, h3, h4); + int maxdh = max(h1, h2, h3, h4); + return max(-mindh, maxdh); + } void set(int x, int y, int value) { if (x < 0 || y < 0 || x >= dx || y >= dy) return; diff --git a/examples/dminer/src/dminer/core/world.d b/examples/dminer/src/dminer/core/world.d index 7a3c82db..0acf5256 100644 --- a/examples/dminer/src/dminer/core/world.d +++ b/examples/dminer/src/dminer/core/world.d @@ -424,18 +424,18 @@ static short[] TERRAIN_INIT_DATA = [ // V 10, 10, 10, 10, 30, 30, 30, 30, 30, 30, 30, 30, 10, 10, 10, 10, 10, 10, 10, 20, 50, 50, 50, 50, 50, 50, 50, 50, 50, 20, 20, 20, 20, 10, - 10, 20, 20, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 20, 20, 10, - 10, 20, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 20, 10, - 10, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 20, 30, + 10, 20, 20, 50, 50, 50, 50, 50, 50, 50, 250, 50, 50, 50, 20, 20, 10, + 10, 20, 50, 50, 50, 50, 50, 150, 50, 50, 50, 50, 50, 50, 50, 20, 10, + 10, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 150, 50, 20, 30, 30, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 30, - 30, 50, 50, 50, 50, 50, 50, 50, 120, 50, 50, 50, 50, 50, 50, 50, 30, - 30, 50, 50, 50, 50, 50, 50, 110, 140, 130, 50, 50, 50, 50, 50, 50, 30, - 30, 50, 50, 50, 50, 50, 50, 140, 150, 140, 50, 50, 50, 50, 50, 50, 30, // <== - 30, 50, 50, 50, 50, 50, 50, 110, 140, 120, 50, 50, 50, 50, 50, 50, 30, - 30, 50, 50, 50, 50, 50, 50, 50, 110, 50, 50, 50, 50, 50, 50, 50, 30, - 30, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 10, - 30, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 10, - 30, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 40, 50, 10, + 30, 50, 50, 50, 50, 50, 50, 50, 120, 50, 50, 50, 80, 50, 250, 50, 30, + 30, 50, 50, 50, 50, 50, 50, 110, 80, 130, 50, 50, 50, 50, 50, 50, 30, + 30, 50, 50, 50, 50, 50, 150, 100, 50, 140, 50, 50, 50, 50, 50, 50, 30, // <== + 30, 50, 50, 50, 50, 50, 50, 110, 40, 120, 50, 90, 50, 50, 50, 50, 30, + 30, 50, 50, 50, 50, 150, 50, 50, 110, 50, 50, 50, 50, 50, 50, 50, 30, + 30, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 150, 50, 50, 50, 10, + 30, 50, 50, 50, 50, 50, 80, 50, 50, 50, 50, 50, 50, 50, 50, 50, 10, + 30, 50, 50, 80, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 40, 50, 10, 30, 20, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 40, 20, 20, 10, 30, 20, 20, 50, 50, 50, 50, 50, 50, 50, 40, 20, 20, 20, 20, 20, 10, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 10, 10, 10, 10, 10, @@ -446,19 +446,19 @@ static short[] TERRAIN_SCALE_DATA = [ // V 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 30, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 45, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 80, 20, 20, 20, 40, 50, 40, 20, 20, + 20, 20, 20, 20, 120, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 40, 60, 50, 20, 20, 30, 20, 20, 20, + 20, 20, 120, 20, 20, 20, 20, 20, 20, 50, 20, 20, 20, 45, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 80, 20, 50, 20, 40, 50, 40, 20, 20, 20, 20, 20, 20, 20, 20, 90, 20, 80, 20, 30, 20, 20, 30, 20, 20, 20, 20, 20, 20, 20, 20, 90, 20, 80, 30, 20, 40, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 90, 30, 40, 30, 50, 20, 20, 20, 20, 20, 20, // <== + 20, 20, 20, 20, 20, 20, 90, 30, 20, 30, 50, 120, 20, 20, 20, 20, 20, // <== 20, 20, 20, 20, 20, 20, 50, 20, 30, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 40, 70, 40, 90, 20, 40, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 80, 20, 50, 70, 50, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 60, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 120, 20, 20, 20, 20, 20, 20, 20, 20, 20, 120, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, // ^ @@ -482,9 +482,12 @@ void initWorldTerrain(World world, int terrSizeBits = 10, int x0 = 0, int z0 = 0 int cellx = x0 + x - terrSize / 2; int cellz = z0 + z - terrSize / 2; int h = terr.get(x, z); - //cell_t cell = BlockId.bedrock; + int dh = terr.getHeightDiff(x, z); + + + cell_t cell = BlockId.bedrock; //cell_t cell = BlockId.grass; - cell_t cell = BlockId.face_test; + //cell_t cell = BlockId.face_test; //if (h < CHUNK_DY / 10) // cell = 100; //else if (h < CHUNK_DY / 5) @@ -497,9 +500,15 @@ void initWorldTerrain(World world, int terrSizeBits = 10, int x0 = 0, int z0 = 0 // cell = 104; //else // cell = 105; + + cell_t topcell = BlockId.bedrock; + if (dh <= 1) + topcell = BlockId.grass; + for (int y = 0; y < h; y++) { world.setCell(cellx, y, cellz, cell); } + world.setCell(cellx, h, cellz, topcell); } } } diff --git a/examples/dminer/src/minermain.d b/examples/dminer/src/minermain.d index 92245b52..ed917965 100644 --- a/examples/dminer/src/minermain.d +++ b/examples/dminer/src/minermain.d @@ -146,6 +146,64 @@ class UiWidget : VerticalLayout, CellVisitor { focusable = true; } + /// process key event, return true if event is processed. + override bool onMouseEvent(MouseEvent event) { + if (event.action == MouseAction.ButtonDown) { + if (event.button == MouseButton.Left) { + int x = event.x; + int y = event.y; + int xindex = 0; + if (x > width * 2 / 3) + xindex = 2; + else if (x > width * 1 / 3) + xindex = 1; + int yindex = 0; + if (y > height * 2 / 3) + yindex = 2; + else if (y > height * 1 / 3) + yindex = 1; + int index = yindex * 3 + xindex; + /* + index: + 0 1 2 + 3 4 5 + 6 7 8 + */ + switch(index) { + default: + case 1: + case 4: + _world.camPosition.forward(1); + updateCamPosition(); + break; + case 0: + case 3: + _world.camPosition.turnLeft(); + updateCamPosition(); + break; + case 2: + case 5: + _world.camPosition.turnRight(); + updateCamPosition(); + break; + case 7: + _world.camPosition.backward(1); + updateCamPosition(); + break; + case 6: + _world.camPosition.moveLeft(); + updateCamPosition(); + break; + case 8: + _world.camPosition.moveRight(); + updateCamPosition(); + break; + } + } + } + return true; + } + /// process key event, return true if event is processed. override bool onKeyEvent(KeyEvent event) { if (event.action == KeyAction.KeyDown) { @@ -341,33 +399,13 @@ class UiWidget : VerticalLayout, CellVisitor { /// this is OpenGLDrawableDelegate implementation private void doDraw(Rect windowRect, Rect rc) { _cam.setPerspective(rc.width, rc.height, 45.0f, 0.1, 100); - //_cam.translate(vec3( - // childById!ScrollBar("sbTranslationX").position / 10.0f, - // childById!ScrollBar("sbTranslationY").position / 10.0f, - // childById!ScrollBar("sbTranslationZ").position / 10.0f)); - //_world.camPosition.pos.x; _cam.setIdentity(); _cam.translate(_animatingPosition); _cam.rotateY(_animatingAngle); - //_cam.rotateX(-15); - //_cam.lookAt(vec3(dir.x, dir.y, dir.z), vec3(pos.x, pos.y, pos.z), vec3(0,1,0)); - //_cam.translateX(_world.camPosition.pos.x); - //_cam.translateY(_world.camPosition.pos.y); - //_cam.translateZ(_world.camPosition.pos.z); + dirLightNode.setIdentity(); dirLightNode.translate(_animatingPosition); dirLightNode.rotateY(_animatingAngle); - //dirLightNode.setIdentity(); - //dirLightNode.translateX(_world.camPosition.pos.x); - //dirLightNode.translateY(_world.camPosition.pos.y); - //dirLightNode.translateZ(_world.camPosition.pos.z); - //_cam.rotateX(rotationX); - //_cam.rotateY(rotationY); - //_cam.rotateZ(rotationZ); - //_cam.translate(vec3(-1, -1.5, -1)); // - angle/1000 - //_cam.translate(vec3(0, 0, -1.1)); // - angle/1000 - //_cam.translate(vec3(0, 3, - angle/1000)); // - //_cam.rotateZ(30.0f + angle * 0.3456778); checkgl!glEnable(GL_CULL_FACE); //checkgl!glDisable(GL_CULL_FACE);