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();
setScreen(initialScreen);
System.out.println("pixels per unit: " + pixels_per_unit);
screenWidth = Gdx.graphics.getWidth();
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() {
@ -170,7 +172,7 @@ public class RhythmBullet extends Game {
screenWidth = Gdx.graphics.getWidth();
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);
if (initComplete) {

View File

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

View File

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

View File

@ -35,8 +35,7 @@ public class GameScreen extends ScreenAdapter {
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();
cVisualizer.drawVisualizer();
super.render(delta);
}
}