diff --git a/src/sj/CubeProgram.d b/src/sj/CubeProgram.d index 938512d..06faad4 100644 --- a/src/sj/CubeProgram.d +++ b/src/sj/CubeProgram.d @@ -113,7 +113,7 @@ class CubeProgram { }; /// - enum MaxInstanceCount = 10; + enum MaxInstanceCount = 256; /// this() { diff --git a/src/sj/LobbyWorld.d b/src/sj/LobbyWorld.d index d8332d1..09ab8a4 100644 --- a/src/sj/LobbyWorld.d +++ b/src/sj/LobbyWorld.d @@ -31,7 +31,7 @@ class LobbyWorld { gl.Enable(GL_DEPTH_TEST); gl.DepthMask(true); cube_program_.Draw( - cubes.map!"a.Create()", + CreateCubes(cube_matrix.Create(), cube_interval)[], Projection, view.Create(), light_pos, cube_material); } @@ -40,16 +40,41 @@ class LobbyWorld { return background_; } - /// - ModelMatrixFactory!4[] cubes; /// ViewMatrixFactory view; /// vec3 light_pos = vec3(0, 10, 0); /// CubeProgram.Material cube_material; + /// + ModelMatrixFactory!4 cube_matrix; + /// + float cube_interval = 0.005; private: + static mat4[8] CreateCubes(mat4 model, float interval) { + mat4[8] cubes; + + enum sz = 0.05; + const si = sz + interval; + + auto m = mat4.identity; + m.scale(sz, sz, sz); + cubes[] = m; + + cubes[0].translate( si, si, si); + cubes[1].translate(-si, si, si); + cubes[2].translate( si, -si, si); + cubes[3].translate(-si, -si, si); + cubes[4].translate( si, si, -si); + cubes[5].translate(-si, si, -si); + cubes[6].translate( si, -si, -si); + cubes[7].translate(-si, -si, -si); + + cubes[].each!((ref x) => x = model * x); + return cubes; + } + Background background_; CubeProgram cube_program_; diff --git a/src/sj/TitleScene.d b/src/sj/TitleScene.d index b3c8c45..675a24d 100644 --- a/src/sj/TitleScene.d +++ b/src/sj/TitleScene.d @@ -1,6 +1,10 @@ /// License: MIT module sj.TitleScene; +import std.math; + +import gl4d; + import sj.AbstractScene, sj.KeyInput, sj.LobbyWorld, @@ -12,11 +16,7 @@ class TitleScene : AbstractScene { /// this(LobbyWorld lobby) { lobby_ = lobby; - - // TODO: test - import gl4d; - lobby_.background.outer_color = vec4(0.8, 0.8, 0.8, 1); - lobby_.background.inner_color = vec4(1, 1, 1, 1); + SetupLobby(lobby); } /// @@ -25,12 +25,28 @@ class TitleScene : AbstractScene { } override void Update(KeyInput input) { + lobby_.cube_matrix.rotation += vec3(PI/300, PI/300, PI/300); } override void Draw() { lobby_.Draw(); } private: + static void SetupLobby(LobbyWorld lobby) { + lobby.view.pos = vec3(0, 0, -1); + lobby.view.target = vec3(0, -0.2, 0); + + lobby.background.inner_color = vec4(0.9, 0.9, 0.9, 1); + lobby.background.outer_color = vec4(0.2, 0.2, 0.2, 1); + + lobby.light_pos = vec3(0, 10, 0); + lobby.cube_material.diffuse_color = vec3(0.1, 0.1, 0.1); + lobby.cube_material.light_color = vec3(1, 0.8, 0.8); + lobby.cube_material.light_power = vec3(100, 100, 100); + lobby.cube_material.ambient_color = vec3(0.1, 0.1, 0.1); + lobby.cube_material.specular_color = vec3(0.5, 0.2, 0.2); + } + SceneInterface next_scene_; LobbyWorld lobby_;