added proper rotation to visualizer

This commit is contained in:
Harrison Deng 2017-09-11 20:43:59 -05:00
parent 3e05e66a38
commit 6fb5744048
3 changed files with 31 additions and 12 deletions

View File

@ -8,37 +8,46 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import zero1hd.rhythmbullet.audio.MusicDataPack; import zero1hd.rhythmbullet.audio.MusicDataPack;
public class HorizontalVisualizer extends VisualizerCore { public class BasicVisualizer extends VisualizerCore {
private Pixmap pixmap; private Pixmap pixmap;
private Texture bar; private Texture bar;
private int barWidth; private int barWidth;
private int binsPerBar; private int binsPerBar;
private int spaceBetweenBars; private int spaceBetweenBars;
private Texture[] textures;
private Sprite[] bars; private Sprite[] bars;
private int smoothRange; private int smoothRange;
private float barHeightMultiplier; private float barHeightMultiplier;
private float rotation; private float rotation;
private Vector2 angleRad;
public HorizontalVisualizer() { public BasicVisualizer() {
super(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()/2, 0, 0); super(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()/2, 0, 0);
barHeightMultiplier = Gdx.graphics.getHeight()*0.01f; barHeightMultiplier = Gdx.graphics.getHeight()*0.01f;
pixmap = new Pixmap(2, 2, Format.RGBA8888); pixmap = new Pixmap(2, 2, Format.RGBA8888);
pixmap.setColor(Color.GRAY); pixmap.setColor(Color.GRAY);
pixmap.fill(); pixmap.fill();
bar = new Texture(pixmap);
pixmap.dispose();
barCount = 70; barCount = 70;
barWidth = MathUtils.ceil((float) width/(float) barCount); barWidth = MathUtils.ceil((float) width/(float) barCount);
spaceBetweenBars = (barWidth-2); spaceBetweenBars = (barWidth-2);
barWidth -= spaceBetweenBars; barWidth -= spaceBetweenBars;
smoothRange = 4; smoothRange = 4;
angleRad = new Vector2(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation));
textures = new Texture[barCount];
bars = new Sprite[barCount]; bars = new Sprite[barCount];
for (int i = 0; i < bars.length; i++) {
bars[i] = new Sprite(bar);
for (int i = 0; i < textures.length; i++) {
textures[i] = new Texture(pixmap);
bars[i] = new Sprite(textures[i]);
} }
updatePositionInfo();
pixmap.dispose();
} }
@Override @Override
@ -88,4 +97,14 @@ public class HorizontalVisualizer extends VisualizerCore {
bar.dispose(); bar.dispose();
super.dispose(); super.dispose();
} }
public void updatePositionInfo() {
int barSpace;
for (int i = 0; i < bars.length; i++) {
barSpace = i*(barWidth+spaceBetweenBars);
bars[i].rotate(rotation);
bars[i].setPosition(xPos + barSpace*angleRad.x, yPos + barSpace*angleRad.y);
}
}
} }

View File

@ -2,12 +2,12 @@ package zero1hd.rhythmbullet.ui.components;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import zero1hd.rhythmbullet.audio.visualizer.HorizontalVisualizer; import zero1hd.rhythmbullet.audio.visualizer.BasicVisualizer;
public class Visualizer extends Actor { public class Visualizer extends Actor {
private HorizontalVisualizer hVis; private BasicVisualizer hVis;
public Visualizer() { public Visualizer() {
hVis = new HorizontalVisualizer(); hVis = new BasicVisualizer();
} }
} }

View File

@ -17,7 +17,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.MusicDataPack; import zero1hd.rhythmbullet.audio.MusicDataPack;
import zero1hd.rhythmbullet.audio.SongController; import zero1hd.rhythmbullet.audio.SongController;
import zero1hd.rhythmbullet.audio.visualizer.HorizontalVisualizer; import zero1hd.rhythmbullet.audio.visualizer.BasicVisualizer;
import zero1hd.rhythmbullet.events.OnDifferentSongListener; import zero1hd.rhythmbullet.events.OnDifferentSongListener;
import zero1hd.rhythmbullet.screens.PreGameScreen; import zero1hd.rhythmbullet.screens.PreGameScreen;
@ -32,10 +32,10 @@ public class MainPage extends Page implements OnDifferentSongListener {
private WidgetGroup playButton; private WidgetGroup playButton;
private SongController sc; private SongController sc;
private HorizontalVisualizer hvisual; private BasicVisualizer hvisual;
public MainPage(RhythmBullet core, Vector3 targetPosition, SongController sc) { public MainPage(RhythmBullet core, Vector3 targetPosition, SongController sc) {
hvisual = new HorizontalVisualizer(); hvisual = new BasicVisualizer();
this.sc = sc; this.sc = sc;
sc.addOnDifferentSongListener(this); sc.addOnDifferentSongListener(this);
hvisual.setMDP(sc.getCurrentSong()); hvisual.setMDP(sc.getCurrentSong());