Renamed desktop count from one.
This commit is contained in:
parent
89ae253bc2
commit
1298b18b9e
|
@ -88,12 +88,12 @@ public enum BaseGlyphSet implements DefaultEnumSetᴶᴹˣ<BaseGlyphSet,BãßBȍ
|
|||
*/
|
||||
/* TODO: Egyptian hieroglyphs should be mapped 0x13000 to 0x1342E but for now on 0xE000 to 0xE42E (BMP) */
|
||||
HIERO(
|
||||
new BaseGlyphSetNumber("\ue429","\ue3fa","\ue3fb","\ue3fc","\ue3fd","\ue3fe","\ue3ff","\ue400","\ue401","\ue401"),
|
||||
new BaseGlyphSetNumber("\ue254","\ue255","\ue256","\ue257","\ue258","\ue259","\ue25a","\ue25b","\ue25c","\ue25d","\ue25e","\ue25f","\ue260","\ue261","\ue262","\ue263"),
|
||||
new BaseGlyphSetNumber("\ue429","\ue3fa","\ue3fb","\ue3fc","\ue3fd","\ue3fe","\ue3ff","\ue400","\ue401","\ue401").withSeperator(BãßBȍőnConstantsʸᴰ.STR_SPACE),
|
||||
new BaseGlyphSetNumber("\ue254","\ue255","\ue256","\ue257","\ue258","\ue259","\ue25a","\ue25b","\ue25c","\ue25d","\ue25e","\ue25f","\ue260","\ue261","\ue262","\ue263").withSeperator(BãßBȍőnConstantsʸᴰ.STR_SPACE),
|
||||
new BaseGlyphSetNumber(
|
||||
"\ue3fa","\ue3fb","\ue3fc","\ue3fd","\ue3fe","\ue3ff","\ue400","\ue401","\ue401",
|
||||
"\ue386","\ue387","\ue388","\ue389","\ue38a","\ue38b","\ue38c","\ue38d","\ue38e",
|
||||
"\ue362","\ue363","\ue364","\ue365","\ue366","\ue367","\ue368","\ue369","\ue36a")
|
||||
"\ue362","\ue363","\ue364","\ue365","\ue366","\ue367","\ue368","\ue369","\ue36a").withSeperator(BãßBȍőnConstantsʸᴰ.STR_SPACE)
|
||||
),
|
||||
RUNIC(
|
||||
new BaseGlyphSetNumber("ᛰ","ᚠ","ᚢ","ᚦ","ᚬ","ᚱ","ᚴ","ᚼ","ᚾ","ᛁ"),
|
||||
|
|
|
@ -32,10 +32,10 @@ import love.distributedrebirth.gdxapp.desktop.apps.Unicode4DApp;
|
|||
import love.distributedrebirth.gdxapp.music.MusicManager;
|
||||
import love.distributedrebirth.gdxapp.music.MusicSongType;
|
||||
import love.distributedrebirth.gdxapp.screen.ScreenCredits;
|
||||
import love.distributedrebirth.gdxapp.screen.ScreenDesktop0;
|
||||
import love.distributedrebirth.gdxapp.screen.ScreenDesktop1;
|
||||
import love.distributedrebirth.gdxapp.screen.ScreenDesktop2;
|
||||
import love.distributedrebirth.gdxapp.screen.ScreenDesktop3;
|
||||
import love.distributedrebirth.gdxapp.screen.ScreenDesktop4;
|
||||
import love.distributedrebirth.gdxapp.screen.ScreenHelp;
|
||||
import love.distributedrebirth.gdxapp.screen.ScreenIntro;
|
||||
import love.distributedrebirth.gdxapp.screen.ScreenIntroMission;
|
||||
|
@ -65,10 +65,10 @@ public class GDXAppMain extends Game {
|
|||
|
||||
private Map<Class<? extends Screen>,Screen> screens;
|
||||
private List<GDXAppLauncher> apps;
|
||||
private GDXAppScreen desktop0;
|
||||
private GDXAppScreen desktop1;
|
||||
private GDXAppScreen desktop2;
|
||||
private GDXAppScreen desktop3;
|
||||
private GDXAppScreen desktop4;
|
||||
private ImBoolean openWindowFlag = new ImBoolean(true);
|
||||
private ImBoolean showImGuiDemo = new ImBoolean(false);
|
||||
|
||||
|
@ -130,7 +130,7 @@ public class GDXAppMain extends Game {
|
|||
}
|
||||
if (args.contains("intro-skip")) {
|
||||
System.out.println("intro-skip: requested");
|
||||
selectScreen(ScreenDesktop0.class);
|
||||
selectScreen(ScreenDesktop1.class);
|
||||
music.play(MusicSongType.BACKGROUND);
|
||||
} else {
|
||||
selectScreen(ScreenIntro.class);
|
||||
|
@ -163,18 +163,18 @@ public class GDXAppMain extends Game {
|
|||
apps.add(new GDXAppLauncher("Unicode4D", () -> new Unicode4DApp()));
|
||||
apps.add(new GDXAppLauncher("Music Player", () -> new MusicPlayerApp(this)));
|
||||
|
||||
desktop0 = new ScreenDesktop0(this);
|
||||
desktop1 = new ScreenDesktop1(this);
|
||||
desktop2 = new ScreenDesktop2();
|
||||
desktop2 = new ScreenDesktop2(this);
|
||||
desktop3 = new ScreenDesktop3();
|
||||
desktop4 = new ScreenDesktop4();
|
||||
|
||||
putScreen(new ScreenLoading(this));
|
||||
putScreen(new ScreenIntro(this));
|
||||
putScreen(new ScreenIntroMission(this));
|
||||
putScreen(desktop0);
|
||||
putScreen(desktop1);
|
||||
putScreen(desktop2);
|
||||
putScreen(desktop3);
|
||||
putScreen(desktop4);
|
||||
putScreen(new ScreenCredits(this));
|
||||
putScreen(new ScreenHelp(this));
|
||||
|
||||
|
@ -312,13 +312,10 @@ public class GDXAppMain extends Game {
|
|||
}
|
||||
ImGui.separator();
|
||||
|
||||
String infix0 = "";
|
||||
String infix1 = "";
|
||||
String infix2 = "";
|
||||
String infix3 = "";
|
||||
if (appScreen instanceof ScreenDesktop0) {
|
||||
infix0 = "=> ";
|
||||
}
|
||||
String infix4 = "";
|
||||
if (appScreen instanceof ScreenDesktop1) {
|
||||
infix1 = "=> ";
|
||||
}
|
||||
|
@ -328,18 +325,8 @@ public class GDXAppMain extends Game {
|
|||
if (appScreen instanceof ScreenDesktop3) {
|
||||
infix3 = "=> ";
|
||||
}
|
||||
if (ImGui.beginMenu(infix0+"Desktop0")) {
|
||||
if (ImGui.menuItem("Main reality")) {
|
||||
selectScreen(ScreenDesktop0.class);
|
||||
desktop0.getDeskAppScreen().setCurrentDeskApp(null);
|
||||
}
|
||||
for (DeskApp app: desktop0.getDeskAppScreen().getDeskApps()) {
|
||||
if (ImGui.menuItem(app.getName())) {
|
||||
selectScreen(ScreenDesktop0.class);
|
||||
desktop0.getDeskAppScreen().setCurrentDeskApp(app);
|
||||
}
|
||||
}
|
||||
ImGui.endMenu();
|
||||
if (appScreen instanceof ScreenDesktop4) {
|
||||
infix4 = "=> ";
|
||||
}
|
||||
if (ImGui.beginMenu(infix1+"Desktop1")) {
|
||||
if (ImGui.menuItem("Main reality")) {
|
||||
|
@ -380,6 +367,19 @@ public class GDXAppMain extends Game {
|
|||
}
|
||||
ImGui.endMenu();
|
||||
}
|
||||
if (ImGui.beginMenu(infix4+"Desktop4")) {
|
||||
if (ImGui.menuItem("Main reality")) {
|
||||
selectScreen(ScreenDesktop4.class);
|
||||
desktop4.getDeskAppScreen().setCurrentDeskApp(null);
|
||||
}
|
||||
for (DeskApp app: desktop4.getDeskAppScreen().getDeskApps()) {
|
||||
if (ImGui.menuItem(app.getName())) {
|
||||
selectScreen(ScreenDesktop4.class);
|
||||
desktop4.getDeskAppScreen().setCurrentDeskApp(app);
|
||||
}
|
||||
}
|
||||
ImGui.endMenu();
|
||||
}
|
||||
ImGui.separator();
|
||||
if (Gdx.graphics.isFullscreen()) {
|
||||
if (ImGui.menuItem("Window Mode")) {
|
||||
|
|
|
@ -74,7 +74,7 @@ public class ScreenCredits extends AbstractScrollScreen {
|
|||
|
||||
@Override
|
||||
protected Class<? extends Screen> getNextScreen(GDXAppMain main) {
|
||||
return ScreenDesktop0.class;
|
||||
return ScreenDesktop1.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
package love.distributedrebirth.gdxapp.screen;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.ScreenAdapter;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
|
||||
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
|
||||
import love.distributedrebirth.gdxapp.GDXAppMain;
|
||||
import love.distributedrebirth.gdxapp.GDXAppScreen;
|
||||
import love.distributedrebirth.gdxapp.desktop.DeskAppScreen;
|
||||
|
||||
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
|
||||
public class ScreenDesktop0 extends ScreenAdapter implements GDXAppScreen {
|
||||
private final GDXAppMain main;
|
||||
private DeskAppScreen deskAppScreen;
|
||||
private Texture backgroundImage;
|
||||
|
||||
public ScreenDesktop0(final GDXAppMain main) {
|
||||
this.main = main;
|
||||
deskAppScreen = new DeskAppScreen("Desktop0");
|
||||
backgroundImage = new Texture(Gdx.files.internal("background/terrydavis-front.png"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
main.batch.begin();
|
||||
main.batch.draw(backgroundImage, 0, 0, main.viewWidth, main.viewHeight);
|
||||
main.batch.end();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
backgroundImage.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeskAppScreen getDeskAppScreen() {
|
||||
return deskAppScreen;
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@ public class ScreenDesktop1 extends ScreenAdapter implements GDXAppScreen {
|
|||
public ScreenDesktop1(final GDXAppMain main) {
|
||||
this.main = main;
|
||||
deskAppScreen = new DeskAppScreen("Desktop1");
|
||||
backgroundImage = new Texture(Gdx.files.internal("background/terrydavis-nose.png"));
|
||||
backgroundImage = new Texture(Gdx.files.internal("background/terrydavis-front.png"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,30 +1,40 @@
|
|||
package love.distributedrebirth.gdxapp.screen;
|
||||
|
||||
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
|
||||
import com.badlogic.gdx.graphics.g3d.Material;
|
||||
import com.badlogic.gdx.graphics.g3d.Model;
|
||||
import com.badlogic.gdx.graphics.g3d.ModelInstance;
|
||||
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
|
||||
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.ScreenAdapter;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
|
||||
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
|
||||
import love.distributedrebirth.gdxapp.GDXAppMain;
|
||||
import love.distributedrebirth.gdxapp.GDXAppScreen;
|
||||
import love.distributedrebirth.gdxapp.desktop.DeskAppScreen;
|
||||
|
||||
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
|
||||
public class ScreenDesktop2 extends AbstractScreenDesktop {
|
||||
private Model grid;
|
||||
public class ScreenDesktop2 extends ScreenAdapter implements GDXAppScreen {
|
||||
private final GDXAppMain main;
|
||||
private DeskAppScreen deskAppScreen;
|
||||
private Texture backgroundImage;
|
||||
|
||||
public ScreenDesktop2() {
|
||||
super("Desktop2");
|
||||
}
|
||||
|
||||
protected void createModel(ModelBuilder modelBuilder, Array<ModelInstance> modelInstances) {
|
||||
grid = modelBuilder.createLineGrid(33, 33, 1f, 1f, new Material(ColorAttribute.createDiffuse(1f,1f,1f,.1f)), Usage.Position | Usage.Normal);
|
||||
modelInstances.add(new ModelInstance(grid, 0, 0, 0));
|
||||
public ScreenDesktop2(final GDXAppMain main) {
|
||||
this.main = main;
|
||||
deskAppScreen = new DeskAppScreen("Desktop2");
|
||||
backgroundImage = new Texture(Gdx.files.internal("background/terrydavis-nose.png"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void disposeDesktop() {
|
||||
grid.dispose();
|
||||
public void render(float delta) {
|
||||
main.batch.begin();
|
||||
main.batch.draw(backgroundImage, 0, 0, main.viewWidth, main.viewHeight);
|
||||
main.batch.end();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
backgroundImage.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeskAppScreen getDeskAppScreen() {
|
||||
return deskAppScreen;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,58 +1,24 @@
|
|||
package love.distributedrebirth.gdxapp.screen;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.PerspectiveCamera;
|
||||
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFontCache;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g3d.Material;
|
||||
import com.badlogic.gdx.graphics.g3d.Model;
|
||||
import com.badlogic.gdx.graphics.g3d.ModelBatch;
|
||||
import com.badlogic.gdx.graphics.g3d.ModelInstance;
|
||||
import com.badlogic.gdx.graphics.g3d.Shader;
|
||||
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
|
||||
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
|
||||
import com.badlogic.gdx.math.Matrix4;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.viewport.ScreenViewport;
|
||||
|
||||
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
|
||||
|
||||
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
|
||||
public class ScreenDesktop3 extends AbstractScreenDesktop {
|
||||
private final Shader shader;
|
||||
private final BitmapFont font;
|
||||
private final BitmapFontCache fontCache;
|
||||
private final ScreenViewport uiViewport = new ScreenViewport();
|
||||
private final SpriteBatch spriteBatch;
|
||||
private final Vector3 textPosition = new Vector3(6.5f, 10.5f, 5.5f);
|
||||
private Model grid;
|
||||
private Model model;
|
||||
private float colorDeltaTime = 0f;
|
||||
private float colorFade = 0f;
|
||||
private boolean colorPositive = true;
|
||||
|
||||
public ScreenDesktop3() {
|
||||
super("Desktop3");
|
||||
shader = new UserColorShader();
|
||||
shader.init();
|
||||
font = new BitmapFont();
|
||||
fontCache = new BitmapFontCache(font, false);
|
||||
spriteBatch = new SpriteBatch();
|
||||
}
|
||||
|
||||
protected void createModel(ModelBuilder modelBuilder, Array<ModelInstance> modelInstances) {
|
||||
model = modelBuilder.createBox(.3f, .3f, .3f,new Material(ColorAttribute.createDiffuse(.1f,.1f,.1f,0f)), Usage.Position | Usage.Normal);
|
||||
for (int x = -4; x < 6; x++) {
|
||||
for (int y = 1; y < 11; y++) {
|
||||
for (int z = -4; z < 7; z++) {
|
||||
modelInstances.add(new ModelInstance(model, x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
grid = modelBuilder.createLineGrid(33, 33, 1f, 1f, new Material(ColorAttribute.createDiffuse(1f,1f,1f,.1f)), Usage.Position | Usage.Normal);
|
||||
modelInstances.add(new ModelInstance(grid, 0, 0, 0));
|
||||
}
|
||||
|
@ -60,110 +26,5 @@ public class ScreenDesktop3 extends AbstractScreenDesktop {
|
|||
@Override
|
||||
protected void disposeDesktop() {
|
||||
grid.dispose();
|
||||
model.dispose();
|
||||
}
|
||||
|
||||
protected void renderDesktop(float delta, ModelBatch modelBatch, PerspectiveCamera cam, Array<ModelInstance> modelInstances) {
|
||||
colorFade(delta, modelInstances);
|
||||
|
||||
modelBatch.begin(cam);
|
||||
for (ModelInstance instance : modelInstances) {
|
||||
modelBatch.render(instance, shader);
|
||||
}
|
||||
modelBatch.end();
|
||||
|
||||
// Multiply vector with world-space position with 3D projection-view matrix
|
||||
final Vector3 clipSpacePos = new Vector3(textPosition);
|
||||
final float w = multiplyProjective(cam.combined, clipSpacePos, 1f);
|
||||
|
||||
// Do not render the text if it is behind the camera or too far away
|
||||
if (clipSpacePos.z >= -1f && clipSpacePos.z <= 1f) {
|
||||
// Calculate the position on screen (clip space is [-1,1], we need [-size/2, size/2], but this depends on your viewport)
|
||||
final float textPosX = clipSpacePos.x * Gdx.graphics.getWidth() * 0.5f;
|
||||
final float textPosY = clipSpacePos.y * Gdx.graphics.getHeight() * 0.5f;
|
||||
|
||||
// Set the text normally. The position must be 0, otherwise the scaling won't work.
|
||||
// If you don't want perspective scaling, you can set x,y to textPosX,textPosY directly and skip the next part.
|
||||
fontCache.setText("Now in 3D", 0f, 0, 0f, Align.center, false);
|
||||
|
||||
// Size of the text in the world
|
||||
final float fontSize = 5f;
|
||||
// Scaling factor
|
||||
final float fontScale = fontSize / w;
|
||||
// Go through prepared vertices of the font cache and do necessary transformation
|
||||
final int regionCount = font.getRegions().size;
|
||||
for (int page = 0; page < regionCount; page++) {
|
||||
final int vertexCount = fontCache.getVertexCount(page);
|
||||
final float[] vertices = fontCache.getVertices(page);
|
||||
for (int v = 0; v < vertexCount; v += 5) {
|
||||
// This is why the text position must be 0 - otherwise the scaling would move the text
|
||||
vertices[v] = vertices[v] * fontScale + textPosX;
|
||||
vertices[v + 1] = vertices[v + 1] * fontScale + textPosY;
|
||||
}
|
||||
}
|
||||
|
||||
// Standard viewport update
|
||||
uiViewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
|
||||
spriteBatch.setProjectionMatrix(uiViewport.getCamera().projection);
|
||||
// Draw the text normally
|
||||
spriteBatch.begin();
|
||||
fontCache.draw(spriteBatch);
|
||||
spriteBatch.end();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply 4x4 matrix {@code m} and 4D vector {$code (v, vW)} together.
|
||||
* Store result {@code (x/w, y/w, z/w)} back in {@code v} and return {@code w}.
|
||||
*/
|
||||
private static float multiplyProjective(Matrix4 m, Vector3 v, float vW) {
|
||||
final float[] mat = m.val;
|
||||
final float x = v.x * mat[Matrix4.M00] + v.y * mat[Matrix4.M01] + v.z * mat[Matrix4.M02] + vW * mat[Matrix4.M03];
|
||||
final float y = v.x * mat[Matrix4.M10] + v.y * mat[Matrix4.M11] + v.z * mat[Matrix4.M12] + vW * mat[Matrix4.M13];
|
||||
final float z = v.x * mat[Matrix4.M20] + v.y * mat[Matrix4.M21] + v.z * mat[Matrix4.M22] + vW * mat[Matrix4.M23];
|
||||
final float w = v.x * mat[Matrix4.M30] + v.y * mat[Matrix4.M31] + v.z * mat[Matrix4.M32] + vW * mat[Matrix4.M33];
|
||||
final float iw = 1f / w;
|
||||
v.set(x * iw, y * iw, z * iw);
|
||||
return w;
|
||||
}
|
||||
|
||||
private void colorFade(float delta, Array<ModelInstance> modelInstances) {
|
||||
colorDeltaTime += delta;
|
||||
if (colorDeltaTime > 0.04f) {
|
||||
colorDeltaTime = 0f;
|
||||
if (colorPositive) {
|
||||
colorFade += delta;
|
||||
} else {
|
||||
colorFade -= delta;
|
||||
}
|
||||
if (colorFade > 1f) {
|
||||
colorPositive = false;
|
||||
} else if (colorFade < .5f) {
|
||||
colorPositive = true;
|
||||
}
|
||||
}
|
||||
|
||||
int i=0;
|
||||
for (int x = -4; x < 6; x++) {
|
||||
for (int y = 1; y < 11; y++) {
|
||||
for (int z = -4; z < 7; z++) {
|
||||
float red = .1f;
|
||||
float green = (y+2f)/10f*colorFade;
|
||||
float blue = .1f;
|
||||
if (x == 3 || y == 1 || z == -1) {
|
||||
red = (y+2f)/10f*colorFade;
|
||||
green = 0f;
|
||||
}
|
||||
if (x == -1 || y == 10 || z == 5) {
|
||||
green = 0f;
|
||||
blue = (y+2f)/10f*colorFade;
|
||||
}
|
||||
|
||||
ModelInstance instance = modelInstances.get(i++);
|
||||
ColorAttribute attr = ColorAttribute.createDiffuse(red, green, blue, 1f);
|
||||
instance.materials.get(0).set(attr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,169 @@
|
|||
package love.distributedrebirth.gdxapp.screen;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.PerspectiveCamera;
|
||||
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFontCache;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g3d.Material;
|
||||
import com.badlogic.gdx.graphics.g3d.Model;
|
||||
import com.badlogic.gdx.graphics.g3d.ModelBatch;
|
||||
import com.badlogic.gdx.graphics.g3d.ModelInstance;
|
||||
import com.badlogic.gdx.graphics.g3d.Shader;
|
||||
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
|
||||
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
|
||||
import com.badlogic.gdx.math.Matrix4;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.viewport.ScreenViewport;
|
||||
|
||||
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
|
||||
|
||||
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
|
||||
public class ScreenDesktop4 extends AbstractScreenDesktop {
|
||||
private final Shader shader;
|
||||
private final BitmapFont font;
|
||||
private final BitmapFontCache fontCache;
|
||||
private final ScreenViewport uiViewport = new ScreenViewport();
|
||||
private final SpriteBatch spriteBatch;
|
||||
private final Vector3 textPosition = new Vector3(6.5f, 10.5f, 5.5f);
|
||||
private Model grid;
|
||||
private Model model;
|
||||
private float colorDeltaTime = 0f;
|
||||
private float colorFade = 0f;
|
||||
private boolean colorPositive = true;
|
||||
|
||||
public ScreenDesktop4() {
|
||||
super("Desktop4");
|
||||
shader = new UserColorShader();
|
||||
shader.init();
|
||||
font = new BitmapFont();
|
||||
fontCache = new BitmapFontCache(font, false);
|
||||
spriteBatch = new SpriteBatch();
|
||||
}
|
||||
|
||||
protected void createModel(ModelBuilder modelBuilder, Array<ModelInstance> modelInstances) {
|
||||
model = modelBuilder.createBox(.3f, .3f, .3f,new Material(ColorAttribute.createDiffuse(.1f,.1f,.1f,0f)), Usage.Position | Usage.Normal);
|
||||
for (int x = -4; x < 6; x++) {
|
||||
for (int y = 1; y < 11; y++) {
|
||||
for (int z = -4; z < 7; z++) {
|
||||
modelInstances.add(new ModelInstance(model, x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
grid = modelBuilder.createLineGrid(33, 33, 1f, 1f, new Material(ColorAttribute.createDiffuse(1f,1f,1f,.1f)), Usage.Position | Usage.Normal);
|
||||
modelInstances.add(new ModelInstance(grid, 0, 0, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void disposeDesktop() {
|
||||
grid.dispose();
|
||||
model.dispose();
|
||||
}
|
||||
|
||||
protected void renderDesktop(float delta, ModelBatch modelBatch, PerspectiveCamera cam, Array<ModelInstance> modelInstances) {
|
||||
colorFade(delta, modelInstances);
|
||||
|
||||
modelBatch.begin(cam);
|
||||
for (ModelInstance instance : modelInstances) {
|
||||
modelBatch.render(instance, shader);
|
||||
}
|
||||
modelBatch.end();
|
||||
|
||||
// Multiply vector with world-space position with 3D projection-view matrix
|
||||
final Vector3 clipSpacePos = new Vector3(textPosition);
|
||||
final float w = multiplyProjective(cam.combined, clipSpacePos, 1f);
|
||||
|
||||
// Do not render the text if it is behind the camera or too far away
|
||||
if (clipSpacePos.z >= -1f && clipSpacePos.z <= 1f) {
|
||||
// Calculate the position on screen (clip space is [-1,1], we need [-size/2, size/2], but this depends on your viewport)
|
||||
final float textPosX = clipSpacePos.x * Gdx.graphics.getWidth() * 0.5f;
|
||||
final float textPosY = clipSpacePos.y * Gdx.graphics.getHeight() * 0.5f;
|
||||
|
||||
// Set the text normally. The position must be 0, otherwise the scaling won't work.
|
||||
// If you don't want perspective scaling, you can set x,y to textPosX,textPosY directly and skip the next part.
|
||||
fontCache.setText("Now in 3D", 0f, 0, 0f, Align.center, false);
|
||||
|
||||
// Size of the text in the world
|
||||
final float fontSize = 5f;
|
||||
// Scaling factor
|
||||
final float fontScale = fontSize / w;
|
||||
// Go through prepared vertices of the font cache and do necessary transformation
|
||||
final int regionCount = font.getRegions().size;
|
||||
for (int page = 0; page < regionCount; page++) {
|
||||
final int vertexCount = fontCache.getVertexCount(page);
|
||||
final float[] vertices = fontCache.getVertices(page);
|
||||
for (int v = 0; v < vertexCount; v += 5) {
|
||||
// This is why the text position must be 0 - otherwise the scaling would move the text
|
||||
vertices[v] = vertices[v] * fontScale + textPosX;
|
||||
vertices[v + 1] = vertices[v + 1] * fontScale + textPosY;
|
||||
}
|
||||
}
|
||||
|
||||
// Standard viewport update
|
||||
uiViewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
|
||||
spriteBatch.setProjectionMatrix(uiViewport.getCamera().projection);
|
||||
// Draw the text normally
|
||||
spriteBatch.begin();
|
||||
fontCache.draw(spriteBatch);
|
||||
spriteBatch.end();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply 4x4 matrix {@code m} and 4D vector {$code (v, vW)} together.
|
||||
* Store result {@code (x/w, y/w, z/w)} back in {@code v} and return {@code w}.
|
||||
*/
|
||||
private static float multiplyProjective(Matrix4 m, Vector3 v, float vW) {
|
||||
final float[] mat = m.val;
|
||||
final float x = v.x * mat[Matrix4.M00] + v.y * mat[Matrix4.M01] + v.z * mat[Matrix4.M02] + vW * mat[Matrix4.M03];
|
||||
final float y = v.x * mat[Matrix4.M10] + v.y * mat[Matrix4.M11] + v.z * mat[Matrix4.M12] + vW * mat[Matrix4.M13];
|
||||
final float z = v.x * mat[Matrix4.M20] + v.y * mat[Matrix4.M21] + v.z * mat[Matrix4.M22] + vW * mat[Matrix4.M23];
|
||||
final float w = v.x * mat[Matrix4.M30] + v.y * mat[Matrix4.M31] + v.z * mat[Matrix4.M32] + vW * mat[Matrix4.M33];
|
||||
final float iw = 1f / w;
|
||||
v.set(x * iw, y * iw, z * iw);
|
||||
return w;
|
||||
}
|
||||
|
||||
private void colorFade(float delta, Array<ModelInstance> modelInstances) {
|
||||
colorDeltaTime += delta;
|
||||
if (colorDeltaTime > 0.04f) {
|
||||
colorDeltaTime = 0f;
|
||||
if (colorPositive) {
|
||||
colorFade += delta;
|
||||
} else {
|
||||
colorFade -= delta;
|
||||
}
|
||||
if (colorFade > 1f) {
|
||||
colorPositive = false;
|
||||
} else if (colorFade < .5f) {
|
||||
colorPositive = true;
|
||||
}
|
||||
}
|
||||
|
||||
int i=0;
|
||||
for (int x = -4; x < 6; x++) {
|
||||
for (int y = 1; y < 11; y++) {
|
||||
for (int z = -4; z < 7; z++) {
|
||||
float red = .1f;
|
||||
float green = (y+2f)/10f*colorFade;
|
||||
float blue = .1f;
|
||||
if (x == 3 || y == 1 || z == -1) {
|
||||
red = (y+2f)/10f*colorFade;
|
||||
green = 0f;
|
||||
}
|
||||
if (x == -1 || y == 10 || z == 5) {
|
||||
green = 0f;
|
||||
blue = (y+2f)/10f*colorFade;
|
||||
}
|
||||
|
||||
ModelInstance instance = modelInstances.get(i++);
|
||||
ColorAttribute attr = ColorAttribute.createDiffuse(red, green, blue, 1f);
|
||||
instance.materials.get(0).set(attr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -57,7 +57,7 @@ public class ScreenHelp extends AbstractScrollScreen {
|
|||
|
||||
@Override
|
||||
protected Class<? extends Screen> getNextScreen(GDXAppMain main) {
|
||||
return ScreenDesktop0.class;
|
||||
return ScreenDesktop1.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -67,7 +67,7 @@ public class ScreenIntroMission extends AbstractScrollScreen {
|
|||
|
||||
@Override
|
||||
protected Class<? extends Screen> getNextScreen(GDXAppMain main) {
|
||||
return ScreenDesktop0.class;
|
||||
return ScreenDesktop1.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue