[update] Implemented drawing cubes in TitleScene.

This commit is contained in:
falsycat 2019-10-12 00:00:00 +00:00
parent 0f17719b79
commit 957f9724db
3 changed files with 50 additions and 9 deletions

View File

@ -113,7 +113,7 @@ class CubeProgram {
};
///
enum MaxInstanceCount = 10;
enum MaxInstanceCount = 256;
///
this() {

View File

@ -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_;

View File

@ -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_;