rewrite the mirror visualizer

This commit is contained in:
Harrison Deng 2017-10-01 12:42:13 -05:00
parent b4e7f97f5b
commit fdafba2127
4 changed files with 52 additions and 37 deletions

View File

@ -40,7 +40,8 @@ public class BasicVisualizer extends VisualizerCore {
angleRot = new Vector2(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation));
textures = new Texture[barCount];
bars = new Sprite[barCount];
spaceBetweenBars = 4;
for (int i = 0; i < textures.length; i++) {
textures[i] = new Texture(pixmap);
bars[i] = new Sprite(textures[i]);
@ -82,7 +83,7 @@ public class BasicVisualizer extends VisualizerCore {
}
for (int i = 0; i < mirrors.size; i++) {
mirrors.get(i).render(bars, batch);
mirrors.get(i).render(batch, parentAlpha, bars);
}
}
super.render(batch, parentAlpha);
@ -107,7 +108,6 @@ public class BasicVisualizer extends VisualizerCore {
angleRot.set(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation));
barWidth = MathUtils.ceil((float) width/(float) barCount);
spaceBetweenBars = 1;
barWidth -= spaceBetweenBars;
for (int i = 0; i < bars.length; i++) {
@ -120,7 +120,7 @@ public class BasicVisualizer extends VisualizerCore {
bars[i].setPosition(xPos + barSpace*angleRot.x, yPos + barSpace*angleRot.y);
}
for (int i = 0; i < mirrors.size; i++) {
mirrors.get(i).updatePositioning(bars, barSpace);
mirrors.get(i).position(barWidth, spaceBetweenBars);
}
}
@ -149,10 +149,15 @@ public class BasicVisualizer extends VisualizerCore {
}
public void addMirrorVisualizer(MirrorVisualizer mirror) {
mirror.setup(bars, barWidth, spaceBetweenBars, (int) width);
mirrors.add(mirror);
}
public void removeMirrorVisualizer(MirrorVisualizer mirror) {
mirrors.removeValue(mirror, true);
}
public void setSpaceBetweenBars(int spaceBetweenBars) {
this.spaceBetweenBars = spaceBetweenBars;
}
}

View File

@ -6,55 +6,63 @@ import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
public class MirrorVisualizer {
private Sprite[] bars;
private float rotation;
private int xPos, yPos;
private Vector2 angleRot;
private float rotation;
private Sprite[] bars;
private boolean flip;
protected void setup(Sprite[] sprites, float rotation, int x, int y, Vector2 angleRot) {
this.xPos = x;
this.yPos = y;
this.angleRot = angleRot;
bars = new Sprite[sprites.length];
private Vector2 rectCoordRot;
public MirrorVisualizer() {
rectCoordRot = new Vector2();
}
protected void setup(Sprite[] bars, int xPos, int yPos, float rotation) {
this.bars = new Sprite[bars.length];
this.xPos = xPos;
this.yPos = yPos;
this.rotation = rotation;
rectCoordRot.set(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation));
for (int i = 0; i < bars.length; i++) {
bars[i] = new Sprite(sprites[i]);
this.bars[i] = new Sprite(bars[i]);
}
}
protected void render(Sprite[] sprites, Batch batch) {
for (int i = 0; i < sprites.length; i++) {
bars[i].setSize(bars[i].getWidth(), sprites[i].getHeight());
bars[i].draw(batch);
public void render(Batch batch, float parentAlpha, Sprite[] bars) {
for (int i = 0; i < this.bars.length; i++) {
this.bars[i].setSize(bars[i].getWidth(), bars[i].getHeight());
this.bars[i].draw(batch);
}
}
public void updatePositioning(Sprite[] sprites, int barSpace) {
angleRot.set(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation));
for (int i = 0; i < sprites.length; i++) {
bars[i].set(sprites[i]);
bars[i].setPosition(xPos + barSpace*angleRot.x, yPos + barSpace*angleRot.y);
public void position(int barWidth, int spaceBetweenBars) {
int barSpaceMultiplier = barWidth + spaceBetweenBars;
for (int i = 0; i < bars.length; i ++) {
if (flip) {
bars[i].setRotation(rotation+180);
} else {
bars[i].setRotation(rotation);
}
bars[i].setPosition(xPos + i*barSpaceMultiplier*rectCoordRot.x, yPos + i*barSpaceMultiplier*rectCoordRot.y);
}
}
public void flip() {
flip = flip ? false : true;
public float getRotation() {
return rotation;
}
public boolean isFlipped() {
return flip;
}
public void setxPos(int xPos) {
this.xPos = xPos;
public void setRotation(float rotation) {
this.rotation = rotation;
}
public void setyPos(int yPos) {
this.yPos = yPos;
}
public void setxPos(int xPos) {
this.xPos = xPos;
}
}

View File

@ -9,10 +9,12 @@ import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.utils.Disposable;
import zero1hd.rhythmbullet.audio.visualizer.MirrorVisualizer;
import zero1hd.rhythmbullet.graphics.meshes.TitleBarMesh;
public class TitleBarVisualizer extends Group implements Disposable {
private Visualizer hvisual;
private MirrorVisualizer visual2;
private TitleBarMesh background;
public TitleBarVisualizer(AssetManager assets, OrthographicCamera camera) {
@ -28,7 +30,10 @@ public class TitleBarVisualizer extends Group implements Disposable {
hvisual.setWidth(getWidth());
hvisual.setHeight(Gdx.graphics.getHeight()*0.3f);
hvisual.getVis().flip();
}
visual2 = new MirrorVisualizer();
hvisual.getVis().addMirrorVisualizer(visual2);
visual2.setRotation(hvisual.getRotation());
visual2.setyPos(background.getHeight()-10);
@Override
public void act(float delta) {
@ -44,6 +49,8 @@ public class TitleBarVisualizer extends Group implements Disposable {
}
public Visualizer getHvisual() {
System.out.println("Harrison is a weeb oh and delet system32");
}
return hvisual;
}

View File

@ -2,7 +2,6 @@ package zero1hd.rhythmbullet.graphics.ui.components;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.ui.Widget;
import zero1hd.rhythmbullet.audio.MusicManager;
@ -10,13 +9,9 @@ import zero1hd.rhythmbullet.audio.visualizer.BasicVisualizer;
public class Visualizer extends Widget {
private BasicVisualizer vis;
private Vector2 coords;
private Vector2 size;
private boolean updatePositioning = true;
public Visualizer() {
vis = new BasicVisualizer();
coords = new Vector2();
size = new Vector2();
}
@Override