basic visualizer with reverse function

This commit is contained in:
Harrison Deng 2017-10-02 00:00:36 -05:00
parent fdafba2127
commit 411ac59f6f
3 changed files with 40 additions and 21 deletions

View File

@ -27,6 +27,7 @@ public class BasicVisualizer extends VisualizerCore {
private Vector2 angleRot; private Vector2 angleRot;
private boolean flip; private boolean flip;
private Array<MirrorVisualizer> mirrors; private Array<MirrorVisualizer> mirrors;
private boolean reverse;
public BasicVisualizer() { public BasicVisualizer() {
super(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()/2, 0, 0); super(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()/2, 0, 0);
@ -117,7 +118,11 @@ public class BasicVisualizer extends VisualizerCore {
} else { } else {
bars[i].setRotation(rotation); bars[i].setRotation(rotation);
} }
bars[i].setPosition(xPos + barSpace*angleRot.x, yPos + barSpace*angleRot.y); if (reverse) {
bars[bars.length-i-1].setPosition(xPos + barSpace*angleRot.x, yPos + barSpace*angleRot.y);
} else {
bars[i].setPosition(xPos + barSpace*angleRot.x, yPos + barSpace*angleRot.y);
}
} }
for (int i = 0; i < mirrors.size; i++) { for (int i = 0; i < mirrors.size; i++) {
mirrors.get(i).position(barWidth, spaceBetweenBars); mirrors.get(i).position(barWidth, spaceBetweenBars);
@ -149,7 +154,7 @@ public class BasicVisualizer extends VisualizerCore {
} }
public void addMirrorVisualizer(MirrorVisualizer mirror) { public void addMirrorVisualizer(MirrorVisualizer mirror) {
mirror.setup(bars, barWidth, spaceBetweenBars, (int) width); mirror.setup(bars, xPos, yPos, rotation);
mirrors.add(mirror); mirrors.add(mirror);
} }
@ -160,4 +165,16 @@ public class BasicVisualizer extends VisualizerCore {
public void setSpaceBetweenBars(int spaceBetweenBars) { public void setSpaceBetweenBars(int spaceBetweenBars) {
this.spaceBetweenBars = spaceBetweenBars; this.spaceBetweenBars = spaceBetweenBars;
} }
public int getBarWidth() {
return barWidth;
}
public void reverse() {
reverse = reverse ? false : true;
}
public boolean isReversed() {
return reverse;
}
} }

View File

@ -16,10 +16,10 @@ public class MirrorVisualizer {
rectCoordRot = new Vector2(); rectCoordRot = new Vector2();
} }
protected void setup(Sprite[] bars, int xPos, int yPos, float rotation) { protected void setup(Sprite[] bars, float xPos, float yPos, float rotation) {
this.bars = new Sprite[bars.length]; this.bars = new Sprite[bars.length];
this.xPos = xPos; this.xPos = (int) xPos;
this.yPos = yPos; this.yPos = (int) yPos;
this.rotation = rotation; this.rotation = rotation;
rectCoordRot.set(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation)); rectCoordRot.set(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation));

View File

@ -13,28 +13,32 @@ import zero1hd.rhythmbullet.audio.visualizer.MirrorVisualizer;
import zero1hd.rhythmbullet.graphics.meshes.TitleBarMesh; import zero1hd.rhythmbullet.graphics.meshes.TitleBarMesh;
public class TitleBarVisualizer extends Group implements Disposable { public class TitleBarVisualizer extends Group implements Disposable {
private Visualizer hvisual; private Visualizer visual;
private MirrorVisualizer visual2; private MirrorVisualizer visual2;
private TitleBarMesh background; private TitleBarMesh background;
public TitleBarVisualizer(AssetManager assets, OrthographicCamera camera) { public TitleBarVisualizer(AssetManager assets, OrthographicCamera camera) {
if (assets == null) throw new NullPointerException("TitleBarVisualizer requires assets manager... ITS NULL YOU FOOL"); if (assets == null) throw new NullPointerException("TitleBarVisualizer requires assets manager... ITS NULL YOU FOOL");
setSize((float) Math.sqrt(Gdx.graphics.getWidth()*Gdx.graphics.getWidth() + Gdx.graphics.getHeight()*Gdx.graphics.getHeight()), Gdx.graphics.getHeight()*0.3f); visual = new Visualizer();
hvisual = new Visualizer(); visual.getVis().setSpaceBetweenBars(visual.getVis().getBarWidth()-3);
addActor(hvisual); addActor(visual);
background = new TitleBarMesh(); background = new TitleBarMesh();
background.setHeight((int) MathUtils.round(Gdx.graphics.getHeight()*0.3f)); background.setHeight(MathUtils.round(Gdx.graphics.getHeight()*0.3f));
setRotation((float) (MathUtils.radiansToDegrees*Math.atan2(Gdx.graphics.getHeight()-background.getHeight(), Gdx.graphics.getWidth()))); setRotation((float) (MathUtils.radiansToDegrees*Math.atan2(Gdx.graphics.getHeight()-background.getHeight(), Gdx.graphics.getWidth())));
setSize((float) Math.sqrt(Gdx.graphics.getWidth()*Gdx.graphics.getWidth() + Gdx.graphics.getHeight()*Gdx.graphics.getHeight()), ((float) background.getHeight())*MathUtils.sinDeg(90f-getRotation()));
background.setCam(camera); background.setCam(camera);
hvisual.setWidth(getWidth()); visual.setWidth(getWidth());
hvisual.setHeight(Gdx.graphics.getHeight()*0.3f); visual.setHeight(background.getHeight());
hvisual.getVis().flip(); visual.getVis().flip();
visual.getVis().reverse();
visual2 = new MirrorVisualizer(); visual2 = new MirrorVisualizer();
hvisual.getVis().addMirrorVisualizer(visual2); visual.getVis().addMirrorVisualizer(visual2);
visual2.setRotation(hvisual.getRotation()); visual2.setRotation(visual.getRotation());
visual2.setyPos(background.getHeight()-10); visual2.setyPos(MathUtils.round(getHeight()));
}
@Override @Override
public void act(float delta) { public void act(float delta) {
super.act(delta); super.act(delta);
@ -42,16 +46,14 @@ public class TitleBarVisualizer extends Group implements Disposable {
@Override @Override
public void draw(Batch batch, float parentAlpha) { public void draw(Batch batch, float parentAlpha) {
background.draw();
batch.end(); batch.end();
background.draw();
batch.begin(); batch.begin();
super.draw(batch, parentAlpha); super.draw(batch, parentAlpha);
} }
public Visualizer getHvisual() { public Visualizer getHvisual() {
System.out.println("Harrison is a weeb oh and delet system32"); return visual;
}
return hvisual;
} }
@Override @Override