all points for circles are properly placed in arrays

This commit is contained in:
Harrison Deng 2018-02-12 21:22:12 -06:00
parent 5395473205
commit 768f562a25
4 changed files with 54 additions and 45 deletions

View File

@ -99,10 +99,12 @@ public class RhythmBullet extends Game {
queueAssets(); queueAssets();
setScreen(initialScreen); setScreen(initialScreen);
System.out.println("pixels per unit: " + pixels_per_unit);
screenWidth = Gdx.graphics.getWidth(); screenWidth = Gdx.graphics.getWidth();
screenHeight = Gdx.graphics.getHeight(); screenHeight = Gdx.graphics.getHeight();
pixels_per_unit = (int) (Float.valueOf(screenHeight)/Float.valueOf(WORLD_HEIGHT));
System.out.println("pixels per unit: " + pixels_per_unit);
} }
public void checkAssetQueue() { public void checkAssetQueue() {
@ -170,7 +172,7 @@ public class RhythmBullet extends Game {
screenWidth = Gdx.graphics.getWidth(); screenWidth = Gdx.graphics.getWidth();
screenHeight = Gdx.graphics.getHeight(); screenHeight = Gdx.graphics.getHeight();
pixels_per_unit = (int) (screenHeight/Float.valueOf(WORLD_HEIGHT)); pixels_per_unit = (int) (Float.valueOf(screenHeight)/Float.valueOf(WORLD_HEIGHT));
System.out.println("pixels per unit: " + pixels_per_unit); System.out.println("pixels per unit: " + pixels_per_unit);
if (initComplete) { if (initComplete) {

View File

@ -12,14 +12,13 @@ import com.badlogic.gdx.utils.Disposable;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
public class CircularVisualizer extends Visualizer implements Disposable { public class CircularVisualizer extends Visualizer implements Disposable {
private int indexCirclePoints; private int circlePointIndex;
private int centerX, centerY; private int centerX, centerY;
private int r; private int r;
private int componentCount = 2 + 1; private int componentCount = 2 + 1;
private float[][] circlePoints; private float[][] circlePoints;
private float[] vertComponents; private float[] vertComponents;
private float color; private float color;
private boolean flushed;
private Mesh mesh; private Mesh mesh;
private ShaderProgram shader; private ShaderProgram shader;
private int barCount = 180; private int barCount = 180;
@ -28,8 +27,11 @@ public class CircularVisualizer extends Visualizer implements Disposable {
private Camera camera; private Camera camera;
public CircularVisualizer() { public CircularVisualizer() {
shader = new ShaderProgram(Gdx.files.internal("shaders/mesh.vsh"), Gdx.files.internal("shaders/mesh.fsh")); shader = new ShaderProgram(Gdx.files.internal("shaders/mesh.vsh"), Gdx.files.internal("shaders/mesh.fsh"));
if (!shader.isCompiled() || shader.getLog().length() != 0) {
Gdx.app.debug("Circular visualizer shader", shader.getLog());
Gdx.app.exit();
}
r = RhythmBullet.pixels_per_unit*2; r = RhythmBullet.pixels_per_unit*2;
System.out.println(RhythmBullet.pixels_per_unit);
} }
/** /**
@ -39,12 +41,13 @@ public class CircularVisualizer extends Visualizer implements Disposable {
int vertsReq = calculateVerticeCount(centerX, centerY, r); int vertsReq = calculateVerticeCount(centerX, centerY, r);
vertComponents = new float[vertsReq * componentCount]; vertComponents = new float[vertsReq * componentCount];
circlePoints = new float[vertsReq][2]; circlePoints = new float[vertsReq][2];
Gdx.app.debug("Circular Visualizer", "Using " + circlePoints.length + " points to create a circle.");
if (mesh != null) { if (mesh != null) {
mesh.dispose(); mesh.dispose();
} }
createCircleVertices(centerX, centerY, r); 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")); mesh = new Mesh(true, circlePoints.length, 0, new VertexAttribute(Usage.Position, 2, "a_position"), new VertexAttribute(Usage.ColorPacked, 4, "a_color"));
} }
public void setCenter(int x, int y) { public void setCenter(int x, int y) {
@ -53,44 +56,44 @@ public class CircularVisualizer extends Visualizer implements Disposable {
} }
private void addCircleVertex(int x, int y) { private void addCircleVertex(int x, int y) {
circlePoints[indexCirclePoints][0] = x; circlePoints[circlePointIndex][0] = x;
circlePoints[indexCirclePoints][1] = y; circlePoints[circlePointIndex][1] = y;
indexCirclePoints++; circlePointIndex++;
} }
public void drawCircle() { public void drawVisualizer() {
if (flushed) { for (int circlePointIndex = 0; circlePointIndex < circlePoints.length; circlePointIndex++) {
for (int circleVertexID = 0; circleVertexID < vertComponents.length; circleVertexID++) { System.out.print("("+ circlePoints[circlePointIndex][0] + "," + circlePoints[circlePointIndex][1] + "),");
vertComponents[circleVertexID] = circlePoints[circleVertexID][0];
circleVertexID++; for (int componentIndex = 0; componentIndex < componentCount; componentIndex++) {
vertComponents[circleVertexID] = circlePoints[circleVertexID][1]; int index = circlePointIndex*componentCount + componentIndex;
circleVertexID++;
vertComponents[circleVertexID] = color; if (componentIndex == 2) {
vertComponents[index] = color;
} else {
vertComponents[index] = circlePoints[circlePointIndex][componentIndex];
}
} }
flushed = false;
} else {
flush();
} }
flush();
} }
public void flush() { private void flush() {
if (!flushed) { mesh.setVertices(vertComponents);
mesh.setVertices(vertComponents);
Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glEnable(GL20.GL_BLEND);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
int vertexCount = circlePoints.length; int vertexCount = circlePoints.length;
shader.begin(); shader.begin();
shader.setUniformMatrix("u_projTrans", camera.combined); shader.setUniformMatrix("u_projTrans", camera.combined);
mesh.render(shader, GL20.GL_TRIANGLES, 0, vertexCount); mesh.render(shader, GL20.GL_TRIANGLES, 0, vertexCount);
shader.end(); shader.end();
flushed = true; Gdx.gl.glDepthMask(true);
Gdx.gl.glDepthMask(true);
}
} }
private void createCircleVertices(int centerX, int centerY, int radius) { private void createCircleVertices(int centerX, int centerY, int radius) {
@ -99,7 +102,7 @@ public class CircularVisualizer extends Visualizer implements Disposable {
int dx = 1; int dx = 1;
int dy = 1; int dy = 1;
int err = dx - (radius << 1); int err = dx - (radius << 1);
indexCirclePoints = 0; circlePointIndex = 0;
while (x >= y) while (x >= y)
{ {
addCircleVertex(centerX + x, centerY + y); addCircleVertex(centerX + x, centerY + y);
@ -144,7 +147,6 @@ public class CircularVisualizer extends Visualizer implements Disposable {
err += dx - (radius << 1); err += dx - (radius << 1);
} }
} }
return vertCount; return vertCount;
} }

View File

@ -137,8 +137,10 @@ public class MusicSelectionPage extends Page implements Observer {
beginButton.addListener(new ChangeListener() { beginButton.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
cameraTarget.x = 2.5f*getWidth(); if (getSelectedMusic() != null) {
ap.processSong(mc.getMusicList().getAudioData(getSelectedMusic()), (albumCoverTexture != null ? albumCoverTexture : assets.get("defaultCover.png", Texture.class)), mic.getInfo(getSelectedMusic())); cameraTarget.x = 2.5f*getWidth();
ap.processSong(mc.getMusicList().getAudioData(getSelectedMusic()), (albumCoverTexture != null ? albumCoverTexture : assets.get("defaultCover.png", Texture.class)), mic.getInfo(getSelectedMusic()));
}
} }
}); });
} }
@ -203,7 +205,11 @@ public class MusicSelectionPage extends Page implements Observer {
} }
public FileHandle getSelectedMusic() { public FileHandle getSelectedMusic() {
return currentlySelected.getMusicFile(); if (currentlySelected != null) {
return currentlySelected.getMusicFile();
} else {
return null;
}
} }
public MusicInfo getSelectedMusicInfo() { public MusicInfo getSelectedMusicInfo() {

View File

@ -35,8 +35,7 @@ public class GameScreen extends ScreenAdapter {
public void render(float delta) { public void render(float delta) {
Gdx.gl.glClearColor(0.22f, 0.22f, 0.22f, 1f); Gdx.gl.glClearColor(0.22f, 0.22f, 0.22f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
cVisualizer.drawCircle(); cVisualizer.drawVisualizer();
cVisualizer.flush();
super.render(delta); super.render(delta);
} }
} }