[update] Implemented drawing cubes in TitleScene.
This commit is contained in:
parent
0f17719b79
commit
957f9724db
@ -113,7 +113,7 @@ class CubeProgram {
|
|||||||
};
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
enum MaxInstanceCount = 10;
|
enum MaxInstanceCount = 256;
|
||||||
|
|
||||||
///
|
///
|
||||||
this() {
|
this() {
|
||||||
|
@ -31,7 +31,7 @@ class LobbyWorld {
|
|||||||
gl.Enable(GL_DEPTH_TEST);
|
gl.Enable(GL_DEPTH_TEST);
|
||||||
gl.DepthMask(true);
|
gl.DepthMask(true);
|
||||||
cube_program_.Draw(
|
cube_program_.Draw(
|
||||||
cubes.map!"a.Create()",
|
CreateCubes(cube_matrix.Create(), cube_interval)[],
|
||||||
Projection, view.Create(), light_pos, cube_material);
|
Projection, view.Create(), light_pos, cube_material);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,16 +40,41 @@ class LobbyWorld {
|
|||||||
return background_;
|
return background_;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
|
||||||
ModelMatrixFactory!4[] cubes;
|
|
||||||
///
|
///
|
||||||
ViewMatrixFactory view;
|
ViewMatrixFactory view;
|
||||||
///
|
///
|
||||||
vec3 light_pos = vec3(0, 10, 0);
|
vec3 light_pos = vec3(0, 10, 0);
|
||||||
///
|
///
|
||||||
CubeProgram.Material cube_material;
|
CubeProgram.Material cube_material;
|
||||||
|
///
|
||||||
|
ModelMatrixFactory!4 cube_matrix;
|
||||||
|
///
|
||||||
|
float cube_interval = 0.005;
|
||||||
|
|
||||||
private:
|
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_;
|
Background background_;
|
||||||
|
|
||||||
CubeProgram cube_program_;
|
CubeProgram cube_program_;
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
/// License: MIT
|
/// License: MIT
|
||||||
module sj.TitleScene;
|
module sj.TitleScene;
|
||||||
|
|
||||||
|
import std.math;
|
||||||
|
|
||||||
|
import gl4d;
|
||||||
|
|
||||||
import sj.AbstractScene,
|
import sj.AbstractScene,
|
||||||
sj.KeyInput,
|
sj.KeyInput,
|
||||||
sj.LobbyWorld,
|
sj.LobbyWorld,
|
||||||
@ -12,11 +16,7 @@ class TitleScene : AbstractScene {
|
|||||||
///
|
///
|
||||||
this(LobbyWorld lobby) {
|
this(LobbyWorld lobby) {
|
||||||
lobby_ = lobby;
|
lobby_ = lobby;
|
||||||
|
SetupLobby(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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -25,12 +25,28 @@ class TitleScene : AbstractScene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override void Update(KeyInput input) {
|
override void Update(KeyInput input) {
|
||||||
|
lobby_.cube_matrix.rotation += vec3(PI/300, PI/300, PI/300);
|
||||||
}
|
}
|
||||||
override void Draw() {
|
override void Draw() {
|
||||||
lobby_.Draw();
|
lobby_.Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
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_;
|
SceneInterface next_scene_;
|
||||||
|
|
||||||
LobbyWorld lobby_;
|
LobbyWorld lobby_;
|
||||||
|
Reference in New Issue
Block a user