Progress on game screen and circular visualizer

This commit is contained in:
Harrison Deng 2018-02-12 17:29:23 -06:00
parent de38d1c863
commit 5395473205
6 changed files with 212 additions and 83 deletions

View File

@ -99,10 +99,12 @@ public class RhythmBullet extends Game {
queueAssets();
setScreen(initialScreen);
System.out.println("pixels per unit: " + pixels_per_unit);
screenWidth = Gdx.graphics.getWidth();
screenHeight = Gdx.graphics.getHeight();
}
public void checkAssetQueue() {
if (!initComplete) {
if (assetManager.update()) {
@ -168,7 +170,8 @@ public class RhythmBullet extends Game {
screenWidth = Gdx.graphics.getWidth();
screenHeight = Gdx.graphics.getHeight();
pixels_per_unit = screenHeight/WORLD_HEIGHT;
pixels_per_unit = (int) (screenHeight/Float.valueOf(WORLD_HEIGHT));
System.out.println("pixels per unit: " + pixels_per_unit);
if (initComplete) {
Gdx.app.debug("Resize", "Pre-transition is happening. Using resolution " + width + "x" + height);

View File

@ -1,75 +0,0 @@
package zero1hd.rhythmbullet.graphics.meshes;
import zero1hd.rhythmbullet.RhythmBullet;
public class CircularVisualizerMesh {
private int x, y;
private int componentCount = 2 + 4;
private float[] verts;
public CircularVisualizerMesh() {
}
public void applyPositionChanges() {
verts = new float[calculateVertices(x, y, RhythmBullet.pixels_per_unit) * componentCount];
}
private void createCircleVertices(int centerX, int centerY, int radius) {
int x = radius - 1;
int y = 0;
int dx = 1;
int dy = 1;
int err = dx - (radius << 1);
while (x >= y)
{
putVertex(centerX + x, centerY + y);
putVertex(centerX + y, centerY + x);
putVertex(centerX - y, centerY + x);
putVertex(centerX - x, centerY + y);
putVertex(centerX - x, centerY - y);
putVertex(centerX - y, centerY - x);
putVertex(centerX + y, centerY - x);
putVertex(centerX + x, centerY - y);
if (err <= 0) {
y++;
err += dy;
dy += 2;
} else {
x--;
dx += 2;
err += dx - (radius << 1);
}
}
}
private int calculateVertices(int centerX, int centerY, int radius) {
int x = radius - 1;
int y = 0;
int dx = 1;
int dy = 1;
int err = dx - (radius << 1);
int vertCount = 0;
while (x >= y)
{
vertCount += 8;
if (err <= 0) {
y++;
err += dy;
dy += 2;
} else {
x--;
dx += 2;
err += dx - (radius << 1);
}
}
return vertCount;
}
private void putVertex(int x, int y) {
}
}

View File

@ -0,0 +1,184 @@
package zero1hd.rhythmbullet.desktop.audio.visualizer;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.utils.Disposable;
import zero1hd.rhythmbullet.RhythmBullet;
public class CircularVisualizer extends Visualizer implements Disposable {
private int indexCirclePoints;
private int centerX, centerY;
private int r;
private int componentCount = 2 + 1;
private float[][] circlePoints;
private float[] vertComponents;
private float color;
private boolean flushed;
private Mesh mesh;
private ShaderProgram shader;
private int barCount = 180;
private float barHeightMultiplier = 1.5f;
private float[] audioSpectrum;
private Camera camera;
public CircularVisualizer() {
shader = new ShaderProgram(Gdx.files.internal("shaders/mesh.vsh"), Gdx.files.internal("shaders/mesh.fsh"));
r = RhythmBullet.pixels_per_unit*2;
System.out.println(RhythmBullet.pixels_per_unit);
}
/**
* Only should be called when all changes have been done.
*/
public void applyPositionChanges() {
int vertsReq = calculateVerticeCount(centerX, centerY, r);
vertComponents = new float[vertsReq * componentCount];
circlePoints = new float[vertsReq][2];
if (mesh != null) {
mesh.dispose();
}
createCircleVertices(centerX, centerY, r);
mesh = new Mesh(false, circlePoints.length, 0, new VertexAttribute(Usage.Position, 2, "a_position"), new VertexAttribute(Usage.ColorPacked, 4, "a_color"));
}
public void setCenter(int x, int y) {
this.centerX = x;
this.centerY = y;
}
private void addCircleVertex(int x, int y) {
circlePoints[indexCirclePoints][0] = x;
circlePoints[indexCirclePoints][1] = y;
indexCirclePoints++;
}
public void drawCircle() {
if (flushed) {
for (int circleVertexID = 0; circleVertexID < vertComponents.length; circleVertexID++) {
vertComponents[circleVertexID] = circlePoints[circleVertexID][0];
circleVertexID++;
vertComponents[circleVertexID] = circlePoints[circleVertexID][1];
circleVertexID++;
vertComponents[circleVertexID] = color;
}
flushed = false;
} else {
flush();
}
}
public void flush() {
if (!flushed) {
mesh.setVertices(vertComponents);
Gdx.gl.glEnable(GL20.GL_BLEND);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
int vertexCount = circlePoints.length;
shader.begin();
shader.setUniformMatrix("u_projTrans", camera.combined);
mesh.render(shader, GL20.GL_TRIANGLES, 0, vertexCount);
shader.end();
flushed = true;
Gdx.gl.glDepthMask(true);
}
}
private void createCircleVertices(int centerX, int centerY, int radius) {
int x = radius - 1;
int y = 0;
int dx = 1;
int dy = 1;
int err = dx - (radius << 1);
indexCirclePoints = 0;
while (x >= y)
{
addCircleVertex(centerX + x, centerY + y);
addCircleVertex(centerX + y, centerY + x);
addCircleVertex(centerX - y, centerY + x);
addCircleVertex(centerX - x, centerY + y);
addCircleVertex(centerX - x, centerY - y);
addCircleVertex(centerX - y, centerY - x);
addCircleVertex(centerX + y, centerY - x);
addCircleVertex(centerX + x, centerY - y);
if (err <= 0) {
y++;
err += dy;
dy += 2;
} else {
x--;
dx += 2;
err += dx - (radius << 1);
}
}
}
private int calculateVerticeCount(int centerX, int centerY, int radius) {
int x = radius - 1;
int y = 0;
int dx = 1;
int dy = 1;
int err = dx - (radius << 1);
int vertCount = 0;
while (x >= y)
{
vertCount += 8;
if (err <= 0) {
y++;
err += dy;
dy += 2;
} else {
x--;
dx += 2;
err += dx - (radius << 1);
}
}
return vertCount;
}
public void setColor(float color) {
this.color = color;
}
@Override
public void dispose() {
mesh.dispose();
shader.dispose();
}
/**
* set the maximum radius
* @param r
*/
public void setR(int r) {
this.r = r;
}
/**
* get the maximum radius
* @return
*/
public int getR() {
return r;
}
public void setCamera(Camera camera) {
this.camera = camera;
}
public Camera getCamera() {
return camera;
}
}

View File

@ -1,7 +1,6 @@
package zero1hd.rhythmbullet.desktop.graphics.ui.pages;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Actor;
@ -13,9 +12,11 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.MusicInfo;
import zero1hd.rhythmbullet.audio.MusicManager;
import zero1hd.rhythmbullet.audio.analyzer.AudioAnalyzer;
import zero1hd.rhythmbullet.desktop.screens.GameScreen;
public class AnalysisPage extends Page {
private boolean confirmed;
@ -29,14 +30,17 @@ public class AnalysisPage extends Page {
private Label progressLabel;
private TextButton confirmButton;
private Image albumArt;
private RhythmBullet core;
public AnalysisPage(Skin skin, AssetManager assets, Vector3 cameraPosition) {
public AnalysisPage(RhythmBullet core, Vector3 cameraPosition) {
table = new Table();
table.setFillParent(true);
table.defaults().space(10f);
addActor(table);
this.core = core;
adjustment = new Table();
Skin skin = core.getDefaultSkin();
difficultyModLabel = new Label("Difficulty Modifier: ", skin, "sub-font", skin.getColor("default"));
difficultyModifierSlider = new Slider(1, 3, 0.5f, false, skin);
diffModPercentLabel = new Label(String.valueOf(difficultyModifierSlider.getValue()) + "x", skin);
@ -131,7 +135,7 @@ public class AnalysisPage extends Page {
public void act(float delta) {
if (aa != null && aa.isDone()) {
if (confirmed) {
core.setScreen(new GameScreen(core.getAssetManager(), core.getPrefs()));
}
}
super.act(delta);

View File

@ -1,12 +1,16 @@
package zero1hd.rhythmbullet.desktop.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.desktop.audio.visualizer.CircularVisualizer;
import zero1hd.rhythmbullet.game.GameController;
public class GameScreen extends ScreenAdapter {
@ -14,16 +18,25 @@ public class GameScreen extends ScreenAdapter {
private SpriteBatch batch;
private ExtendViewport viewport;
private GameController gc;
private CircularVisualizer cVisualizer;
public GameScreen(AssetManager assets, Preferences prefs) {
this.assets = assets;
batch = new SpriteBatch();
viewport = new ExtendViewport(RhythmBullet.WORLD_WIDTH, RhythmBullet.WORLD_HEIGHT);
cVisualizer = new CircularVisualizer();
cVisualizer.setCenter(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2);
cVisualizer.setCamera(viewport.getCamera());
cVisualizer.setColor(Color.CYAN.toFloatBits());
cVisualizer.applyPositionChanges();
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0.22f, 0.22f, 0.22f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
cVisualizer.drawCircle();
cVisualizer.flush();
super.render(delta);
}
}

View File

@ -109,7 +109,7 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
creditsPage.setPosition(0, Gdx.graphics.getHeight());
stage.addActor(creditsPage);
analysisPage = new AnalysisPage(core.getDefaultSkin(),core.getAssetManager(), cameraPosition);
analysisPage = new AnalysisPage(core, cameraPosition);
analysisPage.setPosition(2*Gdx.graphics.getWidth(), 0f);
stage.addActor(analysisPage);