From d64dc8a4d1ab4df7d5c0029a7f76b2231a5eb389 Mon Sep 17 00:00:00 2001 From: Recrown Date: Thu, 21 Sep 2017 14:35:48 -0500 Subject: [PATCH] mesh now looks right --- .../audio/visualizer/BasicVisualizer.java | 13 +++++++++---- .../graphics/meshes/TitleBarMesh.java | 16 ++++++++-------- .../ui/components/TitleBarVisualizer.java | 17 +++++++---------- .../graphics/ui/components/Visualizer.java | 14 ++++++++++++-- .../graphics/ui/pages/MainPage.java | 7 +++++++ 5 files changed, 43 insertions(+), 24 deletions(-) diff --git a/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java b/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java index 4ebb422..586c337 100755 --- a/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java +++ b/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java @@ -23,7 +23,7 @@ public class BasicVisualizer extends VisualizerCore { private int smoothRange; private float barHeightMultiplier; private float rotation; - private Vector2 angleRad; + private Vector2 angleRot; public BasicVisualizer() { super(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()/2, 0, 0); @@ -36,7 +36,7 @@ public class BasicVisualizer extends VisualizerCore { spaceBetweenBars = (barWidth-7); barWidth -= spaceBetweenBars; smoothRange = 4; - angleRad = new Vector2(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation)); + angleRot = new Vector2(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation)); textures = new Texture[barCount]; bars = new Sprite[barCount]; @@ -100,11 +100,16 @@ public class BasicVisualizer extends VisualizerCore { public void updatePositionInfo() { int barSpace; - angleRad.set(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation)); + angleRot.set(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation)); + + barWidth = MathUtils.ceil((float) width/(float) barCount); + spaceBetweenBars = (barWidth-7); + barWidth -= spaceBetweenBars; + for (int i = 0; i < bars.length; i++) { barSpace = i*(barWidth+spaceBetweenBars); bars[i].setRotation(rotation); - bars[i].setPosition(xPos + barSpace*angleRad.x, yPos + barSpace*angleRad.y); + bars[i].setPosition(xPos + barSpace*angleRot.x, yPos + barSpace*angleRot.y); } } diff --git a/core/src/zero1hd/rhythmbullet/graphics/meshes/TitleBarMesh.java b/core/src/zero1hd/rhythmbullet/graphics/meshes/TitleBarMesh.java index 1651695..51b46c4 100755 --- a/core/src/zero1hd/rhythmbullet/graphics/meshes/TitleBarMesh.java +++ b/core/src/zero1hd/rhythmbullet/graphics/meshes/TitleBarMesh.java @@ -58,26 +58,26 @@ public class TitleBarMesh implements Disposable { private int idx = 0; public void draw() { - if (idx >= verts.length) { + if (idx == verts.length) { flush(); } float c = color.toFloatBits(); verts[idx++] = 0; - verts[idx++] = Gdx.graphics.getHeight()/2; + verts[idx++] = height; verts[idx++] = c; - verts[idx++] = Gdx.graphics.getWidth(); - verts[idx++] = Gdx.graphics.getHeight()-height; - verts[idx++] = c; - verts[idx++] = Gdx.graphics.getWidth(); verts[idx++] = Gdx.graphics.getHeight(); verts[idx++] = c; + verts[idx++] = Gdx.graphics.getWidth(); + verts[idx++] = Gdx.graphics.getHeight() - height; + verts[idx++] = c; + + verts[idx++] = 0; verts[idx++] = 0; - verts[idx++] = Gdx.graphics.getHeight()/2 + height; verts[idx++] = c; } @@ -97,7 +97,7 @@ public class TitleBarMesh implements Disposable { shader.setUniformMatrix("u_projTrans", cam.combined); - mesh.render(shader, GL20.GL_TRIANGLES, 0, vertCount); + mesh.render(shader, GL20.GL_TRIANGLE_FAN, 0, vertCount); shader.end(); diff --git a/core/src/zero1hd/rhythmbullet/graphics/ui/components/TitleBarVisualizer.java b/core/src/zero1hd/rhythmbullet/graphics/ui/components/TitleBarVisualizer.java index c935a25..567cb7f 100755 --- a/core/src/zero1hd/rhythmbullet/graphics/ui/components/TitleBarVisualizer.java +++ b/core/src/zero1hd/rhythmbullet/graphics/ui/components/TitleBarVisualizer.java @@ -4,10 +4,9 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.assets.AssetManager; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.OrthographicCamera; -import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.scenes.scene2d.Group; -import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.utils.Disposable; import zero1hd.rhythmbullet.graphics.meshes.TitleBarMesh; @@ -15,22 +14,20 @@ import zero1hd.rhythmbullet.graphics.meshes.TitleBarMesh; public class TitleBarVisualizer extends Group implements Disposable { private Visualizer hvisual; private TitleBarMesh background; - private Image titleImage; public TitleBarVisualizer(AssetManager assets, OrthographicCamera camera) { 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); hvisual = new Visualizer(); addActor(hvisual); - - titleImage = new Image(assets.get("title.png", Texture.class)); - addActor(titleImage); - + debug(); background = new TitleBarMesh(); - background.setHeight((int) (Gdx.graphics.getHeight()*0.2)); + background.setHeight((int) MathUtils.round(Gdx.graphics.getHeight()*0.3f)); + setRotation((float) (MathUtils.radiansToDegrees*Math.atan2(Gdx.graphics.getHeight()-background.getHeight(), Gdx.graphics.getWidth()))); background.setCam(camera); - hvisual.setY(getHeight()); + hvisual.setWidth(getWidth()); + hvisual.setHeight(Gdx.graphics.getHeight()*0.3f); } @Override diff --git a/core/src/zero1hd/rhythmbullet/graphics/ui/components/Visualizer.java b/core/src/zero1hd/rhythmbullet/graphics/ui/components/Visualizer.java index 3ced7b6..40fff43 100755 --- a/core/src/zero1hd/rhythmbullet/graphics/ui/components/Visualizer.java +++ b/core/src/zero1hd/rhythmbullet/graphics/ui/components/Visualizer.java @@ -12,7 +12,7 @@ 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(); @@ -32,7 +32,9 @@ public class Visualizer extends Widget { vis.setxPos(getX()); vis.setyPos(getY()); vis.setRotation(getRotation()); - vis.updatePositionInfo(); + if (updatePositioning) { + vis.updatePositionInfo(); + } vis.calculate(); super.act(delta); } @@ -53,4 +55,12 @@ public class Visualizer extends Widget { vis.setColor(r, g, b, a); super.setColor(r, g, b, a); } + + public void setUpdatePositioning(boolean updatePositioning) { + this.updatePositioning = updatePositioning; + } + + public boolean isUpdatePositioning() { + return updatePositioning; + } } diff --git a/core/src/zero1hd/rhythmbullet/graphics/ui/pages/MainPage.java b/core/src/zero1hd/rhythmbullet/graphics/ui/pages/MainPage.java index d4acc66..e225311 100755 --- a/core/src/zero1hd/rhythmbullet/graphics/ui/pages/MainPage.java +++ b/core/src/zero1hd/rhythmbullet/graphics/ui/pages/MainPage.java @@ -22,6 +22,8 @@ public class MainPage extends Page implements OnDifferentSongListener { titleBar = new TitleBarVisualizer(core.getAssetManager(), camera); addActor(titleBar); + titleBar.getHvisual().setMDP(sc.getCurrentSong()); + sc.addOnDifferentSongListener(this); versionLabel = new Label("Version: " + RhythmBullet.VERSION, core.getDefaultSkin(), "sub-font", @@ -44,4 +46,9 @@ public class MainPage extends Page implements OnDifferentSongListener { public void onDifferentSong(MusicManager mdp) { titleBar.getHvisual().setMDP(mdp); } + + @Override + public void dispose() { + super.dispose(); + } }